Giter Club home page Giter Club logo

resque-status's Introduction

resque-status

resque-status is an extension to the resque queue system that provides simple trackable jobs.

About

resque-status provides a set of simple classes that extend resque’s default functionality (with 0% monkey patching) to give apps a way to track specific job instances and their status. It achieves this by giving job instances UUID’s and allowing the job instances to report their status from within their iterations.

Installation

resque-status *requires Redis >= 1.1* (though I recommend getting the latest stable version). You can download Redis here: code.google.com/p/redis/ or install it using homebrew (brew install redis).

Install the resque-status gem (which will pull in the dependencies).

gem install resque-status

With newer Rails add this to your Gemfile:

# Gemfile
gem 'resque-status'

Then in an initializer:

# config/initializers/resque.rb
Resque.redis = "your/redis/socket" # default localhost:6379
Resque::Plugins::Status::Hash.expire_in = (24 * 60 * 60) # 24hrs in seconds

Usage

The most direct way to use resque-status is to create your jobs using the Resque::Plugins::Status module. An example job would look something like:

class SleepJob
  include Resque::Plugins::Status

  def perform
    total = (options['length'] || 1000).to_i
    total.times do |i|
      num = i+1
      at(num, total, "At #{num} of #{total}")
      sleep(1)
    end
  end
end

One major difference is that instead of implementing perform as a class method, we do our job implementation within instances of the job class.

In order to queue a SleepJob up, we also won’t use Resque.enqueue, instead we’ll use the create class method which will wrap enqueue and creating a unique id (UUID) for us to track the job with.

job_id = SleepJob.create(length: 100)

This will create a UUID enqueue the job and pass the :length option on the SleepJob instance as options (as you can see above).

Now that we have a UUID its really easy to get the status:

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

This returns a Resque::Plugins::Status::Hash object, which is a Hash (with benefits).

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

Once the worker reserves the job, the instance of SleepJob updates the status at each iteration using at()

status = Resque::Plugins::Status::Hash.get(job_id)
status.working? #=> true
status.num #=> 5
status.total #=> 100
status.pct_complete #=> 5

If an error occurs within the job instance, the status is set to ‘failed’ and then the error is re-raised so that Resque can capture it.

Its also possible to get a list of current/recent job statuses:

Resque::Plugins::Status::Hash.statuses #=> [#<Resque::Plugins::Status::Hash>, ...]

Passing back data from the job

You may want to save data from inside the job to access it from outside the job.

A common use-case is web-triggered jobs that create files, later available for download by the user.

A Status is actually just a hash, so inside a job you can do:

set_status(filename: "myfilename")

Also, all the status setting methods take any number of hash arguments. So you could do:

completed('filename' => '/myfilename')

Kill! Kill! Kill!

Because we’re tracking UUIDs per instance, and we’re checking in/updating the status on each iteration (using at or tick) we can kill specific jobs by UUID.

Resque::Plugins::Status::Hash.kill(job_id)

The next time the job at job_id calls at or tick, it will raise a Killed error and set the status to killed.

Percent Complete and setting the message

Use at or tick to show progress in your job’s perform function (which is displayed on the resque-web status tab). This will also be where Killed is raised if the job is killed.

at(steps_completed, total_steps, "${steps_completed} of #{total_steps} steps completed!")

Expiration

Since Redis is RAM based, we probably don’t want to keep these statuses around forever (at least until @antirez releases the VM feature). By setting expire_in, all statuses and their related keys will expire in expire_in seconds from the last time theyre updated:

Resque::Plugins::Status::Hash.expire_in = (60 * 60) # 1 hour

Testing

