mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Merge pull request #1623 from alphagov/rc_update_utils_add_logs_to_celery
Updated utils to the latest version and add celery logging
This commit is contained in:
@@ -76,7 +76,7 @@ def create_app(application):
|
|||||||
register_blueprint(application)
|
register_blueprint(application)
|
||||||
register_v2_blueprints(application)
|
register_v2_blueprints(application)
|
||||||
|
|
||||||
# avoid circular imports by importing this file later 😬
|
# avoid circular imports by importing this file later
|
||||||
from app.commands import setup_commands
|
from app.commands import setup_commands
|
||||||
setup_commands(application)
|
setup_commands(application)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from celery import Celery, Task
|
from celery import Celery, Task
|
||||||
|
|
||||||
|
|
||||||
class NotifyTask(Task):
|
class NotifyTask(Task):
|
||||||
abstract = True
|
abstract = True
|
||||||
|
start = None
|
||||||
|
|
||||||
|
def on_success(self, retval, task_id, args, kwargs):
|
||||||
|
elapsed_time = time.time() - self.start
|
||||||
|
current_app.logger.info(
|
||||||
|
"{task_name} took {time}".format(
|
||||||
|
task_name=Task.name, time="{0:.4f}".format(elapsed_time)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def on_failure(self, exc, task_id, args, kwargs, einfo):
|
def on_failure(self, exc, task_id, args, kwargs, einfo):
|
||||||
# ensure task will log exceptions to correct handlers
|
# ensure task will log exceptions to correct handlers
|
||||||
@@ -13,6 +24,7 @@ class NotifyTask(Task):
|
|||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
# ensure task has flask context to access config, logger, etc
|
# ensure task has flask context to access config, logger, etc
|
||||||
with current_app.app_context():
|
with current_app.app_context():
|
||||||
|
self.start = time.time()
|
||||||
return super().__call__(*args, **kwargs)
|
return super().__call__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,6 @@ notifications-python-client==4.7.1
|
|||||||
awscli==1.14.31
|
awscli==1.14.31
|
||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@23.5.2#egg=notifications-utils==23.5.2
|
git+https://github.com/alphagov/notifications-utils.git@23.5.3#egg=notifications-utils==23.5.3
|
||||||
|
|
||||||
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
||||||
|
|||||||
Reference in New Issue
Block a user