[#5] Add new finished field for harvest job

When the run command flags a job as finished, it will query the most
recent harvest object for this job and use its import_finished value as
the job finishing time.
This commit is contained in:
amercader 2013-01-28 17:19:28 +00:00
parent 920f07cdf7
commit 42bace3628
3 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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);

View File

@ -45,7 +45,7 @@
</tr>
<tr>
<th>{{ _('Finished') }}</th>
<td>?? (gather_finished, last object import_finished)</td>
<td>{{ c.job.finished }}</td>
</tr>
</tbody>
</table>