From 654508d518dd83f6258b4264db2d9eb27c61493c Mon Sep 17 00:00:00 2001 From: Amos Elliston Date: Sat, 25 Jan 2020 10:11:48 -0800 Subject: [PATCH 1/7] upgrades kombu to fix 'unknown worker' issue --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 37fb85c0..591f751c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ redis==3.2.1 # NOTE: Kombu 4.6.5 results in a build failure. Bumping down to 4.6.4 # See this github issue: https://github.com/celery/kombu/issues/1063 -kombu==4.6.4 +kombu==4.6.7 From 14aaad98b167cc2989019870029ba0f072b71d80 Mon Sep 17 00:00:00 2001 From: Amos Elliston Date: Sat, 25 Jan 2020 10:20:32 -0800 Subject: [PATCH 2/7] tries to downgrade kombu to fix the problem --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 591f751c..76587a43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ redis==3.2.1 # NOTE: Kombu 4.6.5 results in a build failure. Bumping down to 4.6.4 # See this github issue: https://github.com/celery/kombu/issues/1063 -kombu==4.6.7 +kombu==4.6.3 From 2ce96ba70772e5fdf541f6ecae098dd90bec8e5a Mon Sep 17 00:00:00 2001 From: Amos Elliston <7338+famoseagle@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:05:55 -0700 Subject: [PATCH 3/7] updates flower --- .gitignore | 24 ++++++++++++++++++++++++ requirements.txt | 13 +++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..edc34614 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# Distribution / packaging +.Python +.venv +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib64/ +parts/ +sdist/ +var/ +.vscode/ +*.egg-info/ +.installed.cfg +*.egg + +# vim +*.swp diff --git a/requirements.txt b/requirements.txt index 76587a43..8de5a5e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,6 @@ celery==4.3.0 -Flask==1.0.2 -flower==0.9.3 -gunicorn==19.9.0 -redis==3.2.1 - -# NOTE: Kombu 4.6.5 results in a build failure. Bumping down to 4.6.4 -# See this github issue: https://github.com/celery/kombu/issues/1063 -kombu==4.6.3 +Flask==1.1.2 +flower==0.9.5 +gunicorn==20.0.4 +redis==3.5.3 +kombu==4.6.7 From f5debde7e8838420c36e7a6142ad2ec59c237b2a Mon Sep 17 00:00:00 2001 From: Amos Elliston <7338+famoseagle@users.noreply.github.com> Date: Mon, 9 Nov 2020 13:52:34 -0800 Subject: [PATCH 4/7] upgrades celery and kombu --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8de5a5e3..8ddf20b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -celery==4.3.0 +celery==4.4.7 Flask==1.1.2 flower==0.9.5 gunicorn==20.0.4 redis==3.5.3 -kombu==4.6.7 +kombu==4.6.11 From d6c81a9aa426efe3487be931d64dcf5420da0e50 Mon Sep 17 00:00:00 2001 From: Ryan Orban Date: Tue, 10 Aug 2021 16:09:12 -0700 Subject: [PATCH 5/7] update celery, flower, gunicorn, kombu Signed-off-by: Ryan Orban --- requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8ddf20b8..adcac6be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -celery==4.4.7 +celery==5.0.5 Flask==1.1.2 -flower==0.9.5 -gunicorn==20.0.4 +flower==1.0.0 +gunicorn==20.1.0 redis==3.5.3 -kombu==4.6.11 +kombu==5.1.0 From 5b2a2912ce2c8f0ffb47724268688d6ef167c63b Mon Sep 17 00:00:00 2001 From: Amos Elliston <7338+famoseagle@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:22:53 -0800 Subject: [PATCH 6/7] upgrade flower --- README.md | 64 ++++++- app.py | 15 +- requirements.txt | 12 +- tasks.py | 23 ++- templates/main.html | 411 +++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 488 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index d8d48477..23af42d1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,66 @@ -# Celery on Render +# Celery Task Queue with Flower -This repo can be used to deploy the [Celery](https://github.com/celery/celery) distributed task queue on [Render](https://render.com). It also includes deployment instructions for [Flower](https://github.com/mher/flower), a web monitoring frontend for Celery. +A modern Flask + Celery distributed task queue with Flower monitoring dashboard. +## Tech Stack + +- **Flask 3.0** - Web framework +- **Celery 5.3** - Distributed task queue +- **Flower 2.0** - Real-time Celery monitoring +- **Redis** - Message broker & result backend + +## Local Development + +### Prerequisites + +- Python 3.10+ +- Redis server running locally + +### Setup + +```bash +# Create virtual environment +python -m venv venv +source venv/bin/activate # On Windows: venv\Scripts\activate + +# Install dependencies +pip install -r requirements.txt + +# Set environment variables (optional) +export CELERY_BROKER_URL=redis://localhost:6379/0 +export CELERY_RESULT_BACKEND=redis://localhost:6379/0 +export FLASK_SECRET_KEY=your-secret-key +``` + +### Running + +Start each service in a separate terminal: + +```bash +# Terminal 1: Start Redis (if not running as a service) +redis-server + +# Terminal 2: Start Celery worker +celery -A tasks worker --loglevel=info + +# Terminal 3: Start Flower monitoring +celery -A tasks flower --port=5555 + +# Terminal 4: Start Flask app +flask run +``` + +Then visit: +- **Web App**: http://localhost:5000 +- **Flower Dashboard**: http://localhost:5555 ## Deployment -Follow the guide at https://render.com/docs/deploy-celery. \ No newline at end of file +Follow the guide at https://render.com/docs/deploy-celery for production deployment on Render. + +## Features + +- Asynchronous task execution +- Real-time task monitoring via Flower +- Task result tracking with Redis backend +- Modern, responsive UI diff --git a/app.py b/app.py index 3ae0a7b9..1bb6d8e4 100644 --- a/app.py +++ b/app.py @@ -13,8 +13,15 @@ def main(): @app.route('/add', methods=['POST']) def add_inputs(): - x = int(request.form['x']) - y = int(request.form['y']) - add.delay(x, y) - flash("Your addition job has been submitted.") + try: + x = int(request.form['x']) + y = int(request.form['y']) + result = add.delay(x, y) + flash(f"Job submitted! Task ID: {result.id[:8]}...") + except (ValueError, KeyError): + flash("Please enter valid numbers for both X and Y.") return redirect('/') + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/requirements.txt b/requirements.txt index adcac6be..e4e658d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -celery==5.0.5 -Flask==1.1.2 -flower==1.0.0 -gunicorn==20.1.0 -redis==3.5.3 -kombu==5.1.0 +celery==5.3.6 +Flask==3.0.0 +flower==2.0.1 +gunicorn==21.2.0 +redis==5.0.1 +kombu==5.3.4 diff --git a/tasks.py b/tasks.py index 101a88ac..e7f9a77b 100644 --- a/tasks.py +++ b/tasks.py @@ -1,9 +1,26 @@ import os from celery import Celery -app = Celery('tasks', broker=os.getenv("CELERY_BROKER_URL")) +# Configure Celery with broker and optional result backend +app = Celery( + 'tasks', + broker=os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0"), + backend=os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0") +) +# Celery configuration +app.conf.update( + task_serializer='json', + accept_content=['json'], + result_serializer='json', + timezone='UTC', + enable_utc=True, + task_track_started=True, + result_expires=3600, +) -@app.task -def add(x, y): + +@app.task(bind=True) +def add(self, x, y): + """Add two numbers asynchronously.""" return x + y diff --git a/templates/main.html b/templates/main.html index c0584a3c..689a9ae8 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,28 +1,389 @@ - + + - + + + Celery Task Queue + + + + -
-
-
-

