[Backgroundrb-devel] Is fork { } safe inside of a worker? How else may this be done...

Adam Roth adamjroth at gmail.com
Tue Nov 20 19:06:34 EST 2007

I have a BackgrounDRb worker running every 2 minutes. Here's the basic idea:

- events = Event.find_all_pending( 2.minutes )
- while( all events have yet to be processed )
---- if( Time.now <= event.time_to_process )
------- fork { process_event }
--- end
--- sleep( 0.25 )
- end
- puts "Done..."

Events that need to be processed within the next 2 minutes are loaded and
iterated over. If its time to process the event, fork and do so. Sleep for
0.25 seconds between loops until all events have been processed.

I have a few questions:

- Is this safe? Specifically calling fork within a BackgroundRb worker...
Some events may fire at the same exact time and cannot be delayed. This is a
very time sensitive application.
- Is there a better way to handle this scenario?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20071120/5199f61d/attachment.html 

More information about the Backgroundrb-devel mailing list