Recent versions of Resque introduced ‘Resque.inline` which changes the behavior to instead of enqueueing and performing jobs to just executing them inline. In Resque itself this removes the dependency on a Redis, however, `Resque::Status` uses Redis to store information about jobs, so though `inline` “works”, you will still need to use or mock a redis connection. You should be able to use a library like github.com/causes/mock_redis alongside `inline` if you really want to avoid Redis connections in your test.

resque-web

Though the main purpose of these trackable jobs is to allow you to surface the status of user created jobs through your apps’ own UI, I’ve added a simple example UI as a plugin to resque-web.

To use, you need to setup a resque-web config file:

# ~/resque_conf.rb
require 'resque/status_server'

Then start resque-web with your config:

resque-web ~/resque_conf.rb

This should launch resque-web in your browser and you should see a ‘Statuses’ tab.

More

Source: github.com/quirkey/resque-status API Docs: rdoc.info/projects/quirkey/resque-status Examples: github.com/quirkey/resque-status/tree/master/examples Resque: github.com/defunkt/resque

Thanks

Resque is awesome, @defunkt needs a shout-out.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Aaron Quint. See LICENSE for details.

resque-status's People

Contributors

anthonylewis avatar beljun avatar bmaddy avatar damncabbage avatar databus23 avatar dbalatero avatar drewski371-bot avatar endeepak avatar eugzol avatar fallwith avatar fotos avatar grosser avatar guilherme avatar humancopy avatar jarajapu avatar jens avatar jperville avatar karmi avatar kenpratt avatar kiela avatar kronos avatar mpatric avatar noahd1 avatar pdf avatar quirkey avatar rainkinz avatar tgsergeant avatar thbar avatar vicentemundim avatar zapnap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

resque-status's Issues

update UUID dependency to latest version

A particularly frustrating issue I ran into with using UUID 2.0.2 was that it was trying to write a UUID to the state file and it ran into a conversion issue and could not recover from this error. I don't fully understand what caused this problem in the first place, but it occurred after updating resque-status to version 0.3.1.

The problem: UUID would try to write to the statefile in the initializer. It would pack the array of the mac addresses, the sequence and the time into the binary sequence according to the STATE_FILE_FORMAT template. Then, when actually calling io.write, it would get UndefinedConversionError. After that, it would have an empty state_file that it would try to read and unpack from, which would cause the second error.

The solution: In UUID 2.0.2, the write and read modes are always set to 'w' and 'r' in the open-lock methods. In later versions, it is 'wb' and 'rb' which allows the opened File to avoid the conversion error. A quick and dirty solution is to update the gem on your own machine so that all write and read modes include the 'b', however it would be best if we just updated the resque-status to use the latest version, 2.3.5.

For googling purposes if someone else runs into this issue, this is what the exceptions look like.

Initial problem:

Encoding::UndefinedConversionError: "\xDF" from ASCII-8BIT to UTF-8
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:281:in `write'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:281:in `write_state'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:167:in `block in initialize'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:255:in `block in open_lock'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open_lock'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:166:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
    from script/rails:6:in `require'
    from script/rails:6:in `'

Then, if If the /var/tmp/ruby-uuid exists

NoMethodError: undefined method `unpack' for nil:NilClass
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:265:in `read_state'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:224:in `block in next_sequence'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:255:in `block in open_lock'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open_lock'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:223:in `next_sequence'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:160:in `initialize'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:112:in `new'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:112:in `generate'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status/hash.rb:152:in `generate_uuid'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status/hash.rb:15:in `create'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status.rb:85:in `enqueue'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status.rb:79:in `create'
    from /home/developer/code/multi/vairifi2/app/helpers/Eraser.rb:33:in `async_erase'
    from (irb):5
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
    from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
    from script/rails:6:in `require'

Untitled

Hello,
I tried upgrading resque to the latest version as well as resque-status, this is what I get when I try to require the status server lib.

