technoweenie / coffee-resque

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emitting "error" on connection failure

gtracy opened this issue · comments

I thought I could create an "on" function and look for errors (like ECONNREFUSED) when the connect call fails.

Is there some other mechanism for catching this error?

Hi Greg,

If a connection to redis can't be established there really isn't anything resque can do. I think in this situation it is probably best to not handle the error and exit. Of course this isn't appropriate for all cases and if you want to handle this more gracefully resque gives you an option for that. You can establish the redis connection yourself and pass the client reference in the options hash to the connect factory method. However, I'm not totally sure if resque will function properly, I don't remember how the control flow works when an 'error' is raised and handled in node. May want to refer to the node_redis docs on this.

redis = require('redis').createClient()
redis.on 'error', (err) ->
  # your handler logic

resque = require('coffee-resque').connect redis: redis

Hope this helps.

Thanks. This helps.

Redis behaves strangely with retries - it never seems to want to stop retrying. Even after quit() is called on the client. Still investigating.

Hmm. Maybe quit() itself is raising an error? Interesting, let us know what you find out.

ha-ha. i just turned on debug for redis and got this...

"Queueing quit for next server connection."

:)

D'oh! That makes perfect sense.

I backed off this... decided to use a command line option to control whether or not I connect.