Reputation: 38062
I have a Rails application hosted on Heroku that requires a weekly data import. The task is performed by administrators and takes about 1-2 minutes to run (compute time). On Heroku, jobs that require more than 30 seconds time out. Heroku recommends job queues - however paying $36.00 per month (price of one worker) for 8 minutes of compute time doesn't seem appropriate. A few questions:
Thanks!
Upvotes: 3
Views: 3175
Reputation: 471
You might check out HireFire.
HireFire automatically "hires" and "fires" (aka "scales") Delayed Job and Resque workers on Heroku. When there are no queue jobs, HireFire will fire (shut down) all workers. If there are queued jobs, then it'll hire (spin up) workers. The amount of workers that get hired depends on the amount of queued jobs (the ratio can be configured by you).
Upvotes: 8
Reputation: 35022
Delayed Job workers are billed by the second, so you can absolutely spin one up to handle your task, and have it turn itself off via the heroku API when finished.
Upvotes: 1
Reputation: 38062
After testing, realized that the timeout does not prevent long running tasks from completing (just results being displayed to user). Ended up adding email notification and allow timeout to occur. Looked at threading request, but support in Rails seems flakey.
Upvotes: 0
Reputation: 18177
Is it possible to only pay for delayed jobs when they are used (i.e. launch the delayed job service only when administrators are uploading the data import).
This is a question you should direct at the heroku support.
Is delayed job required? I'm not sure if the timeout is just displayed to the client or if the actual work is cancelled. The documentation does list 'take no action' as an option, but I'm not sure what the implications of this are.
If it's run weekly it's more likely a cronjob than something that is just delayed. You can use the daily cron Addon (it's free). Then create a file called lib/tasks/cron.rake
.
task :cron => :environment do
if Time.now.strftime('%w').to_i == 0 # run every sunday
puts "Importing..."
#... run import
puts "done."
end
end
This task will be run daily from heroku, so you need to check the day of week, if you want to run it on a weekly basis.
Upvotes: 2