Search code examples
ruby-on-railsresque

Throwing an exception if resque is not enabled


I currently have a rails app that sends tasks to a resque queue. In the rails app, a progress bar gives a "percent done" reading via ajax polling. This all works perfectly well...unless resque is down, in which case the progress bar just sits at zero forever, with no notification to the user that the task isn't going to run (at least, not until someone starts up a resque worker).

My question is: Is there any way to bubble an exception back to the rails app if resque isn't actually up?


Solution

  • AFAIK I dont thing such functionality exist in resque not atleast in v1-x-stable I believe,

    but Resque has few handy method which can help eventually

    1. Resque::Worker.all => Return List of all workers present

    2. Resque::Worker.working => Return List of currently running workers

    Case 1 :

    Now if your queue is * (GLOBAL QUEUE) then I believe

    checking the above

    Resque::Worker.all.empty? or Resque::Worker.length == 0 or Resque::Worker.present?

    would do the trick for you

    Case 2

    Now if you dont have * (GLOBAL QUEUE) Perhaps then you need to hooks some of your codes to achieve that (lets assume your queue name is progress_bar)

    Resque::Worker.all.map { |worker| worker worker.to_s.split(':') =~ /(\*|progress_bar)/ }.present?

    NOTE:

    I'm checking for * GLOBAL QUEUE as well as progress_bar QUEUE and also I'm not sure whether the regex is broken or not you can check that on your end I believe

    Last TIP:

    At any given time Redis is the awesome source of information if you want metadata about Resque worker or job Just .

    Hope this help