Show More
@@ -0,0 +1,4 b'' | |||||
|
1 | ## Broker settings. | |||
|
2 | BROKER_VHOST = "rabbitmqhost" | |||
|
3 | BROKER_USER = "rabbitmq" | |||
|
4 | BROKER_PASSWORD = "qweqwe" |
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.lib.celerylib.tasks |
|
3 | rhodecode.lib.celerylib.tasks | |
4 | ~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | RhodeCode task modules, containing all task that suppose to be run |
|
6 | RhodeCode task modules, containing all task that suppose to be run | |
7 | by celery daemon |
|
7 | by celery daemon | |
@@ -29,6 +29,8 b' from celery.decorators import task' | |||||
29 |
|
29 | |||
30 | import os |
|
30 | import os | |
31 | import traceback |
|
31 | import traceback | |
|
32 | import logging | |||
|
33 | ||||
32 | from time import mktime |
|
34 | from time import mktime | |
33 | from operator import itemgetter |
|
35 | from operator import itemgetter | |
34 |
|
36 | |||
@@ -72,21 +74,25 b' def get_repos_path():' | |||||
72 | q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one() |
|
74 | q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one() | |
73 | return q.ui_value |
|
75 | return q.ui_value | |
74 |
|
76 | |||
75 | @task |
|
77 | @task(ignore_result=True) | |
76 | @locked_task |
|
78 | @locked_task | |
77 | def whoosh_index(repo_location, full_index): |
|
79 | def whoosh_index(repo_location, full_index): | |
78 | log = whoosh_index.get_logger() |
|
80 | #log = whoosh_index.get_logger() | |
79 | from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon |
|
81 | from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon | |
80 | index_location = config['index_dir'] |
|
82 | index_location = config['index_dir'] | |
81 | WhooshIndexingDaemon(index_location=index_location, |
|
83 | WhooshIndexingDaemon(index_location=index_location, | |
82 | repo_location=repo_location, sa=get_session())\ |
|
84 | repo_location=repo_location, sa=get_session())\ | |
83 | .run(full_index=full_index) |
|
85 | .run(full_index=full_index) | |
84 |
|
86 | |||
85 | @task |
|
87 | @task(ignore_result=True) | |
86 | @locked_task |
|
88 | @locked_task | |
87 | def get_commits_stats(repo_name, ts_min_y, ts_max_y): |
|
89 | def get_commits_stats(repo_name, ts_min_y, ts_max_y): | |
|
90 | try: | |||
|
91 | log = get_commits_stats.get_logger() | |||
|
92 | except: | |||
|
93 | log = logging.getLogger(__name__) | |||
|
94 | ||||
88 | from rhodecode.model.db import Statistics, Repository |
|
95 | from rhodecode.model.db import Statistics, Repository | |
89 | log = get_commits_stats.get_logger() |
|
|||
90 |
|
96 | |||
91 | #for js data compatibilty |
|
97 | #for js data compatibilty | |
92 | author_key_cleaner = lambda k: person(k).replace('"', "") |
|
98 | author_key_cleaner = lambda k: person(k).replace('"', "") | |
@@ -218,9 +224,13 b' def get_commits_stats(repo_name, ts_min_' | |||||
218 |
|
224 | |||
219 | return True |
|
225 | return True | |
220 |
|
226 | |||
221 | @task |
|
227 | @task(ignore_result=True) | |
222 | def reset_user_password(user_email): |
|
228 | def reset_user_password(user_email): | |
223 | log = reset_user_password.get_logger() |
|
229 | try: | |
|
230 | log = reset_user_password.get_logger() | |||
|
231 | except: | |||
|
232 | log = logging.getLogger(__name__) | |||
|
233 | ||||
224 | from rhodecode.lib import auth |
|
234 | from rhodecode.lib import auth | |
225 | from rhodecode.model.db import User |
|
235 | from rhodecode.model.db import User | |
226 |
|
236 | |||
@@ -254,7 +264,7 b' def reset_user_password(user_email):' | |||||
254 |
|
264 | |||
255 | return True |
|
265 | return True | |
256 |
|
266 | |||
257 | @task |
|
267 | @task(ignore_result=True) | |
258 | def send_email(recipients, subject, body): |
|
268 | def send_email(recipients, subject, body): | |
259 | """ |
|
269 | """ | |
260 | Sends an email with defined parameters from the .ini files. |
|
270 | Sends an email with defined parameters from the .ini files. | |
@@ -265,7 +275,11 b' def send_email(recipients, subject, body' | |||||
265 | :param subject: subject of the mail |
|
275 | :param subject: subject of the mail | |
266 | :param body: body of the mail |
|
276 | :param body: body of the mail | |
267 | """ |
|
277 | """ | |
268 | log = send_email.get_logger() |
|
278 | try: | |
|
279 | log = send_email.get_logger() | |||
|
280 | except: | |||
|
281 | log = logging.getLogger(__name__) | |||
|
282 | ||||
269 | email_config = config |
|
283 | email_config = config | |
270 |
|
284 | |||
271 | if not recipients: |
|
285 | if not recipients: | |
@@ -289,11 +303,16 b' def send_email(recipients, subject, body' | |||||
289 | return False |
|
303 | return False | |
290 | return True |
|
304 | return True | |
291 |
|
305 | |||
292 | @task |
|
306 | @task(ignore_result=True) | |
293 | def create_repo_fork(form_data, cur_user): |
|
307 | def create_repo_fork(form_data, cur_user): | |
|
308 | try: | |||
|
309 | log = create_repo_fork.get_logger() | |||
|
310 | except: | |||
|
311 | log = logging.getLogger(__name__) | |||
|
312 | ||||
294 | from rhodecode.model.repo import RepoModel |
|
313 | from rhodecode.model.repo import RepoModel | |
295 | from vcs import get_backend |
|
314 | from vcs import get_backend | |
296 | log = create_repo_fork.get_logger() |
|
315 | ||
297 | repo_model = RepoModel(get_session()) |
|
316 | repo_model = RepoModel(get_session()) | |
298 | repo_model.create(form_data, cur_user, just_db=True, fork=True) |
|
317 | repo_model.create(form_data, cur_user, just_db=True, fork=True) | |
299 | repo_name = form_data['repo_name'] |
|
318 | repo_name = form_data['repo_name'] |
@@ -1,11 +1,35 b'' | |||||
1 | from rhodecode.lib.utils import BasePasterCommand, Command |
|
1 | from rhodecode.lib.utils import BasePasterCommand, Command | |
2 |
|
2 | from celery.app import app_or_default | ||
|
3 | from celery.bin import camqadm, celerybeat, celeryd, celeryev | |||
3 |
|
4 | |||
4 | __all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand', |
|
5 | __all__ = ['CeleryDaemonCommand', 'CeleryBeatCommand', | |
5 | 'CAMQPAdminCommand', 'CeleryEventCommand'] |
|
6 | 'CAMQPAdminCommand', 'CeleryEventCommand'] | |
6 |
|
7 | |||
7 |
|
8 | |||
8 |
class Celery |
|
9 | class CeleryCommand(BasePasterCommand): | |
|
10 | """Abstract class implements run methods needed for celery | |||
|
11 | ||||
|
12 | Starts the celery worker that uses a paste.deploy configuration | |||
|
13 | file. | |||
|
14 | """ | |||
|
15 | ||||
|
16 | def update_parser(self): | |||
|
17 | """ | |||
|
18 | Abstract method. Allows for the class's parser to be updated | |||
|
19 | before the superclass's `run` method is called. Necessary to | |||
|
20 | allow options/arguments to be passed through to the underlying | |||
|
21 | celery command. | |||
|
22 | """ | |||
|
23 | ||||
|
24 | cmd = self.celery_command(app_or_default()) | |||
|
25 | for x in cmd.get_options(): | |||
|
26 | self.parser.add_option(x) | |||
|
27 | ||||
|
28 | def command(self): | |||
|
29 | cmd = self.celery_command(app_or_default()) | |||
|
30 | return cmd.run(**vars(self.options)) | |||
|
31 | ||||
|
32 | class CeleryDaemonCommand(CeleryCommand): | |||
9 | """Start the celery worker |
|
33 | """Start the celery worker | |
10 |
|
34 | |||
11 | Starts the celery worker that uses a paste.deploy configuration |
|
35 | Starts the celery worker that uses a paste.deploy configuration | |
@@ -16,18 +40,10 b' class CeleryDaemonCommand(BasePasterComm' | |||||
16 | description = "".join(__doc__.splitlines()[2:]) |
|
40 | description = "".join(__doc__.splitlines()[2:]) | |
17 |
|
41 | |||
18 | parser = Command.standard_parser(quiet=True) |
|
42 | parser = Command.standard_parser(quiet=True) | |
19 |
|
43 | celery_command = celeryd.WorkerCommand | ||
20 | def update_parser(self): |
|
|||
21 | from celery.bin import celeryd |
|
|||
22 | for x in celeryd.WorkerCommand().get_options(): |
|
|||
23 | self.parser.add_option(x) |
|
|||
24 |
|
||||
25 | def command(self): |
|
|||
26 | from celery.bin import celeryd |
|
|||
27 | return celeryd.WorkerCommand().run(**vars(self.options)) |
|
|||
28 |
|
44 | |||
29 |
|
45 | |||
30 |
class CeleryBeatCommand( |
|
46 | class CeleryBeatCommand(CeleryCommand): | |
31 | """Start the celery beat server |
|
47 | """Start the celery beat server | |
32 |
|
48 | |||
33 | Starts the celery beat server using a paste.deploy configuration |
|
49 | Starts the celery beat server using a paste.deploy configuration | |
@@ -38,17 +54,10 b' class CeleryBeatCommand(BasePasterComman' | |||||
38 | description = "".join(__doc__.splitlines()[2:]) |
|
54 | description = "".join(__doc__.splitlines()[2:]) | |
39 |
|
55 | |||
40 | parser = Command.standard_parser(quiet=True) |
|
56 | parser = Command.standard_parser(quiet=True) | |
41 |
|
57 | celery_command = celerybeat.BeatCommand | ||
42 | def update_parser(self): |
|
|||
43 | from celery.bin import celerybeat |
|
|||
44 | for x in celerybeat.BeatCommand().get_options(): |
|
|||
45 | self.parser.add_option(x) |
|
|||
46 |
|
58 | |||
47 | def command(self): |
|
|||
48 | from celery.bin import celerybeat |
|
|||
49 | return celerybeat.BeatCommand(**vars(self.options)) |
|
|||
50 |
|
59 | |||
51 |
class CAMQPAdminCommand( |
|
60 | class CAMQPAdminCommand(CeleryCommand): | |
52 | """CAMQP Admin |
|
61 | """CAMQP Admin | |
53 |
|
62 | |||
54 | CAMQP celery admin tool. |
|
63 | CAMQP celery admin tool. | |
@@ -58,19 +67,10 b' class CAMQPAdminCommand(BasePasterComman' | |||||
58 | description = "".join(__doc__.splitlines()[2:]) |
|
67 | description = "".join(__doc__.splitlines()[2:]) | |
59 |
|
68 | |||
60 | parser = Command.standard_parser(quiet=True) |
|
69 | parser = Command.standard_parser(quiet=True) | |
61 |
|
70 | celery_command = camqadm.AMQPAdminCommand | ||
62 | def update_parser(self): |
|
|||
63 | from celery.bin import camqadm |
|
|||
64 | for x in camqadm.OPTION_LIST: |
|
|||
65 | self.parser.add_option(x) |
|
|||
66 |
|
71 | |||
67 | def command(self): |
|
72 | class CeleryEventCommand(CeleryCommand): | |
68 | from celery.bin import camqadm |
|
73 | """Celery event command. | |
69 | return camqadm.camqadm(*self.args, **vars(self.options)) |
|
|||
70 |
|
||||
71 |
|
||||
72 | class CeleryEventCommand(BasePasterCommand): |
|
|||
73 | """Celery event commandd. |
|
|||
74 |
|
74 | |||
75 | Capture celery events. |
|
75 | Capture celery events. | |
76 | """ |
|
76 | """ | |
@@ -79,12 +79,4 b' class CeleryEventCommand(BasePasterComma' | |||||
79 | description = "".join(__doc__.splitlines()[2:]) |
|
79 | description = "".join(__doc__.splitlines()[2:]) | |
80 |
|
80 | |||
81 | parser = Command.standard_parser(quiet=True) |
|
81 | parser = Command.standard_parser(quiet=True) | |
82 |
|
82 | celery_command = celeryev.EvCommand | ||
83 | def update_parser(self): |
|
|||
84 | from celery.bin import celeryev |
|
|||
85 | for x in celeryev.OPTION_LIST: |
|
|||
86 | self.parser.add_option(x) |
|
|||
87 |
|
||||
88 | def command(self): |
|
|||
89 | from celery.bin import celeryev |
|
|||
90 | return celeryev.run_celeryev(**vars(self.options)) |
|
@@ -17,15 +17,29 b' class PylonsSettingsProxy(object):' | |||||
17 | pylons_key = to_pylons(key) |
|
17 | pylons_key = to_pylons(key) | |
18 | try: |
|
18 | try: | |
19 | value = config[pylons_key] |
|
19 | value = config[pylons_key] | |
20 |
if key in LIST_PARAMS: |
|
20 | if key in LIST_PARAMS:return value.split() | |
21 | return self.type_converter(value) |
|
21 | return self.type_converter(value) | |
22 | except KeyError: |
|
22 | except KeyError: | |
23 | raise AttributeError(pylons_key) |
|
23 | raise AttributeError(pylons_key) | |
24 |
|
24 | |||
|
25 | def get(self, key): | |||
|
26 | try: | |||
|
27 | return self.__getattr__(key) | |||
|
28 | except AttributeError: | |||
|
29 | return None | |||
|
30 | ||||
|
31 | def __getitem__(self, key): | |||
|
32 | try: | |||
|
33 | return self.__getattr__(key) | |||
|
34 | except AttributeError: | |||
|
35 | raise KeyError() | |||
|
36 | ||||
25 | def __setattr__(self, key, value): |
|
37 | def __setattr__(self, key, value): | |
26 | pylons_key = to_pylons(key) |
|
38 | pylons_key = to_pylons(key) | |
27 | config[pylons_key] = value |
|
39 | config[pylons_key] = value | |
28 |
|
40 | |||
|
41 | def __setitem__(self, key, value): | |||
|
42 | self.__setattr__(key, value) | |||
29 |
|
43 | |||
30 | def type_converter(self, value): |
|
44 | def type_converter(self, value): | |
31 | #cast to int |
|
45 | #cast to int | |
@@ -35,7 +49,6 b' class PylonsSettingsProxy(object):' | |||||
35 | #cast to bool |
|
49 | #cast to bool | |
36 | if value.lower() in ['true', 'false']: |
|
50 | if value.lower() in ['true', 'false']: | |
37 | return value.lower() == 'true' |
|
51 | return value.lower() == 'true' | |
38 |
|
||||
39 | return value |
|
52 | return value | |
40 |
|
53 | |||
41 | class PylonsLoader(BaseLoader): |
|
54 | class PylonsLoader(BaseLoader): |
General Comments 0
You need to be logged in to leave comments.
Login now