undefined method `register' for Resque::Server:Module
/Users/kain/.gem/ruby/1.8/gems/resque-status-0.1.4/lib/resque/status_server.rb:49

Rails 2.3.9
resque initializer: http://pastie.org/private/u3en2gjhoikxei87epba5a

Job Ancestry

It'd be interesting to use resque-status to track job ancestry. Be able to see what job spawned another job, and track pending child jobs, etc.

status = Resque::Status.get(job_id)
status.parent => nil
status.children => [#<Resque::Status>, ...]

Any thoughts?

Expiring status keys not working?

It looks like the # of keys in redis increases without end, constantly filling with resque-status keys.

I'm using Rails 3.x, and I have in an initializer the following:

Resque::Plugins::Status::Hash.expire_in = (60 * 60)

It seems like it's working, as when I look at http://myapp.inc/resque/statuses, and browse to the last page of statuses, they are only there for the past hour.

However, when looking at the redis keys directly, there are tens of thousands of keys that look like this:

status:c29d66b0b7c4012fb5d952540035c270

I assume that is Resque status?

Do I have something misconfigured where the keys are not being removed?

Supplied options are not available until performing

ExampleJob.create('test_id' => 1)
The test_id can only be read out of the job if the job is actually performing. You can't get this option out of queued jobs.
So I monkey-patched Resque::JobWithStatus in order to get this feature.
def self.enqueue(klass, options = {})
uuid = Resque::Status.create options
Resque.enqueue(klass, uuid, options)
uuid
end
I simply passed options to Status.create. Do you need a pull request for this trivial change?

statuses tab in mapped resque of existing rails app

I'm following the config (mount Resque::Server.new, :at => "/resque") in my rails app existing but statuses tab is not showing in my web page.

How can I put the resque status plugin in the route my rails existing app.

PS.: Sorry for my wrong english

The statuses tab in resque-web doesn't show the job statuses

Using the example you provide in this git repo, I cannot get resque-web to show anything under the statuses tab, even though the sleep_job.rb command reports the status just fine.

I've tried to turn on debug and run resque-web in the foreground to see if I could find anything suspicious, but unfortunately I can't.

Possible to capture kill?

Killing the job using resque-status works by killing the resque processes, but I need a way to trap whatever signal is sent so gracefully close down some processing that the job is done. There is (was) a discussion going on about something similar here https://github.com/defunkt/resque/pull/505 but I imagine that the use of resque-status would complicate things a bit, as each job is wrapped.

Are there any thoughts on this already that I haven't come across? Thanks

Compatibility with jRuby

I'm not sure why when I require resque-status in my sinatra app I get this error:

when running COUNT=2 VERBOSE=true QUEUE=* rake resque:workers --trace for example;

JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
MongoDB logging. Please note that logging negatively impacts performance and should be disabled for high-performance production apps.
MONGODB admin['$cmd'].find({:ismaster=>1}).limit(-1)
rake aborted!
can't convert Class into String
org/jruby/RubyFile.java:872:in `basename'
org/jruby/RubyFile.java:1069:in `extname'
(eval):3:in `extname_with_potential_path_argument'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:561:in `load_imports'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:502:in `raw_load_rakefile'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:78:in `load_rakefile'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:61:in `run'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/amr/.rvm/gems/jruby-1.6.3@global/gems/rake-0.9.2/bin/rake:32:in `(root)'
org/jruby/RubyKernel.java:1063:in `load'
/Users/amr/.rvm/gems/jruby-1.6.3@global/bin/rake:19:in `(root)'

Worker not picking up status jobs

When I create a job through status, I see the "statused" queue created but the number of jobs in the "Overview" does NOT increment, and the job shows up on the "Statuses" tab in the web-ui, but workers stated with:

QUEUE=* rake rescue:work

Never pick up the jobs. The status shows them "queued" and nothing changes.

It seems like the job isn't being inserted properly for them to be visible in the queue.

Am I doing something wrong?

-ERR unknown command (RuntimeError)

redis -------------------
24 Jan 18:16:14 - Server started, Redis version 1.01

resque --------------
$ sudo gem search resque

*** LOCAL GEMS ***

resque (1.3.1)
resque-status (0.1.1)

stacktrace -----------------
$ ruby -rrubygems examples/sleep_job.rb
Creating the SleepJob
/opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:342:in read_reply': -ERR unknown command (RuntimeError) from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:249:inprocess_command'
from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:247:in map' from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:247:inprocess_command'
from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:240:in raw_call_command' from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:255:insynchronize'
from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:255:in maybe_lock' from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:240:inraw_call_command'
from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:195:in call_command' from /opt/local/lib/ruby/gems/1.8/gems/redis-0.1.1/lib/redis.rb:183:inmethod_missing'
from /opt/local/lib/ruby/gems/1.8/gems/redis-namespace-0.1.1/lib/redis/namespace.rb:99:in send' from /opt/local/lib/ruby/gems/1.8/gems/redis-namespace-0.1.1/lib/redis/namespace.rb:99:inmethod_missing'
from /opt/local/lib/ruby/gems/1.8/gems/resque-status-0.1.1/lib/resque/status.rb:19:in create' from /opt/local/lib/ruby/gems/1.8/gems/resque-status-0.1.1/lib/resque/job_with_status.rb:75:inenqueue'
from /opt/local/lib/ruby/gems/1.8/gems/resque-status-0.1.1/lib/resque/job_with_status.rb:69:in `create'
from examples/sleep_job.rb:27

