Commit 01fe46ca authored by Stephan Feurer's avatar Stephan Feurer
Browse files

Merge branch 'dev' of git.vshn.net:elia.ponzio/generic-monitoring into dev

parents de12eff2 2e5d0ee9
......@@ -37,3 +37,9 @@ deactivate
export FLASK_APP=api
flask run
```
### Run Redis Queue with docker
```
docker run -d -p 6379:6379 redis
```
from flask import Flask
from flask_restful import Resource, Api
from tasks import *
app = Flask(__name__)
api = Api(app)
app.config.update(
CELERY_BROKER_URL='redis://localhost:6379',
CELERY_RESULT_BACKEND='redis://localhost:6379'
)
celery = make_celery(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')
@celery.task()
def add_together(a, b):
return a + b
if __name__ == '__main__':
app.run(debug=True)
from celery import Celery
def make_celery(app):
celery = Celery(
app.import_name,
backend=app.config['CELERY_RESULT_BACKEND'],
broker=app.config['CELERY_BROKER_URL']
)
celery.conf.update(app.config)
class ContextTask(celery.Task):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment