Kenny Bania
Kenny Bania

Reputation: 637

How to alert user when a resque job finishes

I have a ruby on rails app using the resque gem to process background jobs. I have users trigger background jobs that can take upwards of 10 minutes to complete (they're processing a ton of data). What is the best way to alert the user when the job has completed?

I've seen the answer here about using resque-status, is that the only solution? Or is there another way to alert the user through normal resque (which I've already implemented)?

Upvotes: 1

Views: 2199

Answers (2)

rony36
rony36

Reputation: 3339

You can use a gem called "resque-status".

Using this gem you can easily get a job's status:

status = Resque::Plugins::Status::Hash.get(job_id)

This Resque::Plugins::Status::Hash object returns:

status.pct_complete #=> 0
status.status #=> 'queued'
status.queued? #=> true
status.working? #=> false
status.time #=> Time object        
status.message #=> "Created at ..."

For more details and getting this gem visit: https://github.com/quirkey/resque-status

Upvotes: 3

Veraticus
Veraticus

Reputation: 16074

If you intend to notify a user asynchronously, you have three options:

  1. Set a flag in the database, and then change your UI the next time they log in. (Like popping in an alert view or something.)
  2. Send them an email at the conclusion of the job's run. Just use the standard ActionMailer stuff for this.
  3. If you're using a pubsub framework like Faye or Juggernaut, push the user a notification that the job is done. If they're signed in they should see it immediately.

Those are pretty much the only things I can think of. I would personally go with a combination of 1 and 2; send them an email on completion, and notify them (and provide a link in the notification) the next time they log in.

Upvotes: 4

Related Questions