quirkey / resque-status

resque-status is an extension to the resque queue system that provides simple trackable jobs.
MIT License
515 stars 169 forks source link

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

Closed joncooper closed 11 years ago

joncooper commented 12 years ago
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

quirkey commented 12 years ago

Guarding on at() seems like the right thing to me. Will accept a patch.