We have a need to send multiple emails to coursemates instantaneously whenever someone posts a takeaway in their course.
This is usually a time taking task since we have to iterate over the coursemates and keep sending individual email to each one of them who has the instantaneous email activated.
We have achieved it using the below approach
This is usually a time taking task since we have to iterate over the coursemates and keep sending individual email to each one of them who has the instantaneous email activated.
We have achieved it using the below approach
- use celery to start a worker on a different heroku dyno
- make the worker and your web server use the same AMQP url and DB url (heroku config will give you all the details)
- use a different Procfile to start your celery worker on worker dyno
- we are using sparse checkout in git so that we dont have merge conflicts whenever we push the latest to the worker dyno.
This can be used for pretty much any heavy weight tasks which need not be handled in the current thread.
Here is how you push code to the worker.
Here is how you push code to the worker.
- git remote add worker git@heroku.com:worker-takeaway.git
- git pull worker master (to get the content from worker dyno git repo)
- add your Procfile to the sparse checkout list in your .git config to avoid getting it overwritten by the Procfile from origin.
- Procfile differs from worker dyno and app server dyno since the former is a worker and latter is web type of dyno.
- once you have added the Procfile to sparse checkout list get the latest from origin to include any changes to the tasks and push it to the worker.
No comments:
Post a Comment