Resque::Plugins::Status::Hash#pct_complete can explode - I'm happy to fix

def pct_complete
  case status
  when 'completed' then 100
  when 'queued' then 0
  else
    t = (total == 0 || total.nil?) ? 1 : total
    (((num || 0).to_f / t.to_f) * 100).to_i
  end
end

If the user accidentally sets total to a string by doing something like at(1, "This is my status"), this method will explode by trying to call NaN.to_i, which will cause the web app's Statuses tab to fail.

I'm happy to patch if you tell me how you'd like it done:

  1. Guard on at()
  2. Guard on pct_complete which raises an Exception
  3. Something else

Jon

JobWithStatus logger does not expire with status

The Redisk::Logger never gets an expiry set on its key, so these loggers persist past the Status's expiry window.

Seems that this needs two things:

  1. A call to redis.expire for the logger_key when creating the logger, and
  2. A sorted set and call to redis.zremrangebyscore in Redisk::IO when adding a new IO name to the dir, like the one in Resque::Status.create

Redis Pubsub

I'm thinking of throwing together a patch which would publish statuses to Redis and wanted to see if anyone had thoughts on it or had done anything similar.

My basic use case is that I'd like to be notified as soon as a job completes. Instead of polling for completion every few seconds, it'd be much easier to subscribe to Redis and receive a message as soon as that job completes. I can also see some usefulness in receiving messages when statuses change.

Has anyone done something similar or have any thoughts?

Integration with resque-scheduler is broken

The scheduled method is passing args to create method inside an array. This happens because args are not splatted when calling create method.

Eg: If args passed to scheduled is {:num => 100}, it is passes as [{:num => 100}] to create method.

I'll attach a pull request containing fix for this bug.

lost resque jobs

While I restart resque workers during deploy if new job comes in, then these jobs are set as queued in resque-status but it's not actually queued in resque. So my jobs are lost.

queued

ruby-1.9.2-p180 :027 > status=Resque::Status.get("f050dd20bc45012e1e77723c9193eb99")
 => #<Resque::Status {"time"=>1315485749, "status"=>"queued", "uuid"=>"f050dd20bc45012e1e77723c9193eb99"}>

ruby-1.9.2-p180 :022 > status.status
 => "queued"

ruby-1.9.2-p180 :033 > Resque.info
 => {:pending=>0, :processed=>12943, :queues=>9, :workers=>10, :working=>0, :failed=>8911, :servers=>["redis://192.168.###.###:6379/0"], :environment=>"production"} 

As you can see there are 12 jobs with queued status but they're not showing up in Queues tab as there is no job pending in resque.
Please take a look at this behaviour.

Is there any method to requeue these workers??

resque-web status page exceptions with Ruby 1.9.1

I get the following exception when trying to view the status page in resque-web. Works correctly under ruby 1.8.7 on same machine with same gem versions.

NameError - uninitialized constant Resque::Server::VIEW_PATH:
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/resque-status-0.1.4/lib/resque/status_server.rb:38:in status_view' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/resque-status-0.1.4/lib/resque/status_server.rb:23:inblock in registered'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:865:in call' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:865:inblock in route'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:521:in instance_eval' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:521:inroute_eval'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:500:in block (2 levels) in route!' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:497:incatch'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:497:in block in route!' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:476:ineach'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:476:in route!' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:601:indispatch!'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:411:in block in call!' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:566:ininstance_eval'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:566:in block in invoke' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:566:incatch'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:566:in invoke' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:411:incall!'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:399:in call' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/rack-1.1.0/lib/rack/showexceptions.rb:24:incall'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:979:in block in call' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:1005:insynchronize'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/sinatra-1.0/lib/sinatra/base.rb:979:in call' /usr/local/rvm/gems/ruby-1.9.1-p378/gems/rack-1.1.0/lib/rack/content_length.rb:13:incall'
/usr/local/rvm/gems/ruby-1.9.1-p378/gems/rack-1.1.0/lib/rack/handler/webrick.rb:48:in service' /usr/local/rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/httpserver.rb:111:inservice'
/usr/local/rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/httpserver.rb:70:in run' /usr/local/rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/server.rb:183:inblock in start_thread'

