[Backgroundrb-devel] MY worker won't stop working

Ezra Zygmuntowicz ezmobius at gmail.com
Tue Jul 25 11:59:18 EDT 2006


Hi~

On Jul 24, 2006, at 11:25 PM, Chris H wrote:

> Hi Ezra,
>
> love backgroundrb! Awesome plugin!

Thanks!

>
> I have a worker that processes some data files and loads this data  
> in mysql.
> It runs fine and processes all the files.
>
> However if I try to call delete_worker from my controller while it is
> processing ,
> it says it has stopped the worker but I can still see the process
> in top and also see the rows still going into mysql.
>
>
> My do_work looks like this:
>
>   def do_work(args)
>     # This method is called in it's own new thread when you
>     # call new worker. args is set to :args
>     if args
>       @process_cdr = ProcessCdr.new(args)
>     else
>       @process_cdr = ProcessCdr.new
>     end
>     @process_cdr.process
>
>   end
>
> I have start and stop actions in my controller:
>
>  def start
>
>     if @params[:cdr_file].to_s.length > 0
>
>       MiddleMan[:process_watcher] ||MiddleMan.new_worker(:class =>
> :watch_cdr_process_worker, :args => @params 
> [:cdr_file].to_s, :job_key =>
>        :process_watcher)
>
>     else
>
>       MiddleMan[:process_watcher] || MiddleMan.new_worker(:class =>
> :watch_cdr_process_worker, :job_key => :process_watcher)
>
>     end
>
>     redirect_to :action => 'status'
>
>   end
>
>   def stop
>
>     MiddleMan.delete_worker(:process_watcher) if MiddleMan 
> [:process_watcher]

Middleman[:process_watcher].terminate &&  MiddleMan.delete_worker 
(:process_watcher)


>     redirect_to :action => 'status'
>
>   end
>
> I have some ajax code monitoring the status of my worker and when I
> choose stop it responds that my worker has indeed stopped.
>
> I also tried adding a method stop_work to my worker which called
> self.terminate but this didn't seem to work either.
>
> I'm confused as to what I should be doing to get my worker to stop.
>
> Thanks in advance,
> Chris.

Chris-
	
	When you say you can see the process in top still what do you mean?  
Killing one worker will not stop the whole backgroundrb process so it  
will still show in top. The way terminate works is that you call it  
and it will signal the thread handle that it is ok to delete this  
worker. THen delete_worker will actually delete it. The next release  
will have a method you can use in your worker to kill it from within  
itself when its finished.

	See if using terminate this way works for you and let me know.

Thanks
-Ezra	






More information about the Backgroundrb-devel mailing list