Created
May 31, 2022 17:43
-
-
Save bryaneaton/cba0a9562c6813ab70fd9d1056fdb222 to your computer and use it in GitHub Desktop.
Celery Task Example, using Flask.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from flask import Flask, jsonify | |
from celery import Celery | |
app = Flask(__name__) | |
app.config["CELERY_BROKER_URL"] = "redis://redis:6379" | |
celery = Celery(app.name, broker=app.config["CELERY_BROKER_URL"]) | |
celery.conf.update(app.config) | |
@app.route('/') | |
def add_task(): | |
""" A job is created in the celery queue, and executed when resources are available.""" | |
for i in range(10000): | |
add.delay(i, i) | |
return jsonify({'status': 'ok'}) | |
@celery.task() | |
def add(x, y): | |
return x + y | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment