From 7da52c8bef05beae963e90b9b45d226b30ed8410 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 28 Feb 2017 12:39:55 -0500 Subject: [PATCH] emit job status over socket after database commit * Wait until the newly created job record hits the database before telling the websocket clients that the job's status is "pending" --- awx/main/models/unified_jobs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index f17b2b4c55..7744f27821 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -964,10 +964,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique # Save the pending status, and inform the SocketIO listener. self.update_fields(start_args=json.dumps(kwargs), status='pending') - self.websocket_emit_status("pending") - from awx.main.scheduler.tasks import run_job_launch - connection.on_commit(lambda: run_job_launch.delay(self.id)) + def post_commit(): + from awx.main.scheduler.tasks import run_job_launch + self.websocket_emit_status("pending") + run_job_launch.delay(self.id) + + connection.on_commit(post_commit) # Each type of unified job has a different Task class; get the # appropirate one.