Fix job_schedule trigger cron

when schedule json_file has some key eg: schedule_{year, week, day}
and so on, it should trigger cron to schedule use apschedule.
But it is unavailable now. This patch should fix it use cron date.

Change-Id: I0113158d60605109fdeefe74f45f4050b5a75d7a
Closes-Bug: #1599715
This commit is contained in:
yangyapeng 2016-07-13 23:25:01 +00:00 committed by Pierre Mathieu
parent a5915135fc
commit e4011c0c86
1 changed files with 8 additions and 1 deletions

View File

@ -233,8 +233,14 @@ class Job(object):
def schedule_cron_fields(self):
cron_fields = ['year', 'month', 'day', 'week', 'day_of_week',
'hour', 'minute', 'second']
cron_schedule = {}
for cron in self.job_doc['job_schedule'].keys():
if cron.startswith('schedule_'):
cron_key = cron.split('_', 1)[1]
cron_schedule.update({
cron_key: self.job_doc['job_schedule'][cron]})
return {key: value
for key, value in self.job_doc['job_schedule'].items()
for key, value in cron_schedule.items()
if key in cron_fields}
@property
@ -282,6 +288,7 @@ class Job(object):
kwargs.update({unit: int(val)})
return kwargs
else:
kwargs = {'trigger': 'cron'}
cron_fields = self.schedule_cron_fields
if cron_fields:
kwargs = {'trigger': 'cron'}.update(kwargs_date)