If your main app process has been successfully deployed on Sevalla, adding a background task worker only requires a few additional steps. For this example, we use Celery and Redis; however, the same approach can be applied to other task queues, such as Huey and RQ. Add bothDocumentation Index
Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
Use this file to discover all available pages before exploring further.
celery and redis to your dependencies.
celery.py in your project directory. The following is the same starter code used by the Celery documentation.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings') and app = Celery('example').
In the __init__.py file in the same directory, you’ll need to import the celery app object.
settings.py file, you’ll need to add your broker URL to the CELERY_BROKER_URL setting. Since Redis is used in this example, you can use the REDIS_URL environment variable as the value.
REDIS_URL to your app when connecting the Redis service to your app.
To get the Celery worker to start, you can create a new background worker with the following start command:
celery -A example worker -c 1 -l INFO
Celery starts by referencing the name of your project. 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.
In the web terminal, start the virtual environment and run the task from the Django shell.
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.