celery and redis to your dependencies.
app/worker.py. This file holds the Celery object and tasks. The following debug_task is an example that demonstrates Celery is working properly.
config.py. Since Redis will serve as the task broker, set the broker configuration value to REDIS_URL.
.env.
Deploy on Sevalla
Within Sevalla, create a Redis database and connect it to your app. Make sure you add theREDIS_URL value to your environment variables.
To start the Celery worker, create a new background worker with the following start command:
celery -A app.worker worker -c 1 -l INFO
Celery is started by referencing the name of the entry point file. The concurrency is set to one here to avoid overuse of your resources. You can adjust the value to match the needs of your app.
Once you deploy your app, you’ll see Celery startup information in your logs.
To test the debug task defined above, you can go to the web terminal and manually trigger the debug task.
Inside the web terminal, start the virtual environment and run the task from the Python REPL.
delay to the debug_task call will send the task to the Celery broker instead of running it directly. Within the runtime logs, you can view the output message.