Running delayed job in a container and on ECS is not too hard, but there are a few gotchas to watch out for. I'll show you the basic steps to getting
delayed_job running and the more general steps that need to be taken when dockerizing any app.
- [How I Dockerized my Rails Apps](https://blog.kurttomlinson.com/posts/how-i-dockerized-my-rails-apps)
- [How to Run Cron Jobs with the Whenever Gem in Rails Apps in a Docker Container](https://blog.kurttomlinson.com/posts/how-to-run-cron-jobs-with-the-whenever-gem-in-rails-apps-in-a-docker-container)
- [How to Run Delayed Job on Docker and ECS](https://blog.kurttomlinson.com/posts/how-to-run-delayed-job-on-docker-and-ecs)
The most important thing is to make sure that each of your jobs is written in such a way that it's not dependent on the local file system being permanent. Containers can be killed and recreated at any time, so a file that was there a minute ago might not be there now.
Once you've updated your app to be compatible with Docker, all that's left is crafting the correct Docker CMD. In a Dockerfile, you'd write something like this:
# Dockerfile ... CMD bundle exec bin/delayed_job run
However, this gets a bit more tricky in ECS. ECS interprets commands as arrays, so you need to use commas instead of spaces:
# Edit container > Environment > Command bundle,exec,bin/delayed_job,run
And that's about it for running delayed job in a Docker container on ECS. Check out my other articles about Dockerizing Ruby apps in the box at the top of this article.
Let me know in the comments if this article was helpful or if I missed anything!
Photo by Clark Young