Asynchronous addition using Celery!

-
-
- - +
+
+
+ +
+
+
+ -
- - +

Async Task Queue

+

Distributed computing with Celery

+
+ + +
+
+
+ + +
+
+
+
+ + +
+
- + -
-
-
-
+ {% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} @@ -30,8 +391,16 @@

Asynchronous addition using Celery!

{% endfor %} {% endif %} {% endwith %} + +
-
- \ No newline at end of file + From bae9ad846806a2314c2a3217a4b860aa3da2a512 Mon Sep 17 00:00:00 2001 From: Amos Elliston <7338+famoseagle@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:29:56 -0800 Subject: [PATCH 7/7] revert main.html --- app.py | 20 ++- tasks.py | 13 +- templates/main.html | 409 +++----------------------------------------- 3 files changed, 38 insertions(+), 404 deletions(-) diff --git a/app.py b/app.py index 1bb6d8e4..25468bd4 100644 --- a/app.py +++ b/app.py @@ -1,27 +1,29 @@ import os -from flask import Flask, flash, render_template, redirect, request + +from flask import Flask, flash, redirect, render_template, request + from tasks import add app = Flask(__name__) -app.secret_key = os.getenv('FLASK_SECRET_KEY', "super-secret") +app.secret_key = os.getenv("FLASK_SECRET_KEY", "super-secret") -@app.route('/') +@app.route("/") def main(): - return render_template('main.html') + return render_template("main.html") -@app.route('/add', methods=['POST']) +@app.route("/add", methods=["POST"]) def add_inputs(): try: - x = int(request.form['x']) - y = int(request.form['y']) + x = int(request.form["x"]) + y = int(request.form["y"]) result = add.delay(x, y) flash(f"Job submitted! Task ID: {result.id[:8]}...") except (ValueError, KeyError): flash("Please enter valid numbers for both X and Y.") - return redirect('/') + return redirect("/") -if __name__ == '__main__': +if __name__ == "__main__": app.run(debug=True) diff --git a/tasks.py b/tasks.py index e7f9a77b..9bcf73f7 100644 --- a/tasks.py +++ b/tasks.py @@ -1,19 +1,20 @@ import os + from celery import Celery # Configure Celery with broker and optional result backend app = Celery( - 'tasks', + "tasks", broker=os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0"), - backend=os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0") + backend=os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0"), ) # Celery configuration app.conf.update( - task_serializer='json', - accept_content=['json'], - result_serializer='json', - timezone='UTC', + task_serializer="json", + accept_content=["json"], + result_serializer="json", + timezone="UTC", enable_utc=True, task_track_started=True, result_expires=3600, diff --git a/templates/main.html b/templates/main.html index 689a9ae8..bd181042 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,389 +1,28 @@ - - + - - - Celery Task Queue - - - - + -
-
-
- -
-
-
- -

Async Task Queue

-

Distributed computing with Celery

-
- -
+
+
+
+

Asynchronous addition using Celery!

+
-
-
- - -
-
+
-
- - -
-
+ + +
+
+ +
- + - +
+
+
+
{% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} @@ -391,16 +30,8 @@

Async Task Queue

{% endfor %} {% endif %} {% endwith %} - -
+