Forum: Ruby on Rails backgrounDRb: problem with saving files within the worker

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6d15bb497266caad1b7639bebf160d2c?d=identicon&s=25 Tom (Guest)
on 2007-05-21 13:52
in my rails app I'm using BackgrounDRb and I have problems with saving
the generated files into the temp directory within the do_work method of
worker. Despite the fact that in log the are written paths to all files,
it actually saves only the half of the files (first file, then 21st file
and then from 46 to the last one which is 98).

Here is the invocation of the worker in the controller:

MiddleMan.new_worker :class => :page_capturer_worker, :args => {
:page_address => "",
:product_ids => @products }, :job_key => 'page_capturer'

Any ideas?

Here is the code of the worker:

class PageCapturerWorker < BackgrounDRb::Rails
require 'open-uri'
require 'tempfile'

  def do_work(args)
    lines = []
    @temppathes = []

    @logger.debug "Object #{self.object_id} : #{self.class}."

    page_addr = args[:page_address]
    products = args[:product_ids]

    products.each do |p|
      file = open(page_addr.to_s + "" + p.to_s){ |f| f.each_line {|line|
lines << line}}
      tmpfile ="product_" + p.to_s)
      tmpfile.puts lines.join('')
      @logger.debug "File saved in " + tmpfile.path + " for product" +
p.to_s + "."
      @temppathes << tmpfile.path
      lines = []

    MiddleMan.cache_as('pathes', 300, @temppathes)

This topic is locked and can not be replied to.