Merge lp:~adeuring/launchpad/bug-1015667 into lp:launchpad

Proposed by Abel Deuring on 2012-07-03
Status: Merged
Approved by: Abel Deuring on 2012-07-03
Approved revision: no longer in the source branch.
Merged at revision: 15548
Proposed branch: lp:~adeuring/launchpad/bug-1015667
Merge into: lp:launchpad
Diff against target: 93 lines (+38/-2)
3 files modified
lib/lp/services/job/runner.py (+26/-1)
lib/lp/services/job/tests/test_runner.py (+11/-0)
versions.cfg (+1/-1)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-1015667
Reviewer Review Type Date Requested Status
Richard Harding (community) 2012-07-03 Approve on 2012-07-03
Review via email: mp+113245@code.launchpad.net

Commit Message

Use more informative task ID for Celery jobs.

Description of the Change

This branch changes the task ID assigned to Celery jobs in
BaseRunnableJob.runViaCelery(). This should help us fix bug
1015667
.

As explained in the doc string of the new method taskId(), it
is difficult to get any clue why and where the result queues
were created. Adding the job class and the job ID gives us at
least a bit more information.

test: ./bin/test services -vvt test_taskId

no lint

To post a comment you must log in.
Richard Harding (rharding) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/job/runner.py'
2--- lib/lp/services/job/runner.py 2012-06-14 05:18:22 +0000
3+++ lib/lp/services/job/runner.py 2012-07-03 15:48:38 +0000
4@@ -37,6 +37,7 @@
5 )
6 import sys
7 from textwrap import dedent
8+from uuid import uuid4
9
10 from ampoule import (
11 child,
12@@ -196,6 +197,29 @@
13 return oops_config.create(
14 context=dict(exc_info=info))
15
16+ def taskId(self):
17+ """Return a task ID that gives a clue what this job is about.
18+
19+ Though we intend to drop the result return by a Celery job
20+ (in the sense that we don't care what
21+ lazr.jobrunner.celerytask.RunJob.run() returns), we might
22+ accidentally create result queues, for example, when a job fails.
23+ The messages stored in these queues are often not very specific,
24+ the queues names are just the IDs of the task, which are by
25+ default just strings returned by Celery's uuid() function.
26+
27+ If we put the job's class name and the job ID into the task ID,
28+ we have better chances to figure out what went wrong than by just
29+ look for example at a message like
30+
31+ {'status': 'FAILURE',
32+ 'traceback': None,
33+ 'result': SoftTimeLimitExceeded(1,),
34+ 'task_id': 'cba7d07b-37fe-4f1d-a5f6-79ad7c30222f'}
35+ """
36+ return '%s-%s-%s' % (
37+ self.__class__.__name__, self.job_id, uuid4())
38+
39 def runViaCelery(self, ignore_result=False):
40 """Request that this job be run via celery."""
41 # Avoid importing from lp.services.job.celeryjob where not needed, to
42@@ -213,7 +237,8 @@
43 else:
44 eta = None
45 return cls.apply_async(
46- (ujob_id, self.config.dbuser), queue=self.task_queue, eta=eta)
47+ (ujob_id, self.config.dbuser), queue=self.task_queue, eta=eta,
48+ task_id=self.taskId())
49
50 def getDBClass(self):
51 return self.context.__class__
52
53=== modified file 'lib/lp/services/job/tests/test_runner.py'
54--- lib/lp/services/job/tests/test_runner.py 2012-05-09 14:17:41 +0000
55+++ lib/lp/services/job/tests/test_runner.py 2012-07-03 15:48:38 +0000
56@@ -4,6 +4,7 @@
57 """Tests for job-running facilities."""
58
59 import logging
60+import re
61 import sys
62 from textwrap import dedent
63 from time import sleep
64@@ -376,6 +377,16 @@
65 self.assertNotIn(job, runner.completed_jobs)
66 self.assertIn(job, runner.incomplete_jobs)
67
68+ def test_taskId(self):
69+ # BaseRunnableJob.taskId() creates a task ID that consists
70+ # of the Job's class name, the job ID and a UUID.
71+ job = NullJob(completion_message="doesn't matter")
72+ task_id = job.taskId()
73+ uuid_expr = (
74+ '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
75+ mo = re.search('^NullJob-%s-%s$' % (job.job_id, uuid_expr), task_id)
76+ self.assertIsNot(None, mo)
77+
78
79 class StaticJobSource(BaseRunnableJob):
80
81
82=== modified file 'versions.cfg'
83--- versions.cfg 2012-07-03 04:35:43 +0000
84+++ versions.cfg 2012-07-03 15:48:38 +0000
85@@ -49,7 +49,7 @@
86 lazr.config = 1.1.3
87 lazr.delegates = 1.2.0
88 lazr.enum = 1.1.3
89-lazr.jobrunner = 0.6
90+lazr.jobrunner = 0.8
91 lazr.lifecycle = 1.1
92 lazr.restful = 0.19.6
93 lazr.restfulclient = 0.12.2