views:

95

answers:

3

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:

  1. 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).
  2. 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.

Thanks!

+1  A: 

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

source

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.

jigfox
Although the task is run weekly, it requires importing data from spread sheets. Thus, running a CRON job isn't really an option.
Kevin Sylvestre
there's no difference between a cronjob and a regularly executed delayed job. They're both executing a ruby method with some parameters.
Damien MATHIEU
@Damien: Heroku makes the difference in the Payment. And A deleyed Job could be something like triggered by user interaction.@Kevin: Why can't you import from spread sheets in a cronjob, that shouldn't be a problem.
jigfox
@Jen and @Damien My understanding is that "cron" jobs are rake tasks executed periodically. In order to set this up, I'd need to have the administrators either (a) host the spreadsheet files in a publicly accessible directory or (b) store the spreadsheet files in the database (email them or post them). Doing this appears to be a terrible solutions: it doesn't allow allow for realtime feedback, it requires emails to be sent for confirmation, if errors occur administrators can't easily retry. Furthermore, I'm just looking for an answer to the delayed job question (not a new cron solution).
Kevin Sylvestre
' *"cron" jobs are rake tasks executed periodically* ', yes they are, but you asked for ' *requires a weekly data import* ', and how would you do it with a delayed, so that you won't need to upload the spreadsheet so it is public available or to store it in the database? If it's done by a delayed job, where does it get the spreadsheet from? And if there is an error, in the cronjob, just make the cronjob write an email if it was (un-)successfull, so you get it if there is an error. And how would you see if a delayed job has problems?
jigfox
A: 

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.

Kevin Sylvestre
A: 

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.

tfe
Exactly. Since you know when you want to run, its easy. You could make a script that starts the worker, then sends the request, then waits a while, then stops the worker. You could leave the worker running for 3 hours everytime you start it for 0.15 it would seem.
Tom Andersen