App Platform Flask rq worker

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?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

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:

  1. 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 the rq worker. It would look something like this:

- name: web
  environment_slug: python
    repo: your_username/your_repo
    branch: master
    deploy_on_push: true
  run_command: gunicorn app:app
  http_port: 5000

- name: rq-worker
  environment_slug: python
    repo: your_username/your_repo
    branch: master
    deploy_on_push: true
  run_command: rq worker app-tasks

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 be python.
  • 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 the rq worker. Based on your description, it’s rq worker app-tasks.

Note that the above is just an example, you would need to add your complete app specs configuration.

  1. 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.

  2. 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 to true, the App Platform will automatically deploy the new configuration. Your rq worker will start automatically and begin processing tasks.

Hope that this helps!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel