[Backgroundrb-devel] BackgrounDRb not working properly with files ?

Ezra Zygmuntowicz ezmobius at gmail.com
Wed Jul 19 11:28:52 EDT 2006


Hi!


On Jul 19, 2006, at 6:49 AM, Tim Anglade wrote:

> Hey there,
>
> I'm kinda new to BackgrounDRb but I'm facing a big problem which I
> can't seem to wrap my head around.
>
> Here's my worker's do_work :
>
> def do_work(args)
>     # This method is called in it's own new thread when you
>     # call new worker. args is set to :args
>
>       #We define the variables used to monitor the progress
>       #@progress is used by the controller for the progress bar,
>       #file_number is used to calculate the progress
>       @progress = 0
>       file_number = 0
>
>       #Checking if the arg is indeed a directory
>       if File.directory?(args)
>
>         path = args
>
>         #we get number_of_files to calculate the progress
>         number_of_files = Dir.entries(path).size
>
>         #Let's get into that dir and look inside
>         Dir.open(path) do |dir|
>           dir.each do |entry|
>             #We ignore ".", ".." (included in ruby dir listings)
>             #we also ignore sub-directories and hidden files
>             unless  ["..", "."].include?(entry) or
> File.directory?(entry) or entry.match('^\.')
>               puts "treating file : "+entry
>
>               #First we create a new clip with the filename
>               cl = Clip.new(:title => entry)
>
>               #We get a File object out of the path
>               fl = File.open(path+entry)
>
>               #We create a new record. path is the file_column defined
> in the model.
>               rec = cl.records.new(:path => fl)
>
>               #... and we save everything.
>               rec.save
>               cl.save
>             end
>               file_number += 1
>               @progress = file_number * 100 / number_of_files
>           end
>         end
>
>       else
>         puts "Gimme a directory !"
>       end
>   end
>
>
> Any help greatly apreciated.
>
> Tim

Hey Tim-

	The first thing I would think of is that you are not passing an  
absolute path to this worker. Can you verify? What is the exact path  
you pass in to kick this worker off?  There should not be an issue  
with using any of the code you have in a worker, it should work fine.  
This line:

> if File.directory?(args)


Makes me think that the rest of your code is just getting skipped  
because the directory may not exist? Can you show me the call you use  
in rails to kick this off? Also I would put some @logger.debug  
statements inside your worker there so you can see which parts of the  
code actually get run when you kick it off.

Thanks
-Ezra


More information about the Backgroundrb-devel mailing list