Gem versions are as follows:
redis (2.0.5)
resque (1.9.9)
resque-status (0.1.4)
sinatra (1.0)
rack (1.1.0)

Status name is different in ruby 1.8.7 and ruby 1.9 (A test fails in 1.8.7)

The spec Resque::JobWithStatus .perform should set the status fails in ruby 1.8.7. The same test passes in ruby 1.9
<"WorkingJob({"num"=>100})"> expected but was
<"WorkingJob(num100)">

This is because of to_s implementation of hash differs in 1.8.7 and 1.9. Fix for this problem would be to use options.inspect instead of options.to_s

No info about queued job

When a job fails or complete, we get information about it but when it is queued we don't have any information. Is there a way to get any details for queued job?

Kill job

Resque::status.kill(job_uuid) return true, but job not killed (or remove from queue).

Document on_failure(), on_killed(), on_success() Methods

Just wanted to pointed out until I get some time to fork the project and contribute changes myself.

Suggestion:
After "Also, all the status setting methods take any number of hash arguments" it should also describe the method handling for each.

Reason:
I imagined I could set the status to failed by calling status setting methods from within a job. But I noticed

completed unless status && status.completed?

Would just set the status back to completed. Then I realized it should raise() an error, and that I could create on_failure() methods to handle it and still have access to the status object.

Thank You.

Options should stay on a status after it's completed

Hey!

Right now, when a job isn't completed yet, we have access to it's options, but after it's completed the options vanish and become instead part on the 'name' string. Am I seeing this right, or is there another way to access them after completion?

Thanks!

stack level too deep

Hi,

For this error :
/home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:181:in pct_complete': stack level too deep (SystemStackError) from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:204:into_json'
from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-1.3.1/lib/resque/helpers.rb:15:in encode' from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:205:into_json'
from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-1.3.1/lib/resque/helpers.rb:15:in encode' from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:205:into_json'
from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-1.3.1/lib/resque/helpers.rb:15:in encode' from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:205:into_json'
from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-1.3.1/lib/resque/helpers.rb:15:in encode' ... 7967 levels... from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/status.rb:18:increate'
from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/job_with_status.rb:75:in enqueue' from /home/ruby/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/resque-status-0.1.2/lib/resque/job_with_status.rb:69:increate'
from sleep_job.rb:28

Use this :
$ gem install yajl-ruby

Florian

forking and redis connections

When resque forks the job, resque-status uses the same connection as the parent job which can cause intermittent errors such as

NoMethodError: undefined method each' for 1:Fixnum /gems/resque-status-0.3.3/lib/resque/plugins/status/hash.rb:41:inclear'

