mirror of
https://github.com/ansible/awx.git
synced 2026-03-06 03:01:06 -03:30
Reimplement last_run detection in the periodic Tower scheduler task to
not rely on celery's last run information
This commit is contained in:
@@ -17,6 +17,8 @@ import traceback
|
|||||||
import urlparse
|
import urlparse
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import dateutil.parser
|
||||||
|
|
||||||
# Pexpect
|
# Pexpect
|
||||||
import pexpect
|
import pexpect
|
||||||
|
|
||||||
@@ -47,24 +49,37 @@ logger = logging.getLogger('awx.main.tasks')
|
|||||||
|
|
||||||
@task(bind=True)
|
@task(bind=True)
|
||||||
def tower_periodic_scheduler(self):
|
def tower_periodic_scheduler(self):
|
||||||
|
def get_last_run():
|
||||||
|
if not os.path.exists('/tmp/.tower_cycle'):
|
||||||
|
return None
|
||||||
|
fd = open('/tmp/.tower_cycle')
|
||||||
|
try:
|
||||||
|
last_run = dateutil.parser.parse(fd.read())
|
||||||
|
return last_run
|
||||||
|
except Exception, e:
|
||||||
|
return None
|
||||||
|
def write_last_run(last_run):
|
||||||
|
fd = open('/tmp/.tower_cycle', 'w')
|
||||||
|
fd.write(last_run.isoformat())
|
||||||
|
fd.close()
|
||||||
|
|
||||||
run_now = now()
|
run_now = now()
|
||||||
try:
|
last_run = get_last_run()
|
||||||
periodic_task = PeriodicTask.objects.filter(task='awx.main.tasks.tower_periodic_scheduler')[0]
|
if not last_run:
|
||||||
except IndexError:
|
logger.debug("First run time")
|
||||||
logger.warning('No PeriodicTask found for tower_periodic_scheduler')
|
write_last_run(run_now)
|
||||||
return
|
return
|
||||||
logger.debug("Last run was: %s", periodic_task.last_run_at)
|
logger.debug("Last run was: %s", last_run)
|
||||||
old_schedules = Schedule.objects.enabled().before(periodic_task.last_run_at)
|
write_last_run(run_now)
|
||||||
|
old_schedules = Schedule.objects.enabled().before(last_run)
|
||||||
for schedule in old_schedules:
|
for schedule in old_schedules:
|
||||||
schedule.save()
|
schedule.save()
|
||||||
schedules = Schedule.objects.enabled().between(periodic_task.last_run_at, run_now)
|
schedules = Schedule.objects.enabled().between(last_run, run_now)
|
||||||
for schedule in schedules:
|
for schedule in schedules:
|
||||||
template = schedule.unified_job_template
|
template = schedule.unified_job_template
|
||||||
schedule.save() # To update next_run timestamp.
|
schedule.save() # To update next_run timestamp.
|
||||||
new_unified_job = template.create_unified_job(launch_type='scheduled', schedule=schedule)
|
new_unified_job = template.create_unified_job(launch_type='scheduled', schedule=schedule)
|
||||||
new_unified_job.signal_start()
|
new_unified_job.signal_start()
|
||||||
periodic_task.last_run_at = run_now
|
|
||||||
periodic_task.save()
|
|
||||||
|
|
||||||
@task()
|
@task()
|
||||||
def notify_task_runner(metadata_dict):
|
def notify_task_runner(metadata_dict):
|
||||||
|
|||||||
Reference in New Issue
Block a user