Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)::

Expand Down
20 changes: 20 additions & 0 deletions ckanext/harvest/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import types
from logging import getLogger

Expand Down Expand Up @@ -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):
Expand Down