~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/job/runner.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    IJob,
52
52
    IRunnableJob,
53
53
    LeaseHeld,
 
54
    SuspendJobException,
54
55
    )
55
56
from lp.services.mail.sendmail import MailController
56
57
from lp.services.scripts.base import LaunchpadCronScript
73
74
 
74
75
    user_error_types = ()
75
76
 
 
77
    retry_error_types = ()
 
78
 
76
79
    # We redefine __eq__ and __ne__ here to prevent the security proxy
77
80
    # from mucking up our comparisons in tests and elsewhere.
78
81
    def __eq__(self, job):
170
173
            'Running job in status %s' % (job.status.title,))
171
174
        job.start()
172
175
        transaction.commit()
173
 
 
 
176
        do_retry = False
174
177
        try:
175
 
            job.run()
 
178
            try:
 
179
                job.run()
 
180
            except job.retry_error_types, e:
 
181
                if job.attempt_count > job.max_retries:
 
182
                    raise
 
183
                self.logger.exception(
 
184
                    "Scheduling retry due to %s.", e.__class__.__name__)
 
185
                do_retry = True
 
186
        except SuspendJobException:
 
187
            self.logger.debug("Job suspended itself")
 
188
            job.suspend()
 
189
            self.incomplete_jobs.append(job)
176
190
        except Exception:
177
191
            self.logger.exception("Job execution raised an exception.")
178
192
            transaction.abort()
184
198
        else:
185
199
            # Commit transaction to update the DB time.
186
200
            transaction.commit()
187
 
            job.complete()
188
 
            self.completed_jobs.append(job)
 
201
            if do_retry:
 
202
                job.queue()
 
203
                self.incomplete_jobs.append(job)
 
204
            else:
 
205
                job.complete()
 
206
                self.completed_jobs.append(job)
189
207
        # Commit transaction to update job status.
190
208
        transaction.commit()
191
209