SponsorPay/em-resque — pull request #7 by jonhyman (2012-08-30 21:32:24+00:00)
Title: Allowing to customize whether or not em-resque workers sleep 

Hey guys,

I am using em-resque to send Apple Push Notifications. I ran into an issue where sometimes my connection to Apple wasn't receiving data back from them across jobs. E.g., I'd have two jobs that each sent 500 push notifications. An error would come back for the first job during or after the second job had been picked up, and most of the time the receive_data call would get dropped.

Through a bunch of debugging, I was able to fix this by switching off EM::Synchrony.sleep and onto using an EM::Timer and EM.next_tick for polling for jobs. This appears to have fixed the problem, but it limits you to only using 1 fiber since there are no more yields. This is totally fine for push notifications (in fact, it's probably better because due to Apple's spec, you shouldn't open up multiple connections to them but instead share a single, persistent connection per server).

Anyway, I modified the code to allow you to configure whether or not you want to sleep in between polling or tick. Ticking is turned off by default so this change is fully backward-compatible. You might think about merging it in, or I'll keep my own fork, whatever you think makes sense. Also in this, I switched from EM::Protocols::Redis to EM::Hiredis since the former is 2+ years old and the latter is under active development.