So I have a functionality in a Django Elastic Beanstalk app that works like so:
Only one instance will run the command because the cron job does not actually run in a cron daemon per-se.
There are few concepts that might help you quickly grok amazon's Elastic Beanstalk mindset.
A message in the queue is picked up only once by one of the instances in the worker environment at a time.
Now the cron.yaml
file actually just tells the leader to create a message in the queue with special attributes, at the times specified in the schedule. When it then finds this message, it's dispatched to one instance only as a POST request to the specified URL.
When I use Django in a worker environment I create a cron
app with views that map to the action I want. For example if I wanted to periodically poll a Facebook endpoint I might have a path /cron/facebook/poll/
which calls a poll_facebook()
function in views.py
That way if I have a cron.yaml as follows, it'll poll Facebook once every hour:
version: 1
cron:
- name: "pollfacebook"
url: "/cron/facebook/poll/"
schedule: "0 * * * *"