Mercurial > kallithea
comparison rhodecode/lib/celerylib/tasks.py @ 1799:99c70e97ce48
fixes issue with unbound session, thanks to slafs for patch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 21 Dec 2011 02:47:39 +0200 |
parents | c0d8171ade36 |
children | 3246fcce2402 |
comparison
equal
deleted
inserted
replaced
1797:c60c54e7d211 | 1799:99c70e97ce48 |
---|---|
53 | 53 |
54 from sqlalchemy import engine_from_config | 54 from sqlalchemy import engine_from_config |
55 | 55 |
56 add_cache(config) | 56 add_cache(config) |
57 | 57 |
58 | |
59 | |
60 __all__ = ['whoosh_index', 'get_commits_stats', | 58 __all__ = ['whoosh_index', 'get_commits_stats', |
61 'reset_user_password', 'send_email'] | 59 'reset_user_password', 'send_email'] |
62 | 60 |
63 CELERY_ON = str2bool(config['app_conf'].get('use_celery')) | 61 CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
64 | 62 |
65 | 63 |
66 def get_session(): | 64 def get_session(): |
67 if CELERY_ON: | 65 if CELERY_ON: |
68 engine = engine_from_config(config, 'sqlalchemy.db1.') | 66 engine = engine_from_config(config, 'sqlalchemy.db1.') |
69 init_model(engine) | 67 init_model(engine) |
68 | |
70 sa = meta.Session() | 69 sa = meta.Session() |
71 return sa | 70 return sa |
72 | 71 |
73 | 72 |
74 def get_repos_path(): | 73 def get_repos_path(): |
101 | 100 |
102 log.info('running task with lockkey %s', lockkey) | 101 log.info('running task with lockkey %s', lockkey) |
103 try: | 102 try: |
104 lock = l = DaemonLock(file_=jn(lockkey_path, lockkey)) | 103 lock = l = DaemonLock(file_=jn(lockkey_path, lockkey)) |
105 | 104 |
106 #for js data compatibilty cleans the key for person from ' | 105 # for js data compatibilty cleans the key for person from ' |
107 akc = lambda k: person(k).replace('"', "") | 106 akc = lambda k: person(k).replace('"', "") |
108 | 107 |
109 co_day_auth_aggr = {} | 108 co_day_auth_aggr = {} |
110 commits_by_day_aggregate = {} | 109 commits_by_day_aggregate = {} |
111 repos_path = get_repos_path() | 110 repos_path = get_repos_path() |
234 log.error(traceback.format_exc()) | 233 log.error(traceback.format_exc()) |
235 sa.rollback() | 234 sa.rollback() |
236 lock.release() | 235 lock.release() |
237 return False | 236 return False |
238 | 237 |
239 #final release | 238 # final release |
240 lock.release() | 239 lock.release() |
241 | 240 |
242 #execute another task if celery is enabled | 241 # execute another task if celery is enabled |
243 if len(repo.revisions) > 1 and CELERY_ON: | 242 if len(repo.revisions) > 1 and CELERY_ON: |
244 run_task(get_commits_stats, repo_name, ts_min_y, ts_max_y) | 243 run_task(get_commits_stats, repo_name, ts_min_y, ts_max_y) |
245 return True | 244 return True |
246 except LockHeld: | 245 except LockHeld: |
247 log.info('LockHeld') | 246 log.info('LockHeld') |
340 """ | 339 """ |
341 try: | 340 try: |
342 log = send_email.get_logger() | 341 log = send_email.get_logger() |
343 except: | 342 except: |
344 log = logging.getLogger(__name__) | 343 log = logging.getLogger(__name__) |
345 | 344 |
345 sa = get_session() | |
346 email_config = config | 346 email_config = config |
347 | 347 |
348 if not recipients: | 348 if not recipients: |
349 # if recipients are not defined we send to email_config + all admins | 349 # if recipients are not defined we send to email_config + all admins |
350 admins = [u.email for u in User.query().filter(User.admin==True).all()] | 350 admins = [ |
351 u.email for u in sa.query(User).filter(User.admin==True).all() | |
352 ] | |
351 recipients = [email_config.get('email_to')] + admins | 353 recipients = [email_config.get('email_to')] + admins |
352 | 354 |
353 mail_from = email_config.get('app_email_from') | 355 mail_from = email_config.get('app_email_from') |
354 user = email_config.get('smtp_username') | 356 user = email_config.get('smtp_username') |
355 passwd = email_config.get('smtp_password') | 357 passwd = email_config.get('smtp_password') |