Commit Graph

11 Commits

Author SHA1 Message Date
Alexey Bezhan
599e611278 Create an app context for each celery task run
Celery tasks require an active app context in order to use app logger,
database or app configuration values. Since there's no builtin support
we create this context by using a custom celery task class NotifyTask.

However, NotifyTask was using `current_app`, which itself is only
available within an app context so the code was pushing an initial
context in run_celery.py.

This works with the default prefork pool implementation, but raises
a "working outside of application context" error with an eventlet
pool since that initial  application context is local to a thread
and eventlet celery worker pool will create multiple green threads.

To avoid this, we bind NotifyTask to the app variable with a closure
and use that variable instead of `current_app` to create the context
for executing the task. This avoids any issues caused by shared
initial app context being lost when spawning additional worker threads.

We still need to keep the context push in run_celery.py for prefork
workers since it's required for logging events outside of tasks
(eg logging during `worker_process_shutdown` signal processing).
2018-02-13 16:44:30 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Leo Hemsted
9f56dccdee Remove flask-script, move commands to click
click (http://click.pocoo.org/) is used by flask to run its cli args.
In removing flask_script (it's unmaintained), we had to migrate all our
commands to use click. This is a change for the better in my eyes - you
don't need to define the command in several places, and it makes
managing options a bit easier.

View diff with whitespace turned off unless you're a masochist.
2017-11-23 17:04:58 +00:00
Leo Hemsted
b5dc7642aa remove aws_run_celery file
it's no longer relevant since the switch to PaaS
2017-07-31 11:12:43 +01:00
Martyn Inglis
27d48a9746 Pass application name in from start scripts
- allows logger to log as correct application
2016-03-16 13:25:09 +00:00
Martyn Inglis
58ae041b64 AWS scripts for celery 2016-02-17 11:36:14 +00:00
Martyn Inglis
e59e66fa21 Run celery needed to read in secrets 2016-02-17 11:25:57 +00:00
Martyn Inglis
e0e47b40fc Setup celery config 2016-02-17 10:22:25 +00:00
Martyn Inglis
e42da7dd54 Fixing up tests to validate the call to the celery tasks.
- mocker used to test call or otherwise of the task
- no new tests just a spring clean
2016-02-16 14:06:56 +00:00
Martyn Inglis
223cb8c2dd Made SMS messages go through celery
- twilio client pulled in from delivery app
- made method to perform task
2016-02-15 16:01:14 +00:00
Martyn Inglis
fb41acdac9 Celery tests 2016-02-09 13:31:45 +00:00