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

Joe Van Dyk joevandyk at gmail.com
Tue Nov 20 19:29:46 EST 2007


Possibly a related question, If I'm making activerecord updates inside
multiple brdb workers at the same time, that should be fine, right?
Wasn't sure how concurrency worked.

On Nov 20, 2007 4:06 PM, Adam Roth <adamjroth at gmail.com> wrote:
> 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?
>
> Thanks
> Adam
>
>
>
>
>
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>


More information about the Backgroundrb-devel mailing list