I have need to periodically run a background task in my rails app. I’ve done some research and it seems that there is not a standard way to do this.
I don’t want to generate a new app context so a runner seems to be out of the question. I’d prefer not to run my own thread handler if I don’t have to. (It looks like this may be the most promising option at this point other than the below).
Using the whenever gem I am doing the following in schedule.rb:
every 15.minutes do
command "curl http://127.0.0.1:3000/periodic"
end
This feels a little like a hack, but I can’t find anything that is more straightforward than this — Everything else I can find seems like a lot of effort for something seemingly basic.
I should note that this is an internal project and will be behind a firewall, and headless automated middleware, so there is low expectation that a user will ever be accessing this project directly.
Am I missing something or is background processing or timed events really just not supported out of the box with rails?
After some research, Amadan’s suggestion of a railtie may get me what I want here. As an ideal solution it isn’t perfect, though depending on the context (i.e. a publicly accessible rails project) this is the way to go. For the project I am working on it’s a little heavy handed, as I’m doing a rails app that is a bridge between two systems, running headless, with no user input behind a firewall.