~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to cronscripts/sendbranchmail.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-13 13:23:34 UTC
  • mfrom: (13278.1.14 memlimit-sendbranchmail)
  • Revision ID: launchpad@pqm.canonical.com-20110713132334-y32hd2pmboy1tjyz
[r=abentley][bug=585126] Memory-limit branch mail jobs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2008-2011 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
# pylint: disable-msg=W0403
12
12
 
13
13
__metaclass__ = type
14
14
 
 
15
 
 
16
import logging
 
17
 
15
18
import _pythonpath
16
 
from zope.component import getUtility
17
19
 
18
20
from canonical.config import config
19
 
from lp.codehosting.vfs import get_ro_server
20
 
from lp.services.job.runner import JobRunner
21
 
from lp.code.interfaces.branchjob import (
22
 
    IRevisionMailJobSource, IRevisionsAddedJobSource)
 
21
from lp.services.job.runner import (
 
22
    TwistedJobRunner,
 
23
    )
 
24
from lp.code.model.branchjob import (
 
25
    BranchMailJobSource,
 
26
    )
23
27
from lp.services.scripts.base import LaunchpadCronScript
24
28
from canonical.launchpad.webapp.errorlog import globalErrorUtility
25
29
 
29
33
 
30
34
    def main(self):
31
35
        globalErrorUtility.configure('sendbranchmail')
32
 
        jobs = list(getUtility(IRevisionMailJobSource).iterReady())
33
 
        jobs.extend(getUtility(IRevisionsAddedJobSource).iterReady())
34
 
        runner = JobRunner(jobs, self.logger)
35
 
        server = get_ro_server()
36
 
        server.start_server()
37
 
        try:
38
 
            runner.runAll()
39
 
        finally:
40
 
            server.stop_server()
 
36
        runner = TwistedJobRunner.runFromSource(
 
37
            BranchMailJobSource, 'send-branch-mail', logging.getLogger())
41
38
        self.logger.info(
42
39
            'Ran %d RevisionMailJobs.' % len(runner.completed_jobs))
43
40