~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
13463.2.1 by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways).
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
6805.19.67 by Aaron Bentley
Suppress lint warning (as per other scripts)
6
# pylint: disable-msg=W0403
6805.19.8 by Aaron Bentley
Add script to run code emails
7
6805.19.42 by Aaron Bentley
Initial work on running mail jobs
8
"""Send branch mail.
6805.19.8 by Aaron Bentley
Add script to run code emails
9
10
This script sends out all the mail jobs that are pending.
11
"""
12
13
__metaclass__ = type
14
15
import _pythonpath
13463.2.1 by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways).
16
from zope.component import getUtility
6805.19.8 by Aaron Bentley
Add script to run code emails
17
6805.19.62 by Aaron Bentley
Update to use codejobrunner user and zopeless layer
18
from canonical.config import config
13463.2.1 by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways).
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)
8356.1.1 by Leonard Richardson
Partial move.
23
from lp.services.scripts.base import LaunchpadCronScript
6805.19.62 by Aaron Bentley
Update to use codejobrunner user and zopeless layer
24
from canonical.launchpad.webapp.errorlog import globalErrorUtility
6805.19.8 by Aaron Bentley
Add script to run code emails
25
26
6805.19.42 by Aaron Bentley
Initial work on running mail jobs
27
class RunRevisionMailJobs(LaunchpadCronScript):
6805.19.46 by Aaron Bentley
Get sendbranchmail under test.
28
    """Run pending branch mail jobs."""
6805.19.8 by Aaron Bentley
Add script to run code emails
29
30
    def main(self):
6805.19.62 by Aaron Bentley
Update to use codejobrunner user and zopeless layer
31
        globalErrorUtility.configure('sendbranchmail')
13463.2.1 by William Grant
Revert r13420 (the relanding of r13292, which broke production in similar ways).
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()
7797.1.18 by Aaron Bentley
Output via logger instead of stdout
41
        self.logger.info(
42
            'Ran %d RevisionMailJobs.' % len(runner.completed_jobs))
6805.19.8 by Aaron Bentley
Add script to run code emails
43
44
45
if __name__ == '__main__':
7675.12.1 by Tim Penhey
Create explicit db users for every script.
46
    script = RunRevisionMailJobs(
47
        'sendbranchmail', config.sendbranchmail.dbuser)
6805.19.62 by Aaron Bentley
Update to use codejobrunner user and zopeless layer
48
    script.lock_and_run()