##// END OF EJS Templates
backported #340 session cleanup for celery tasks
marcink -
r1937:afe8cfa3 default
parent child Browse files
Show More
@@ -25,7 +25,7 b''
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import platform
26 import platform
27
27
28 VERSION = (1, 2, 4)
28 VERSION = (1, 2, 5)
29 __version__ = '.'.join((str(each) for each in VERSION[:4]))
29 __version__ = '.'.join((str(each) for each in VERSION[:4]))
30 __dbversion__ = 3 # defines current db version for migrations
30 __dbversion__ = 3 # defines current db version for migrations
31 __platform__ = platform.system()
31 __platform__ = platform.system()
@@ -7,7 +7,7 b''
7
7
8 :created_on: Nov 27, 2010
8 :created_on: Nov 27, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
@@ -29,19 +29,23 b' import socket'
29 import traceback
29 import traceback
30 import logging
30 import logging
31 from os.path import dirname as dn, join as jn
31 from os.path import dirname as dn, join as jn
32 from pylons import config
32
33
33 from hashlib import md5
34 from hashlib import md5
34 from decorator import decorator
35 from decorator import decorator
35 from pylons import config
36
36
37 from vcs.utils.lazy import LazyProperty
37 from vcs.utils.lazy import LazyProperty
38
38
39 from rhodecode.lib import str2bool, safe_str
39 from rhodecode.lib import str2bool, safe_str
40 from rhodecode.lib.pidlock import DaemonLock, LockHeld
40 from rhodecode.lib.pidlock import DaemonLock, LockHeld
41 from rhodecode.model import init_model
42 from rhodecode.model import meta
43 from rhodecode.model.db import Statistics, Repository, User
44
45 from sqlalchemy import engine_from_config
41
46
42 from celery.messaging import establish_connection
47 from celery.messaging import establish_connection
43
48
44
45 log = logging.getLogger(__name__)
49 log = logging.getLogger(__name__)
46
50
47 try:
51 try:
@@ -107,3 +111,23 b' def locked_task(func):'
107 return 'Task with key %s already running' % lockkey
111 return 'Task with key %s already running' % lockkey
108
112
109 return decorator(__wrapper, func)
113 return decorator(__wrapper, func)
114
115
116 def get_session():
117 if CELERY_ON:
118 engine = engine_from_config(config, 'sqlalchemy.db1.')
119 init_model(engine)
120 sa = meta.Session
121 return sa
122
123
124 def dbsession(func):
125 def __wrapper(func, *fargs, **fkwargs):
126 try:
127 ret = func(*fargs, **fkwargs)
128 return ret
129 finally:
130 if CELERY_ON:
131 meta.Session.remove()
132
133 return decorator(__wrapper, func)
@@ -8,7 +8,7 b''
8
8
9 :created_on: Oct 6, 2010
9 :created_on: Oct 6, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
@@ -39,19 +39,16 b' from pylons.i18n.translation import _'
39
39
40 from rhodecode.lib import LANGUAGES_EXTENSIONS_MAP, safe_str
40 from rhodecode.lib import LANGUAGES_EXTENSIONS_MAP, safe_str
41 from rhodecode.lib.celerylib import run_task, locked_task, str2bool, \
41 from rhodecode.lib.celerylib import run_task, locked_task, str2bool, \
42 __get_lockkey, LockHeld, DaemonLock
42 __get_lockkey, LockHeld, DaemonLock, get_session, dbsession
43 from rhodecode.lib.helpers import person
43 from rhodecode.lib.helpers import person
44 from rhodecode.lib.smtp_mailer import SmtpMailer
44 from rhodecode.lib.smtp_mailer import SmtpMailer
45 from rhodecode.lib.utils import add_cache
45 from rhodecode.lib.utils import add_cache
46 from rhodecode.lib.compat import json, OrderedDict
46 from rhodecode.lib.compat import json, OrderedDict
47
47
48 from rhodecode.model import init_model
49 from rhodecode.model import meta
50 from rhodecode.model.db import RhodeCodeUi, Statistics, Repository, User
48 from rhodecode.model.db import RhodeCodeUi, Statistics, Repository, User
51
49
52 from vcs.backends import get_repo
50 from vcs.backends import get_repo
53
51 from vcs import get_backend
54 from sqlalchemy import engine_from_config
55
52
56 add_cache(config)
53 add_cache(config)
57
54
@@ -61,15 +58,6 b' add_cache(config)'
61 CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
58 CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
62
59
63
60
64 def get_session():
65 if CELERY_ON:
66 engine = engine_from_config(config, 'sqlalchemy.db1.')
67 init_model(engine)
68
69 sa = meta.Session()
70 return sa
71
72
73 def get_repos_path():
61 def get_repos_path():
74 sa = get_session()
62 sa = get_session()
75 q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
63 q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
@@ -78,6 +66,7 b' def get_repos_path():'
78
66
79 @task(ignore_result=True)
67 @task(ignore_result=True)
80 @locked_task
68 @locked_task
69 @dbsession
81 def whoosh_index(repo_location, full_index):
70 def whoosh_index(repo_location, full_index):
82 #log = whoosh_index.get_logger()
71 #log = whoosh_index.get_logger()
83 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
72 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
@@ -88,6 +77,7 b' def whoosh_index(repo_location, full_ind'
88
77
89
78
90 @task(ignore_result=True)
79 @task(ignore_result=True)
80 @dbsession
91 def get_commits_stats(repo_name, ts_min_y, ts_max_y):
81 def get_commits_stats(repo_name, ts_min_y, ts_max_y):
92 try:
82 try:
93 log = get_commits_stats.get_logger()
83 log = get_commits_stats.get_logger()
@@ -248,6 +238,7 b' def get_commits_stats(repo_name, ts_min_'
248 return 'Task with key %s already running' % lockkey
238 return 'Task with key %s already running' % lockkey
249
239
250 @task(ignore_result=True)
240 @task(ignore_result=True)
241 @dbsession
251 def send_password_link(user_email):
242 def send_password_link(user_email):
252 try:
243 try:
253 log = reset_user_password.get_logger()
244 log = reset_user_password.get_logger()
@@ -255,7 +246,6 b' def send_password_link(user_email):'
255 log = logging.getLogger(__name__)
246 log = logging.getLogger(__name__)
256
247
257 from rhodecode.lib import auth
248 from rhodecode.lib import auth
258 from rhodecode.model.db import User
259
249
260 try:
250 try:
261 sa = get_session()
251 sa = get_session()
@@ -288,6 +278,7 b" If you didn't request new password pleas"
288 return True
278 return True
289
279
290 @task(ignore_result=True)
280 @task(ignore_result=True)
281 @dbsession
291 def reset_user_password(user_email):
282 def reset_user_password(user_email):
292 try:
283 try:
293 log = reset_user_password.get_logger()
284 log = reset_user_password.get_logger()
@@ -295,7 +286,6 b' def reset_user_password(user_email):'
295 log = logging.getLogger(__name__)
286 log = logging.getLogger(__name__)
296
287
297 from rhodecode.lib import auth
288 from rhodecode.lib import auth
298 from rhodecode.model.db import User
299
289
300 try:
290 try:
301 try:
291 try:
@@ -329,6 +319,7 b' def reset_user_password(user_email):'
329
319
330
320
331 @task(ignore_result=True)
321 @task(ignore_result=True)
322 @dbsession
332 def send_email(recipients, subject, body):
323 def send_email(recipients, subject, body):
333 """
324 """
334 Sends an email with defined parameters from the .ini files.
325 Sends an email with defined parameters from the .ini files.
@@ -375,9 +366,9 b' def send_email(recipients, subject, body'
375
366
376
367
377 @task(ignore_result=True)
368 @task(ignore_result=True)
369 @dbsession
378 def create_repo_fork(form_data, cur_user):
370 def create_repo_fork(form_data, cur_user):
379 from rhodecode.model.repo import RepoModel
371 from rhodecode.model.repo import RepoModel
380 from vcs import get_backend
381
372
382 try:
373 try:
383 log = create_repo_fork.get_logger()
374 log = create_repo_fork.get_logger()
General Comments 0
You need to be logged in to leave comments. Login now