[Backgroundrb-devel] Singleton-like Worker

Ezra Zygmuntowicz ezmobius at gmail.com
Wed Aug 23 14:42:17 EDT 2006

On Aug 23, 2006, at 11:33 AM, Michael Siebert wrote:

> Hello there,
> I need a Worker Class to be Singleton-like, that means there must  
> be at maximum one Instance at a time. When a new Request is made to  
> create another worker of this type, it should return and wait for  
> the other instance to be destroyed.
> what i need to do: i have a worker who needs to do sth with java  
> and openoffice, and it seems when i have more tha one worker  
> simultaneously, everything goes terribly wrong...
> is there already sth in bgdrb or how would i do that?
> -- 
> Michael Siebert <info at siebert-wd.de>

Hey Michael-

	Yeah there is already singleton type workers in the plugin.  It  
doesn't work exactly as you want it to though. When you create a  
singleton worker it will start doing its thing and any call to  
new_worker for the same singleton will just return the key for the  
already existing singleton worker. So you are always garaunteed to  
get the same singleton. There is not currently any support for  
returning and then starting up after the singleton dies. But check it  
out anyway as it might do what you want.

There is also now an option to have a singleton worker so there is  
only one of a certain worker. Even if you call new_worker twice with  
option enabled you will get back the same instance of the class. Do not
create a worker class and use it as a singleton and a non singleton  
at the same time. This is not supported.

MiddleMan.new_worker(:class => :foo_worker,
                      :args => "Bar",
                      :job_key => :singleton_worker,
                      :singleton => true)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060823/c18dc769/attachment-0001.html 

More information about the Backgroundrb-devel mailing list