Merge lp:~adeuring/lazr.jobrunner/use_job_repr_in_logging into lp:lazr.jobrunner

Proposed by Abel Deuring on 2012-03-22
Status: Merged
Approved by: Aaron Bentley on 2012-03-22
Approved revision: 18
Merged at revision: 22
Proposed branch: lp:~adeuring/lazr.jobrunner/use_job_repr_in_logging
Merge into: lp:lazr.jobrunner
Diff against target: 26 lines (+4/-3)
1 file modified
src/lazr/jobrunner/jobrunner.py (+4/-3)
To merge this branch: bzr merge lp:~adeuring/lazr.jobrunner/use_job_repr_in_logging
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve on 2012-03-22
j.c.sackett (community) 2012-03-22 Approve on 2012-03-22
Richard Harding (community) code* 2012-03-22 Approve on 2012-03-22
Review via email: mp+98821@code.launchpad.net

Description of the Change

Some classes that are dervied from BaseRunnableJob in the Launchpad source code define __repr__(), and repr(job) was used by the old job implementation in log messages.

This change fixes failures in these Launchpad tests:

lp.registry.tests.test_process_job_sources_cronjob.ProcessJobSourceGroupsTest.test_processed
lp.registry.tests.test_process_job_sources_cronjob.ProcessJobSourceTest.test_processed
lp.registry.tests.test_membership_notification_job.MembershipNotificationJobTest

(the first two tests need also an s/DEBUG/INFO / in an assertWhatever() call, but i think it is reasonable to change the log level from DEBUG to INFO.)

To post a comment you must log in.
Abel Deuring (adeuring) wrote :
Richard Harding (rharding) :
review: Approve (code*)
j.c.sackett (jcsackett) :
review: Approve
Aaron Bentley (abentley) wrote :

Please use a more standard __repr__ such as "<Job>" or "Job(id=5)". Other than that, this is fine.

review: Approve
Abel Deuring (adeuring) wrote :

On 22.03.2012 16:29, Aaron Bentley wrote:
> Review: Approve
>
> Please use a more standard __repr__ such as "<Job>" or "Job(id=5)". Other than that, this is fine.

I used '<%s>' % self.__class__.__name__. Something like

  <%s(%s)> % (self.__class__.__name__, self.job_id)

would let the job ID disappear from log messages when a derived class
has its own __repr__() method.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/jobrunner/jobrunner.py'
2--- src/lazr/jobrunner/jobrunner.py 2012-03-16 18:27:52 +0000
3+++ src/lazr/jobrunner/jobrunner.py 2012-03-22 11:51:17 +0000
4@@ -144,6 +144,9 @@
5 def getOopsVars(self):
6 return ()
7
8+ def __repr__(self):
9+ return self.__class__.__name__
10+
11
12 class JobRunner:
13
14@@ -160,9 +163,7 @@
15
16 @staticmethod
17 def job_str(job):
18- class_name = job.__class__.__name__
19- ijob_id = job.job_id
20- return '%s (ID %d)' % (class_name, ijob_id)
21+ return '%r (ID %d)' % (job, job.job_id)
22
23 def runJob(self, job):
24 """Attempt to run a job, updating its status as appropriate."""
25
26=== modified file 'src/lazr/jobrunner/tests/test_jobrunner.py'

Subscribers

People subscribed via source and target branches

to all changes: