Merge lp:~danilo/launchpad/bug-820511 into lp:launchpad

Proposed by Данило Шеган
Status: Merged
Approved by: Данило Шеган
Approved revision: no longer in the source branch.
Merged at revision: 13679
Proposed branch: lp:~danilo/launchpad/bug-820511
Merge into: lp:launchpad
Diff against target: 188 lines (+42/-19)
7 files modified
lib/lp/code/scripts/tests/test_create_merge_proposals.py (+3/-2)
lib/lp/code/scripts/tests/test_merge_proposal_jobs.py (+3/-1)
lib/lp/code/scripts/tests/test_reclaim_branch_space.py (+3/-1)
lib/lp/code/scripts/tests/test_sendbranchmail.py (+6/-4)
lib/lp/services/job/runner.py (+13/-4)
lib/lp/services/job/tests/test_runner.py (+12/-7)
lib/lp/translations/scripts/tests/test_packaging_translations.py (+2/-0)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-820511
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+71179@code.launchpad.net

Commit message

[r=jcsackett][bug=820511] Log Job IDs on INFO level when running jobs to ease debugging efforts when things go wrong.

Description of the change

= Bug 820511 =

Log the job ID and class name on the INFO level in the runner.

== Tests ==

bin/test -cvvt test_runner

== Demo and Q/A ==

Run any jobs (eg. cronscripts/run_jobs.py packaging_translations) with no -v parameters and note how job ID is listed along with the class name.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/services/job/runner.py
  lib/lp/services/job/tests/test_runner.py

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

This looks good. It'll certainly be easier to debug jobs this way.

One question, though.

> 18 @@ -262,7 +265,8 @@
> 19 def _logOopsId(self, oops_id):
> 20 """Report oopses by id to the log."""
> 21 if self.logger is not None:
> 22 - self.logger.info('Job resulted in OOPS: %s' % oops_id)
> 23 + self.logger.info('Job resulted in OOPS: %s' % (
> 24 + oops_id))
> 25 self.oops_ids.append(oops_id)

I'm not sure I see the need for this change; it doesn't look like the line was over the character limit, and functionally the two are identical, aren't they?

Given that I think they're identical, this doesn't block approval, I'm just curious what the intent was.

review: Approve
Revision history for this message
Данило Шеган (danilo) wrote :

