From 8b081e2868c0cc3b258f520954a1250c76837496 Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Thu, 25 Aug 2016 17:52:40 +0200 Subject: [PATCH] Add new parameter return_last_job_status to harvest_source_list In order to get a quick overview over successful/failed harvesters, a call to harvest_source_list with return_last_job_status=true can be used to get this information. By default return_last_job_status is False, and hence the extra resources to grab this information is not wasted for every call, but only if the client requests is explicitly. The original 'status' field stays as-is, this PR introduces a new field called 'last_job_status' to return this information. The returned information is gather by a call to harvest_source_status_show. --- ckanext/harvest/logic/action/get.py | 4 +++- ckanext/harvest/logic/dictization.py | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index 2415278..94594b7 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -130,7 +130,9 @@ def harvest_source_list(context, data_dict): sources = _get_sources_for_user(context, data_dict) - return [harvest_source_dictize(source, context) for source in sources] + last_job_status = data_dict.get('return_last_job_status', False) + + return [harvest_source_dictize(source, context, last_job_status) for source in sources] @side_effect_free diff --git a/ckanext/harvest/logic/dictization.py b/ckanext/harvest/logic/dictization.py index 877ea19..53d1392 100644 --- a/ckanext/harvest/logic/dictization.py +++ b/ckanext/harvest/logic/dictization.py @@ -1,15 +1,12 @@ from sqlalchemy import distinct, func from ckan.model import Package, Group +from ckan import logic from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject, HarvestGatherError, HarvestObjectError) -def harvest_source_dictize(source, context): - ''' - TODO: Deprecated - ''' - +def harvest_source_dictize(source, context, last_job_status=False): out = source.as_dict() out['publisher_title'] = u'' @@ -22,6 +19,10 @@ def harvest_source_dictize(source, context): out['status'] = _get_source_status(source, context) + if last_job_status: + source_status = logic.get_action('harvest_source_show_status')(context, {'id': source.id}) + out['last_job_status'] = source_status.get('last_job', {}) + return out