Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The worker does not send job_fail anymore

This was required because job_fail will not allow us to return
the output of the failed job back to the client (job.py). This is
a problem because gearman protocol does not support it.

So what we did is, we make the worker always return a success but add a
failure return code to the output (json format) that is passed to the
client.

The client checks the rc from the output to determin is the job failed
or succeeded.
  • Loading branch information...
commit 213f03ce48524027100fb4e015824b6443f69859 1 parent 9b8d148
Nikhil Singh authored
Showing with 13 additions and 9 deletions.
  1. +6 −2 job.py
  2. +0 −1  roadrunner.py
  3. +7 −6 worker.py
View
8 job.py
@@ -121,8 +121,12 @@ def poll(self):
for index, gmjob in enumerate(self._completed_gmjobs):
unique = gmjob.job.unique
+ output = json.loads(gmjob.result)
if gmjob.state == gearman.job.JOB_COMPLETE:
- self._rcs[unique] = 0
+ if output["rc"] == -1:
+ self._rcs[unique] = output["rc"]
+ else:
+ self._rcs[unique] = 0
elif gmjob.state == gearman.job.JOB_FAILED:
self._rcs[unique] = 1
elif gmjob.state == gearman.job.JOB_UNKNOWN:
@@ -130,7 +134,7 @@ def poll(self):
else:
self._rcs[unique] = 3
- self._output[unique] = gmjob.result
+ self._output[unique] = output["output"]
def success(self):
View
1  roadrunner.py
@@ -59,7 +59,6 @@ def get_dict_val(key, dic, exit_on_error=False):
def subprocess_wrapper(j):
j.run()
j.poll()
- l.debug("Job: " + j._job_id + " return codes: " + str(j._rcs))
if j.success():
l.debug("Job: " + j._job_id + " executed successfully!")
else:
View
13 worker.py
@@ -16,8 +16,11 @@ def exe_job(worker, job):
cmd = d['command']
retries = int(d['retries'])
output = ""
+ rc = -1
# Run the fabric command. Do not abort on exit
+ # Run job for the given number of retries
+ tmp_retries = retries;
while retries > 0:
with settings(warn_only=True):
result = run(cmd)
@@ -25,18 +28,16 @@ def exe_job(worker, job):
if result.failed:
if retries == 1:
- job.send_fail()
- break
-
+ rc = -1
else:
next
-
else:
+ rc = 0
break
retries = retries - 1
-
- return output
+
+ return json.dumps({ "rc": rc, "output": output })
#
Please sign in to comment.
Something went wrong with that request. Please try again.