Refactor build_jobs_notify_done
@@ -37,17 +37,7 @@ def build_jobs_stop(build_job_id, update_status=True):
dockerizer_scheduler.stop_dockerizer(build_job, update_status=update_status)
-@celery_app.task(name=SchedulerCeleryTasks.BUILD_JOBS_NOTIFY_DONE, ignore_result=True)
-def build_jobs_notify_done(build_job_id):
- build_job = get_valid_build_job(build_job_id=build_job_id)
- if not build_job:
- _logger.info('Something went wrong, '
- 'the BuildJob `%s` does not exist anymore.', build_job_id)
- return
-
- # Notify all dependent jobs, notebooks, tensorboards, and experiments
- # Build job Failed -> Set status Failed with message: build failed
- if build_job.failed:
+def notify_build_job_failed(build_job):
message = 'Build failed'
details = 'build_job_id: {}, {}'.format(build_job.id, build_job.uuid.hex)
@@ -66,10 +56,9 @@ def build_jobs_notify_done(build_job_id):
experiments = Experiment.objects.filter(build_job=build_job)
for experiment in experiments:
experiment.set_status(ExperimentLifeCycle.FAILED, message=message, details=details)
- return
- # Build job Stopped -> Stop the dependent jobs
- if build_job.stopped:
+
+def notify_build_job_stopped(build_job):
message = 'Build stopped'
details = 'build_job_id: {}, {}'.format(build_job.id, build_job.uuid.hex)
@@ -88,10 +77,9 @@ def build_jobs_notify_done(build_job_id):
experiments = Experiment.objects.filter(build_job=build_job)
for experiment in experiments:
experiment.set_status(ExperimentLifeCycle.FAILED, message=message, details=details)
- return
- # Build job Succeeded -> Start the dependent jobs
- if build_job.succeeded:
+
+def notify_build_job_succeeded(build_job):
job_ids = Job.objects.filter(build_job=build_job).values_list('id', flat=True)
for job_id in job_ids:
celery_app.send_task(
@@ -119,4 +107,26 @@ def build_jobs_notify_done(build_job_id):
SchedulerCeleryTasks.EXPERIMENTS_START,
kwargs={'experiment_id': experiment_id})
+
+@celery_app.task(name=SchedulerCeleryTasks.BUILD_JOBS_NOTIFY_DONE, ignore_result=True)
+def build_jobs_notify_done(build_job_id):
+ build_job = get_valid_build_job(build_job_id=build_job_id)
+ if not build_job:
+ _logger.info('Something went wrong, '
+ 'the BuildJob `%s` does not exist anymore.', build_job_id)
return
+
+ # Notify all dependent jobs, notebooks, tensorboards, and experiments
+ # Build job Failed -> Set status Failed with message: build failed
+ if build_job.failed:
+ notify_build_job_failed(build_job)
+ return
+
+ # Build job Stopped -> Stop the dependent jobs
+ if build_job.stopped:
+ notify_build_job_stopped(build_job)
+ return
+
+ # Build job Succeeded -> Start the dependent jobs
+ if build_job.succeeded:
+ notify_build_job_succeeded(build_job)
