1

I successfully hooked up Celery with Django and AWS SQS locally!! Now, I want to deploy my Django project. I need to start my Celery worker like this (which I usually do in Terminal locally):

celery -A my_project worker -l info

How can I do this when it is deployed? Thanks!!

1 Answers1

1

UPDATE: Per OP, elastic beanstalk is being used so modified response

Create a new directory called .ebextensions in your codes root folder

Within that folder add a file <your file name>.config and ad the following contents

commands:
  create_post_dir:
    command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/start_celery.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      celery -A my_project worker -l info

NOTE: There could be more to this depending on what other configs, envs, or installations celery needs to start properly. But at least this should get you started.

Edward Romero
  • 2,905
  • 1
  • 5
  • 17
  • Hey! Thanks so much for this response!! I am actually using Elastic Beanstalk. I thought this could work (https://stackoverflow.com/questions/28586837/execute-command-after-deploy-aws-beanstalk), but I don't really understand how to use it. Thanks!! –  Sep 07 '20 at 19:11
  • @NGI updated response with a bit more info on ebs that should hopefully help you get started. – Edward Romero Sep 07 '20 at 19:24
  • 1
    @NGI I also just found this article as well https://stackoverflow.com/a/41161692/14167216 that provides scalability. But it goes into more detailed once you're ready to move into that front. But I would suggest play around with a simple script as the one provided and move into the more complex setup as you find it fitting. – Edward Romero Sep 07 '20 at 19:29
  • Will do! Thanks so much for your help! –  Sep 07 '20 at 19:31