~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to cronscripts/sendbranchmail.py

MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
2
#
3
 
# Copyright 2008-2011 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009 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
 
 
18
15
import _pythonpath
 
16
from zope.component import getUtility
19
17
 
20
18
from canonical.config import config
21
 
from lp.services.job.runner import (
22
 
    TwistedJobRunner,
23
 
    )
24
 
from lp.code.model.branchjob import (
25
 
    BranchMailJobSource,
26
 
    )
 
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)
27
23
from lp.services.scripts.base import LaunchpadCronScript
28
24
from canonical.launchpad.webapp.errorlog import globalErrorUtility
29
25
 
33
29
 
34
30
    def main(self):
35
31
        globalErrorUtility.configure('sendbranchmail')
36
 
        runner = TwistedJobRunner.runFromSource(
37
 
            BranchMailJobSource, 'send-branch-mail', logging.getLogger())
 
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()
38
41
        self.logger.info(
39
42
            'Ran %d RevisionMailJobs.' % len(runner.completed_jobs))
40
43