diff --git a/ckanext/harvest/logic/action/update.py b/ckanext/harvest/logic/action/update.py index b478abe..8c3a170 100644 --- a/ckanext/harvest/logic/action/update.py +++ b/ckanext/harvest/logic/action/update.py @@ -208,10 +208,19 @@ def harvest_jobs_run(context,data_dict): objects = session.query(HarvestObject.id) \ .filter(HarvestObject.harvest_job_id==job['id']) \ .filter(and_((HarvestObject.state!=u'COMPLETE'), - (HarvestObject.state!=u'ERROR'))) + (HarvestObject.state!=u'ERROR'))) \ + .order_by(HarvestObject.import_finished.desc()) + if objects.count() == 0: job_obj = HarvestJob.get(job['id']) job_obj.status = u'Finished' + + last_object = session.query(HarvestObject) \ + .filter(HarvestObject.harvest_job_id==job['id']) \ + .order_by(HarvestObject.import_finished.desc()) \ + .first() + if last_object: + job_obj.finished = last_object.import_finished job_obj.save() # Reindex the harvest source dataset so it has the latest # status diff --git a/ckanext/harvest/model/__init__.py b/ckanext/harvest/model/__init__.py index 069156a..f973f48 100644 --- a/ckanext/harvest/model/__init__.py +++ b/ckanext/harvest/model/__init__.py @@ -193,6 +193,7 @@ def define_harvester_tables(): Column('created', types.DateTime, default=datetime.datetime.utcnow), Column('gather_started', types.DateTime), Column('gather_finished', types.DateTime), + Column('finished', types.DateTime), Column('source_id', types.UnicodeText, ForeignKey('harvest_source.id')), Column('status', types.UnicodeText, default=u'New', nullable=False), ) @@ -380,6 +381,9 @@ ALTER TABLE harvest_source ADD COLUMN frequency text, ADD COLUMN next_run timestamp without time zone; +ALTER TABLE harvest_job + ADD COLUMN finished timestamp without time zone; + ALTER TABLE harvest_object_extra ADD CONSTRAINT harvest_object_extra_pkey PRIMARY KEY (id); diff --git a/ckanext/harvest/templates_new/job/read.html b/ckanext/harvest/templates_new/job/read.html index d8ad887..85d85ad 100644 --- a/ckanext/harvest/templates_new/job/read.html +++ b/ckanext/harvest/templates_new/job/read.html @@ -45,7 +45,7 @@ {{ _('Finished') }} - ?? (gather_finished, last object import_finished) + {{ c.job.finished }}