# backgrounDRb: problem with saving files within the worker

**URL:** <https://www.ruby-forum.com/t/backgroundrb-problem-with-saving-files-within-the-worker/104679>\
**Category:** Rails\
**Created:** [May 21, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/backgroundrb-problem-with-saving-files-within-the-worker/104679 "2007-05-21T13:52:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [May 21, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/backgroundrb-problem-with-saving-files-within-the-worker/104679/1 "2007-05-21T13:52:42Z")

</div>

Hi,  
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  
my  
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 =\> “[http://127.0.0.1:3001/cd\_creator/product/](http://127.0.0.1:3001/cd_creator/product/)”,  
: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 = Tempfile.new(“product\_” + p.to\_s)  
tmpfile.puts lines.join(‘’)  
tmpfile.close  
@logger.debug “File saved in " + tmpfile.path + " for product” +  
p.to\_s + “.”  
@temppathes \<\< tmpfile.path  
lines = []  
end

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

```

end

end
