diff --git a/README.rst b/README.rst index f3dadf8f2..c0045f3f5 100644 --- a/README.rst +++ b/README.rst @@ -233,6 +233,11 @@ field. The currently supported configuration options are: lower-case ones, and spaces replaced with dashes. Setting this option to False gives the same effect as leaving it unset. +* harvester_app: inactive | CKAN | NG Harvester | Other external app. + Defaults (not set) is _CKAN_. If use _"NG Harvester"_ or other external app this + source will be set _inactive_ locally. Use _"inactive"_ to stop harvesting + temporary from this source. + Here is an example of a configuration object (the one that must be entered in the configuration field):: diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index 77ae0eb3c..f42369afd 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -1,3 +1,4 @@ +import json import types from logging import getLogger @@ -36,14 +37,33 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): ## IPackageController + def _get_harvest_source_state(data_dict): + # if use_external_harvester_app is True we set as inactive locally + # and it will be executed by some external application (e.g. NG harvester) + cfg_str = data_dict.get('config', '{}') + try: + cfg = json.loads(cfg_str) + except Exception as e: + log.error('Failed to read harvest source configuration: {} {}'.format(cfg_str, str(e))) + return 'active' + + # this harvest source config value will be also readed + # by and externall application and run it without conflict. + # By setting as inactive we stop all jobs and avoid to run locally in the future. + ret = 'inactive' if cfg.get('harvester_app', 'CKAN') != 'CKAN' else 'active' + + return ret + def after_create(self, context, data_dict): if 'type' in data_dict and data_dict['type'] == DATASET_TYPE_NAME and not self.startup: # Create an actual HarvestSource object + data_dict['state'] = _get_harvest_source_state(data_dict) _create_harvest_source_object(context, data_dict) def after_update(self, context, data_dict): if 'type' in data_dict and data_dict['type'] == DATASET_TYPE_NAME: # Edit the actual HarvestSource object + data_dict['state'] = _get_harvest_source_state(data_dict) _update_harvest_source_object(context, data_dict) def after_delete(self, context, data_dict):