Skip to content

Example of Realtime Celery Task Monitoring using Flask-SocketIO

Notifications You must be signed in to change notification settings

iwootten/celery-socketio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Celery-SocketIO Example

A super simple example to demonstrate how to monitor celery task progress in realtime by using Flask-SocketIO

Example

from celery import Celery
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
celery_thread = None

@app.route('/')
def index():
    global celery_thread
    if celery_thread is None:
        celery_thread = Thread(target=background_celery_thread)
        celery_thread.start()
    return render_template('index.html')

def background_celery_thread():
    app = Celery(broker='amqp://guest:[email protected]:49153//')
    my_monitor(app)

@socketio.on('my event')
def test_message(message):
    emit('my response', {'data': 'got it!'})

def my_monitor(app):

    with app.connection() as connection:
      recv = app.events.Receiver(connection, handlers={
              '*': do_something,
      })
      recv.capture(limit=None, timeout=None, wakeup=True)

if __name__ == '__main__':
    socketio.run(app)

Resources

About

Example of Realtime Celery Task Monitoring using Flask-SocketIO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages