7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
1 |
#!/usr/bin/python -S
|
2 |
#
|
|
3 |
# Copyright 2009, 2010 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
6 |
"""Handle jobs for a specified job source class."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
||
14612.2.8
by William Grant
cronscripts |
10 |
import _pythonpath |
11 |
||
7675.845.20
by Edwin Grubbs
Formatted imports and delinted. |
12 |
import sys |
13 |
||
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
14 |
from twisted.python import log |
15 |
||
14605.1.1
by Curtis Hovey
Moved canonical.config to lp.services. |
16 |
from lp.services.config import config |
7675.845.20
by Edwin Grubbs
Formatted imports and delinted. |
17 |
from lp.services.job import runner |
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
18 |
from lp.services.job.runner import JobCronScript |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
19 |
|
20 |
||
21 |
class ProcessJobSource(JobCronScript): |
|
7675.845.23
by Edwin Grubbs
Addressed more review comments. |
22 |
"""Run jobs for a specified job source class."""
|
23 |
usage = ( |
|
24 |
"Usage: %prog [options] JOB_SOURCE\n\n" |
|
25 |
"For more help, run:\n" |
|
26 |
" cronscripts/process-job-source-groups.py --help") |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
27 |
|
7675.845.26
by Edwin Grubbs
Simplified cron script. |
28 |
def __init__(self): |
29 |
super(ProcessJobSource, self).__init__() |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
30 |
# The fromlist argument is necessary so that __import__()
|
31 |
# returns the bottom submodule instead of the top one.
|
|
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
32 |
module = __import__(self.config_section.module, |
33 |
fromlist=[self.job_source_name]) |
|
34 |
self.source_interface = getattr(module, self.job_source_name) |
|
35 |
||
36 |
@property
|
|
37 |
def config_name(self): |
|
38 |
return self.job_source_name |
|
39 |
||
40 |
@property
|
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
41 |
def name(self): |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
42 |
return 'process-job-source-%s' % self.job_source_name |
43 |
||
44 |
@property
|
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
45 |
def runner_class(self): |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
46 |
runner_class_name = getattr( |
47 |
self.config_section, 'runner_class', 'JobRunner') |
|
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
48 |
# Override attributes that are normally set in __init__().
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
49 |
return getattr(runner, runner_class_name) |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
50 |
|
13701.1.6
by Aaron Bentley
Special-case process-job-source. |
51 |
def add_my_options(self): |
52 |
self.add_log_twisted_option() |
|
53 |
||
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
54 |
def handle_options(self): |
55 |
if len(self.args) != 1: |
|
56 |
self.parser.print_help() |
|
57 |
sys.exit(1) |
|
58 |
self.job_source_name = self.args[0] |
|
7675.845.28
by Edwin Grubbs
Fixed tests after re-organizing command-line overrides of LaunchpadScript attributes. |
59 |
super(ProcessJobSource, self).handle_options() |
7675.845.27
by Edwin Grubbs
Merged in db-devel. |
60 |
|
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
61 |
def main(self): |
62 |
if self.options.verbose: |
|
63 |
log.startLogging(sys.stdout) |
|
64 |
super(ProcessJobSource, self).main() |
|
65 |
||
66 |
||
67 |
if __name__ == '__main__': |
|
7675.845.22
by Edwin Grubbs
Suggestions from reviewer. |
68 |
script = ProcessJobSource() |
7675.845.17
by Edwin Grubbs
Working as two separate cron scripts. |
69 |
script.lock_and_run() |