TypeError: can't convert Fixnum into String
/gems/resque_unit-0.4.1/lib/resque_unit/helpers.rb:24:in `decode'

NoMethodError: undefined method each' for #<String:0x0000010230cdb8> /gems/resque-status-0.3.3/lib/resque/plugins/status/hash.rb:41:inclear'

we are now using Resque.after_fork to re-initialize the redis connection

possible to update status outside the job

Hi there,

Is it possible to update the Status of the job from somewhere else not inside the job?
for example:

class SleepJob < Resque::JobWithStatus
  def perform
    # call a method somewhere else and send the uuid
    do_something(uuid)
    completed
  end
end

In another ruby File, already included

def do_something(job_id)
  status = Resque::Status.get(job_id)
  # Here update the status as it goes
  status.total = 100
  # some loop  
    status.num = 7
  # end
end

I've been trying to do this but setting status.total and status.num does not change anything on the web interface progress or status.pct_complete is not udpated.

Maybe Im not supposed to do it this way?

Thanks!

Statuses in resque-web not displayed in reverse chronological order

Saw the comment in resque-status/lib/resque/status.rb #status_ids explaining that we expect a reverse chronological ordering of statuses but the tab on resque-web doesn't behave this way.

# Return the <tt>num</tt> most recent status/job UUIDs in reverse chronological order.
def self.status_ids(range_start = nil, range_end = nil)
    ...
    (redis.zrevrange(set_key, -(range_end.abs), -(range_start.abs)) || []).reverse
  end
end

Just need to remove the call to #reverse in that line above since Redis zrevrange already does this for us. Would send a pull request but seems relatively trivial. Do you need me to do that still?

Thanks for a great plugin btw!

Received exception .... #<NameError: uninitialized constant SleepJob>

Using
Ubuntu 10.10, ruby 1.9.3 and Redis 2.4.13 with rbenv

Gems
rails (3.2.3)
resque (1.20.0)
resque-status (0.3.3)

When running the example job sleep_job.rb as explained in the documents, I am getting the following error
... 13543: Received exception when reporting failure: NameError: uninitialized constant SleepJob

The worker is started with
RAILS_ENV=production QUEUE=* be rake resque:work VVERBOSE=1

create / enqueue method interface

Why was choose a hash instead of use the same interface of the default enqueue method? I guess the interface would be much better if it's

def self.create(*options)
    self.enqueue(self, *options)
end

def self.enqueue(klass, *options)
  uuid = Resque::Status.create
  Resque.enqueue(klass, uuid, *options)
  uuid
end

Show args/options in Name field of web interface

Yes, the name method can be overridden, but it would be nice if by default it did
def name
"#{self.class.name}(#{options unless options.empty?})"
end
or something similar, so that the args would show in the web interface (especially when paired with resque-scheduler)

uninitialized constant Resque::Server (NameError)

when i use require 'resque/status_server' in my rails app config/initializers/resque.rb, it failed, error msg

/usr/local/rvm/gems/ruby-1.9.3-p0/gems/resque-status-0.2.4/lib/resque/status_server.rb:73:in `<top (required)>': uninitialized constant Resque::Server (NameError)

i use

require 'resque/server'
require 'resque/status_server'

,it succeed

i think gem lib/resque/status_server.rb should add the following code when Resque::Server.register Resque::StatusServer

require 'resque/server'

For failed jobs, do not have the progress bar jump to 100%

Our team uses resque-status extensively and we're quite happy with it. One feature request I have is to freeze the progress bar in place when a job fails instead of having it jump to 100%.

For example, if I have put 10 at() clauses in my worker class and the job fails after the 50% marker but before the 60% marker, it would be really helpful for me to know that it was in-between this 50-60% range that the worker failed.

Looking at the Resque web interface, I can already tell from the status column that the worker job has a "failed" status, so I know visually that it has died and is not still running. For me, having the progress bar freeze at the point it was at when the job failed would be more useful than having it jump to 100% just because the worker class has stopped running.

Status hash assignment has no effect

My job executes as expected, and I am able to retrieve the status hash from outside of the job. However, within the job, using status["myvariable"] = "myvalue", as in the readme, has no effect on the status hash.

A gist of the code / my initializer / output (this is in a rails project):

https://gist.github.com/2304749

Resque-status is compatible with rubyonrails 3 ?

Resque-status is compatible with rubyonrails 3 ?

I have this error :

uninitialized constant Resque::JobWithStatus

In my Gemfile :

gem 'resque', :require => "resque/server"
gem 'resque-status'

Statuses not showing up in the reque-web statuses tab

I can see the status in resque-web -> stats -> status:1 getting updated which tells me that the status in redis is being created and updated. It's just not showing in "Statuses" tab.
environment:
osx 10.6.6
redis 2.2.1
resque 1.14.0
resque-status 0.2.2
rails 3.0.5
ruby 1.9.2-p136

Thanks!

Resque inline?

Hi, does resque-status work with resque inline? We seem to be seeing an issue wherein jobs that are supposed to be running inline instead try to connect to Redis. Thanks!

Mocking resque-status for RSpec

For now I'm going to fork resque_spec to see if I can hack something together, but it would be useful if resque-status came with some testing facilities.

Maybe something like this?

VideoJob.should have_queued_with_status(:queue_name)

typo in README.md

The README says this should work..

complete('filename' => '/myfilename')

However, after looking into the code, what worked for me is this :

completed('filename' => '/myfilename')

Also, using status as a hash and appending to it did not work for me. You might want to try promoting completed() as a means to append to the status hash instead of having users trying to manipulate it directly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.