There is a question around celery in the forums which hasn’t been addressed for a good while. If I login to the console and run rq worker app-tasks, I’m the able to start a worker, but that doesn’t seem like the right way to do things. Everything I’ve read seems to point to adding a component defined by code, but I can’t find clear details on what the app spec should be for a worker. Anyone know?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
I believe that you should be able to use a worker App Platform component in production, rather than manually starting them from a console. The DigitalOcean App Platform supports running background workers as part of your application.
For Flask applications using
rq
as the task queue, you’d typically want these workers to run continuously to process queued tasks.Here’s how you can set up an
rq
worker in DigitalOcean’s App Platform using the app specification:App Specification:
In your App Spec (
do-app.yaml
), you’ll typically have a section for your main web service (Flask app). To add a worker, you would include another service component just for therq
worker. It would look something like this:In the above, under the
workers
section:name
: A unique name for this worker.environment_slug
: The runtime environment for your worker. If your app uses Python, it would bepython
.github
: Points to your code repository. This should be the same as your main web app because the worker is just a different process running off the same codebase.run_command
: The command to start therq
worker. Based on your description, it’srq worker app-tasks
.Note that the above is just an example, you would need to add your complete app specs configuration.
Redis Connection:
Ensure that your Flask application and the
rq
setup have the correct Redis connection details. If you’re using a managed Redis instance from DigitalOcean or any other provider, ensure that your worker and Flask app have access to it.Deploy:
Once you’ve defined your worker in your app spec, you can push the changes to your GitHub repository. If
deploy_on_push
is set totrue
, the App Platform will automatically deploy the new configuration. Yourrq
worker will start automatically and begin processing tasks.Hope that this helps!
Best,
Bobby