The intent was to add the job ID to this line as well, and then that was reverted :) Reverting this change altogether, thanks for catching it. And thanks for the review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/scripts/tests/test_create_merge_proposals.py'
--- lib/lp/code/scripts/tests/test_create_merge_proposals.py 2010-10-04 19:50:45 +0000
+++ lib/lp/code/scripts/tests/test_create_merge_proposals.py 2011-08-12 13:56:33 +0000
@@ -33,7 +33,7 @@
33 email, file_alias, source, target = (33 email, file_alias, source, target = (
34 self.factory.makeMergeDirectiveEmail(34 self.factory.makeMergeDirectiveEmail(
35 signing_context=signing_context))35 signing_context=signing_context))
36 CreateMergeProposalJob.create(file_alias)36 job = CreateMergeProposalJob.create(file_alias)
37 self.assertEqual(0, source.landing_targets.count())37 self.assertEqual(0, source.landing_targets.count())
38 transaction.commit()38 transaction.commit()
39 retcode, stdout, stderr = run_script(39 retcode, stdout, stderr = run_script(
@@ -41,7 +41,8 @@
41 self.assertEqual(0, retcode)41 self.assertEqual(0, retcode)
42 self.assertEqual(42 self.assertEqual(
43 'INFO Creating lockfile: /var/lock/launchpad-create_merge_proposals.lock\n'43 'INFO Creating lockfile: /var/lock/launchpad-create_merge_proposals.lock\n'
44 'INFO Ran 1 CreateMergeProposalJobs.\n', stderr)44 'INFO Running CreateMergeProposalJob (ID %d) in status Waiting\n'
45 'INFO Ran 1 CreateMergeProposalJobs.\n' % job.job.id, stderr)
45 self.assertEqual('', stdout)46 self.assertEqual('', stdout)
46 self.assertEqual(1, source.landing_targets.count())47 self.assertEqual(1, source.landing_targets.count())
4748
4849
=== modified file 'lib/lp/code/scripts/tests/test_merge_proposal_jobs.py'
--- lib/lp/code/scripts/tests/test_merge_proposal_jobs.py 2010-12-02 16:13:51 +0000
+++ lib/lp/code/scripts/tests/test_merge_proposal_jobs.py 2011-08-12 13:56:33 +0000
@@ -34,7 +34,9 @@
34 'INFO Creating lockfile:'34 'INFO Creating lockfile:'
35 ' /var/lock/launchpad-merge-proposal-jobs.lock\n'35 ' /var/lock/launchpad-merge-proposal-jobs.lock\n'
36 'INFO Running through Twisted.\n'36 'INFO Running through Twisted.\n'
37 'INFO Ran 1 GenerateIncrementalDiffJob jobs.\n', stderr)37 'INFO Running GenerateIncrementalDiffJob (ID %d).\n'
38 'INFO Ran 1 GenerateIncrementalDiffJob jobs.\n' % job.job.id,
39 stderr)
38 self.assertEqual(JobStatus.COMPLETED, job.status)40 self.assertEqual(JobStatus.COMPLETED, job.status)
3941
4042
4143
=== modified file 'lib/lp/code/scripts/tests/test_reclaim_branch_space.py'
--- lib/lp/code/scripts/tests/test_reclaim_branch_space.py 2010-10-04 19:50:45 +0000
+++ lib/lp/code/scripts/tests/test_reclaim_branch_space.py 2011-08-12 13:56:33 +0000
@@ -66,7 +66,9 @@
66 self.assertEqual('', stdout)66 self.assertEqual('', stdout)
67 self.assertEqual(67 self.assertEqual(
68 'INFO Creating lockfile: /var/lock/launchpad-reclaimbranchspace.lock\n'68 'INFO Creating lockfile: /var/lock/launchpad-reclaimbranchspace.lock\n'
69 'INFO Reclaimed space for 1 branches.\n', stderr)69 'INFO Running ReclaimBranchSpaceJob (ID %d) in status Waiting\n'
70 'INFO Reclaimed space for 1 branches.\n' % reclaim_job.job.id,
71 stderr)
70 self.assertEqual(0, retcode)72 self.assertEqual(0, retcode)
71 self.assertFalse(73 self.assertFalse(
72 os.path.exists(mirrored_path))74 os.path.exists(mirrored_path))
7375
=== modified file 'lib/lp/code/scripts/tests/test_sendbranchmail.py'
--- lib/lp/code/scripts/tests/test_sendbranchmail.py 2011-07-18 20:46:27 +0000
+++ lib/lp/code/scripts/tests/test_sendbranchmail.py 2011-08-12 13:56:33 +0000
@@ -49,14 +49,15 @@
49 """Ensure sendbranchmail runs and sends email."""49 """Ensure sendbranchmail runs and sends email."""
50 self.useBzrBranches()50 self.useBzrBranches()
51 branch, tree = self.createBranch()51 branch, tree = self.createBranch()
52 RevisionMailJob.create(52 mail_job = RevisionMailJob.create(
53 branch, 1, 'from@example.org', 'body', True, 'foo')53 branch, 1, 'from@example.org', 'body', True, 'foo')
54 transaction.commit()54 transaction.commit()
55 retcode, stdout, stderr = run_script(55 retcode, stdout, stderr = run_script(
56 'cronscripts/sendbranchmail.py', [])56 'cronscripts/sendbranchmail.py', [])
57 self.assertEqual(57 self.assertEqual(
58 'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n'58 'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n'
59 'INFO Ran 1 RevisionMailJobs.\n', stderr)59 'INFO Running RevisionMailJob (ID %d) in status Waiting\n'
60 'INFO Ran 1 RevisionMailJobs.\n' % mail_job.job.id, stderr)
60 self.assertEqual('', stdout)61 self.assertEqual('', stdout)
61 self.assertEqual(0, retcode)62 self.assertEqual(0, retcode)
6263
@@ -86,14 +87,15 @@
86 # required to generate the revision-id.87 # required to generate the revision-id.
87 with override_environ(BZR_EMAIL='me@example.com'):88 with override_environ(BZR_EMAIL='me@example.com'):
88 tree.commit('Added foo.', rev_id='rev2')89 tree.commit('Added foo.', rev_id='rev2')
89 RevisionsAddedJob.create(90 job = RevisionsAddedJob.create(
90 branch, 'rev1', 'rev2', 'from@example.org')91 branch, 'rev1', 'rev2', 'from@example.org')
91 transaction.commit()92 transaction.commit()
92 retcode, stdout, stderr = run_script(93 retcode, stdout, stderr = run_script(
93 'cronscripts/sendbranchmail.py', [])94 'cronscripts/sendbranchmail.py', [])
94 self.assertEqual(95 self.assertEqual(
95 'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n'96 'INFO Creating lockfile: /var/lock/launchpad-sendbranchmail.lock\n'
96 'INFO Ran 1 RevisionMailJobs.\n',97 'INFO Running RevisionsAddedJob (ID %d) in status Waiting\n'
98 'INFO Ran 1 RevisionMailJobs.\n' % job.job.id,
97 stderr)99 stderr)
98 self.assertEqual('', stdout)100 self.assertEqual('', stdout)
99 self.assertEqual(0, retcode)101 self.assertEqual(0, retcode)
100102
=== modified file 'lib/lp/services/job/runner.py'
--- lib/lp/services/job/runner.py 2011-06-21 13:24:57 +0000
+++ lib/lp/services/job/runner.py 2011-08-12 13:56:33 +0000
@@ -182,8 +182,11 @@
182 """Attempt to run a job, updating its status as appropriate."""182 """Attempt to run a job, updating its status as appropriate."""
183 job = IRunnableJob(job)183 job = IRunnableJob(job)
184184
185 self.logger.debug(185 class_name = job.__class__.__name__
186 'Running job in status %s' % (job.status.title,))186 job_id = removeSecurityProxy(job).job.id
187 self.logger.info(
188 'Running %s (ID %d) in status %s' % (
189 class_name, job_id, job.status.title,))
187 job.start()190 job.start()
188 transaction.commit()191 transaction.commit()
189 do_retry = False192 do_retry = False
@@ -402,10 +405,10 @@
402 packages=('_pythonpath', 'twisted', 'ampoule'), env=env)405 packages=('_pythonpath', 'twisted', 'ampoule'), env=env)
403 super(TwistedJobRunner, self).__init__(logger, error_utility)406 super(TwistedJobRunner, self).__init__(logger, error_utility)
404 self.job_source = job_source407 self.job_source = job_source
405 import_name = '%s.%s' % (408 self.import_name = '%s.%s' % (
406 removeSecurityProxy(job_source).__module__, job_source.__name__)409 removeSecurityProxy(job_source).__module__, job_source.__name__)
407 self.pool = pool.ProcessPool(410 self.pool = pool.ProcessPool(
408 JobRunnerProcess, ampChildArgs=[import_name, str(dbuser)],411 JobRunnerProcess, ampChildArgs=[self.import_name, str(dbuser)],
409 starter=starter, min=0, timeout_signal=SIGHUP)412 starter=starter, min=0, timeout_signal=SIGHUP)
410413
411 def runJobInSubprocess(self, job):414 def runJobInSubprocess(self, job):
@@ -423,6 +426,12 @@
423 transaction.commit()426 transaction.commit()
424 job_id = job.id427 job_id = job.id
425 deadline = timegm(job.lease_expires.timetuple())428 deadline = timegm(job.lease_expires.timetuple())
429
430 # Log the job class and database ID for debugging purposes.
431 class_name = job.__class__.__name__
432 ijob_id = removeSecurityProxy(job).job.id
433 self.logger.info(
434 'Running %s (ID %d).' % (class_name, ijob_id))
426 self.logger.debug(435 self.logger.debug(
427 'Running %r, lease expires %s', job, job.lease_expires)436 'Running %r, lease expires %s', job, job.lease_expires)
428 deferred = self.pool.doWork(437 deferred = self.pool.doWork(
429438
=== modified file 'lib/lp/services/job/tests/test_runner.py'
--- lib/lp/services/job/tests/test_runner.py 2011-07-05 09:01:53 +0000
+++ lib/lp/services/job/tests/test_runner.py 2011-08-12 13:56:33 +0000
@@ -539,6 +539,8 @@
539 self.assertThat(logger.getLogBuffer(), MatchesRegex(539 self.assertThat(logger.getLogBuffer(), MatchesRegex(
540 dedent("""\540 dedent("""\
541 INFO Running through Twisted.541 INFO Running through Twisted.
542 INFO Running StuckJob \(ID .*\).
543 INFO Running StuckJob \(ID .*\).
542 INFO Job resulted in OOPS: .*544 INFO Job resulted in OOPS: .*
543 """)))545 """)))
544546
@@ -559,13 +561,16 @@
559 oops = self.getOopsReport(runner, 0)561 oops = self.getOopsReport(runner, 0)
560 self.assertEqual(562 self.assertEqual(
561 (1, 1), (len(runner.completed_jobs), len(runner.incomplete_jobs)))563 (1, 1), (len(runner.completed_jobs), len(runner.incomplete_jobs)))
562 self.assertEqual(564 self.assertThat(
563 (dedent("""\565 logger.getLogBuffer(), MatchesRegex(
564 INFO Running through Twisted.566 dedent("""\
565 INFO Job resulted in OOPS: %s567 INFO Running through Twisted.
566 """) % oops.id,568 INFO Running ShorterStuckJob \(ID .*\).
567 'TimeoutError', 'Job ran too long.'),569 INFO Running ShorterStuckJob \(ID .*\).
568 (logger.getLogBuffer(), oops.type, oops.value))570 INFO Job resulted in OOPS: %s
571 """) % oops.id))
572 self.assertEqual(('TimeoutError', 'Job ran too long.'),
573 (oops.type, oops.value))
569574
570 def test_previous_failure_gives_new_process(self):575 def test_previous_failure_gives_new_process(self):
571 """Failed jobs cause their worker to be terminated.576 """Failed jobs cause their worker to be terminated.
572577
=== modified file 'lib/lp/translations/scripts/tests/test_packaging_translations.py'
--- lib/lp/translations/scripts/tests/test_packaging_translations.py 2011-05-19 14:40:55 +0000
+++ lib/lp/translations/scripts/tests/test_packaging_translations.py 2011-08-12 13:56:33 +0000
@@ -34,8 +34,10 @@
34 matcher = MatchesRegex(dedent("""\34 matcher = MatchesRegex(dedent("""\
35 INFO Creating lockfile: /var/lock/launchpad-jobcronscript.lock35 INFO Creating lockfile: /var/lock/launchpad-jobcronscript.lock
36 INFO Running synchronously.36 INFO Running synchronously.
37 INFO Running TranslationMergeJob \(ID .*\) in status Waiting
37 INFO Merging .* and .* in Ubuntu Distroseries.*38 INFO Merging .* and .* in Ubuntu Distroseries.*
38 INFO Deleted POTMsgSets: 1. TranslationMessages: 1.39 INFO Deleted POTMsgSets: 1. TranslationMessages: 1.
40 INFO Running TranslationSplitJob \(ID .*\) in status Waiting
39 INFO Splitting .* and .* in Ubuntu Distroseries.*41 INFO Splitting .* and .* in Ubuntu Distroseries.*
40 INFO Ran 1 TranslationMergeJob jobs.42 INFO Ran 1 TranslationMergeJob jobs.
41 INFO Ran 1 TranslationSplitJob jobs.43 INFO Ran 1 TranslationSplitJob jobs.