Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status monitoring per job #7

Closed
pietern opened this issue Nov 5, 2009 · 5 comments
Closed

Status monitoring per job #7

pietern opened this issue Nov 5, 2009 · 5 comments

Comments

@pietern
Copy link

pietern commented Nov 5, 2009

To provide feedback to a user about his just-queued job, I've added a simple mechanism in my branch at http://github.com/pietern/resque/commits/job_status .

This allows you to set an ivar @monitor in the class you wish to queue. Resque then adds an ID to the payload and sets the job status to "queued". When the job is started, the status changes to "started" and then to either "done" or "failed". Inbetween, the perform method can modify the jobs status via Resque.current_job.status.

Because Resque forks a new child for every jobs, it is possible to use this accessor on the Resque module and not introduce race conditions.

Statuses expire after a configurable delay that currently defaults to 5 minutes, to prevent Redis from running out of memory.

When a new job is created that needs to be monitored, Resque returns the job ID on Resque#enqueue.

To provide easy access to setting the status, there is a mixin called Resque::Mixin::Status. This mixin automatically sets the @monitor ivar.

Upon completion, the job status only gets set to "done" when the performing method has not touched the status.

This means that a custom status like "50/50" stays intact.
class SomeJob
include Resque::Mixin::Status

  def self.perform(*args)
    resque_status "00/50"
    # ...
    resque_status "50/50"
  end
end

Resque.enqueue(SomeJob)

A jobs status can be retrieved by Resque::Job.status(job_id).

@defunkt
Copy link
Contributor

defunkt commented Nov 5, 2009

What is the use case for this? The web UI does a pretty good job letting you know what jobs are running, especially in the "working" tab.

@pietern
Copy link
Author

pietern commented Nov 5, 2009

This would be nice to have for user feedback. If a user queues a high priority task, that you obviously want to handle asynchronously, you can instantly provide the user with job-progress. I was thinking of something like:

class PagesController < ApplicationController
    def some_action
      @page = Page.find(params[:id])
      session[:job_id] = @page.async(:do_something)
    end

    def job_status
      render :json => { :status => Resque::Job.status(session[:job_id]) }
    end
end

@defunkt
Copy link
Contributor

defunkt commented Nov 5, 2009

Seems like you could easily do this in your application though, right? I'm not sure it belongs in Resque.

@skrat
Copy link

skrat commented Nov 23, 2009

I believe similar stuff belong to Resque, workers should be able to report whatever status, so anybody can update the web app to display that status

@defunkt
Copy link
Contributor

defunkt commented Nov 23, 2009

skrat: Just pass in a memcached / Redis / id and have the job update it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants