项目作者: rodolfolottin

项目描述 :
An effortlessly pre configured Django, Celery and SQS template repository for those who want to process asynchronous background tasks.
高级语言: Python
项目地址: git://github.com/rodolfolottin/django-sqs-celery-template.git


django-sqs-celery-template

An effortlessly pre configured Django, Celery and SQS template repository for those who want to process asynchronous background tasks.

Getting started

Requirements

Before running this app we will need:

Running locally (docker-compose)

Inside the cloned repository folder:

  1. Copy the .env.example
  1. cp .env.example .env
  1. Build and run the app:
  1. docker-compose up

That’s it! After building and running the app your should have 5 container services available on your machine. Now you can start developing your application and your async background tasks!

Testing it

For the local environment you can test receiving a message on the queue according to the following steps.

  • Launch a bash terminal within the web container with:
  1. docker exec -it <docker_web_id> bash
  • Open the django shell:
  1. python src/manage.py shell_plus
  • Import the task and execute it:
  1. from payment.tasks import capture_payment
  2. capture_payment.delay(pk=10)

You should see the worker docker service logs changing and a new message on the queue named “celery” if you access the panel on: http://localhost:9325

There is also the possibility of testing it through the aws-cli. To do that you need to add a new queue to the config/elasticmq.conf file because the celery queue expects the data on a specific format.

  1. queues {
  2. default {
  3. defaultVisibilityTimeout = 10 seconds
  4. delay = 5 seconds
  5. receiveMessageWait = 0 seconds
  6. }
  7. }

And now you can test it:

  1. aws --endpoint-url http://localhost:9324 sqs send-message --queue-url http://localhost:9324/queue/default --message-body "Hello, queue"