Mercurial > kallithea
comparison rhodecode/lib/celerypylons/commands.py @ 785:277427ac29a9 beta
complete rewrite of paster commands,
used fancy celery-pylons baseCommand to implement better support for paster commands
fixed make-index, and paster celeryd. Moved config's add_cache to utils
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 28 Nov 2010 05:31:05 +0100 |
parents | f6c613fba757 |
children | 3a7f5b1a19dd |
comparison
equal
deleted
inserted
replaced
784:30d3161c6683 | 785:277427ac29a9 |
---|---|
1 import os | 1 from rhodecode.lib.utils import BasePasterCommand, Command |
2 from paste.script.command import Command, BadCommand | |
3 import paste.deploy | |
4 from pylons import config | |
5 | 2 |
6 | 3 |
7 __all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand', | 4 __all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand', |
8 'CAMQPAdminCommand', 'CeleryEventCommand'] | 5 'CAMQPAdminCommand', 'CeleryEventCommand'] |
9 | 6 |
10 | 7 |
11 class CeleryCommand(Command): | 8 class CeleryDaemonCommand(BasePasterCommand): |
12 """ | |
13 Abstract Base Class for celery commands. | |
14 | |
15 The celery commands are somewhat aggressive about loading | |
16 celery.conf, and since our module sets the `CELERY_LOADER` | |
17 environment variable to our loader, we have to bootstrap a bit and | |
18 make sure we've had a chance to load the pylons config off of the | |
19 command line, otherwise everything fails. | |
20 """ | |
21 min_args = 1 | |
22 min_args_error = "Please provide a paster config file as an argument." | |
23 takes_config_file = 1 | |
24 requires_config_file = True | |
25 | |
26 def run(self, args): | |
27 """ | |
28 Overrides Command.run | |
29 | |
30 Checks for a config file argument and loads it. | |
31 """ | |
32 if len(args) < self.min_args: | |
33 raise BadCommand( | |
34 self.min_args_error % {'min_args': self.min_args, | |
35 'actual_args': len(args)}) | |
36 # Decrement because we're going to lob off the first argument. | |
37 # @@ This is hacky | |
38 self.min_args -= 1 | |
39 self.bootstrap_config(args[0]) | |
40 self.update_parser() | |
41 return super(CeleryCommand, self).run(args[1:]) | |
42 | |
43 def update_parser(self): | |
44 """ | |
45 Abstract method. Allows for the class's parser to be updated | |
46 before the superclass's `run` method is called. Necessary to | |
47 allow options/arguments to be passed through to the underlying | |
48 celery command. | |
49 """ | |
50 raise NotImplementedError("Abstract Method.") | |
51 | |
52 def bootstrap_config(self, conf): | |
53 """ | |
54 Loads the pylons configuration. | |
55 """ | |
56 path_to_ini_file = os.path.realpath(conf) | |
57 conf = paste.deploy.appconfig('config:' + path_to_ini_file) | |
58 config.init_app(conf.global_conf, conf.local_conf) | |
59 | |
60 | |
61 class CeleryDaemonCommand(CeleryCommand): | |
62 """Start the celery worker | 9 """Start the celery worker |
63 | 10 |
64 Starts the celery worker that uses a paste.deploy configuration | 11 Starts the celery worker that uses a paste.deploy configuration |
65 file. | 12 file. |
66 """ | 13 """ |
78 def command(self): | 25 def command(self): |
79 from celery.bin import celeryd | 26 from celery.bin import celeryd |
80 return celeryd.WorkerCommand().run(**vars(self.options)) | 27 return celeryd.WorkerCommand().run(**vars(self.options)) |
81 | 28 |
82 | 29 |
83 class CeleryBeatCommand(CeleryCommand): | 30 class CeleryBeatCommand(BasePasterCommand): |
84 """Start the celery beat server | 31 """Start the celery beat server |
85 | 32 |
86 Starts the celery beat server using a paste.deploy configuration | 33 Starts the celery beat server using a paste.deploy configuration |
87 file. | 34 file. |
88 """ | 35 """ |
99 | 46 |
100 def command(self): | 47 def command(self): |
101 from celery.bin import celerybeat | 48 from celery.bin import celerybeat |
102 return celerybeat.BeatCommand(**vars(self.options)) | 49 return celerybeat.BeatCommand(**vars(self.options)) |
103 | 50 |
104 class CAMQPAdminCommand(CeleryCommand): | 51 class CAMQPAdminCommand(BasePasterCommand): |
105 """CAMQP Admin | 52 """CAMQP Admin |
106 | 53 |
107 CAMQP celery admin tool. | 54 CAMQP celery admin tool. |
108 """ | 55 """ |
109 usage = 'CONFIG_FILE [camqadm options...]' | 56 usage = 'CONFIG_FILE [camqadm options...]' |
120 def command(self): | 67 def command(self): |
121 from celery.bin import camqadm | 68 from celery.bin import camqadm |
122 return camqadm.camqadm(*self.args, **vars(self.options)) | 69 return camqadm.camqadm(*self.args, **vars(self.options)) |
123 | 70 |
124 | 71 |
125 class CeleryEventCommand(CeleryCommand): | 72 class CeleryEventCommand(BasePasterCommand): |
126 """Celery event commandd. | 73 """Celery event commandd. |
127 | 74 |
128 Capture celery events. | 75 Capture celery events. |
129 """ | 76 """ |
130 usage = 'CONFIG_FILE [celeryev options...]' | 77 usage = 'CONFIG_FILE [celeryev options...]' |