[Backgroundrb-devel] Backgroundrb assistance

hemant gethemant at gmail.com
Tue Jan 20 16:24:43 EST 2009


You can handle the exception. Http exception would be either timeout
or generic Exception class and hence wrap your external service
invocation code in:

begin
  # do some work
rescue Timeout::Error
  # timeout error
rescue
  # something else
end

It should do the trick.



On Wed, Jan 21, 2009 at 2:16 AM, Diogo Silva <diogo.silva at w20.pt> wrote:
> Hi,
> Don't know if it's the right address but I'm seeking help with my workers.
>
> I have two problems related to workers and backgroundrb:
>
> 1) I have a worker that uses soap/wsdlDriver and it's set to autoload and
> starts called by controller. This only makes a simple SOAP communication. It
> works most of the times. But sometimes worker dies and the reason is related
> with some timeout related with httpclient gem. When it dies it's a pain to
> make it work again.
> Down it's the code of my controller:
>
>  def index
>     prepare_job
>     @id = "prepare"
>     render 'admin/importar/worker'
>   end
>
>   def import
>     execute_job
>     @id = "execute"
>     render 'admin/importar/worker'
>   end
>
>   def prepare_job
>     start_worker("PREPARE_IMPORT")
>   end
>
>   def execute_job
>     start_worker("EXECUTE_IMPORT")
>   end
>
>   def start_worker(action)
>     worker = MiddleMan.ask_status(:worker => :iif_worker)
>
>     if worker != nil && worker[:progress] < 4
>       flash[:notice] = "Já existe um processo de importação a decorrer!"
>     else
>       MiddleMan.ask_work(:worker => :iif_worker, :worker_method => :do_work,
> :data => action)
>       session[:job_key] = :import
>     end
>   end
>
>   def get_progress
>     if request.xhr?
>       worker = MiddleMan.ask_status(:worker => :iif_worker)
>       return if worker == nil
>
>       progress_percent = worker[:progress]
>       render :update do |page|
>         page.call('progressPercent', 'progressbar', progress_percent)
>         if progress_percent >= 100
>           @info = worker[:info]
>           @total = worker[:total]
>           if params[:id] == "prepare"
>             page.replace_html 'import_content', :partial =>
> 'admin/importar/todo'
>           elsif params[:id] == "execute"
>             flash[:notice] = "#{@total} marcas importas com sucesso!"
>             page.replace_html 'import_content', :partial =>
> 'admin/importar/done'
>           end
>         end
>       end
>     else
>      redirect_to :action => 'index'
>     end
>    end
>
> And below some code of worker:
>
> require 'rexml/document'
> require 'soap/wsdlDriver'
> require 'xsd/mapping'
>
> class IifWorker < BackgrounDRb::MetaWorker
>   set_worker_name :iif_worker
>   #set_no_auto_load(true)
>   #attr_reader :progress, :info, :total
>
>   #def create(args = nil)
>   #  register_status('Dass')
>   #  Thread.abort_on_exception = true
>   #end
>
>   def do_work(action)
>     @progress = 0
>     update_status
>     if action == "PREPARE_IMPORT"
>       prepare_import
>     elsif action == "EXECUTE_IMPORT"
>       execute_import
>     end
>     @progress = 100
>     update_status
>   end
>
>   def prepare_import
>     stuff, chave = auth_and_query
>     results = stuff.goldMineData.record
>
>     @total = results.size
>       @progress = 15
>       @increment = ("%4.2f" % ((100.0 - @progress) / results.size)).to_f
>     @info = findRecordsToUpdate(results)
>
>     update_status
>
>     @soap.reset_stream
>   end
>
>   def execute_import
>     stuff, chave = auth_and_query
>     results = stuff.goldMineData.record
>
>     @total = results.size
>       @progress = 15
>       @increment = ("%4.2f" % ((100.0 - @progress) / results.size)).to_f
>     @info = updateRecords(stuff.goldMineData.record)
>     #@soap.UpdateGoldmine(:Key=>chave)
>
>     update_status
>
>     @soap.reset_stream
>   end
>
>   def auth_and_query
>     factory =
> SOAP::WSDLDriverFactory.new("http://infofranchisingwsp.ife.pt:8081/infofranchisingUpdateService.asmx?WSDL")
>     @soap = factory.create_rpc_driver
>     soapResponse = @soap.GetToken(nil)
>     token = soapResponse.getTokenResult
>
>     chave = authenticate(token)
>       @progress = 5
>       update_status
>     soapResponseXML = @soap.GetXML(:Key=>chave)
>       @progress = 10
>       update_status
>
>     return soapResponseXML.getXMLResult, chave
>   end
>
>   def update_status
>     register_status({:progress => @progress, :info => @info, :total =>
> @total})
>   end
>
>   def increment_progress
>     @progress += @increment
>     @progress = ("%3.2f" % @progress).to_f
>     @progress = 100 if @progress > 100
>   end
>
>   def findRecordsToUpdate(results)
> (...)
>
> Can you help me solve this problem?
>
> Thanks in advance,
> Diogo Silva
>
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>



-- 
Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org


More information about the Backgroundrb-devel mailing list