technoweenie / coffee-resque

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

access queue when: worker.on "poll"

optikfluffel opened this issue · comments

commented

Hey :)
How can I access the queue when worker.on "poll", (worker, queue) -> ?
I want to see if there are any jobs left and terminate the worker if there's nothing left to do

@optikfluffel Instead of peeking into the queue you could simply end the worker when resque determines that there is no work left via the pause method. Something like this might work for you. Disclaimer: I haven't tested this. Let me know if this isn't what you are asking for.

resque = require 'coffee-resque'

class NonPollingWorker extends resque.Worker
  pause: -> @end()

Your setup will be a little different if you go this route as you will to construct the custom Worker yourself.

resque = require 'coffee-resque'

connection = resque.connect
  host : redisHost
  port : redisPort

worker = new NonPollingWorker connection, '*', jobs
commented

Yeah! That was exactly what I needed. Big Thanks :)

And btw I used this in my little Coffee-Resque-Demo ^^