Hey all
Im setting up a system that uses the excellent backgroundrb. However i
want to use the very cool directroy watcher (
File: DirectoryWatcher.rb ) to
monitor a directory, however i keep getting an error saying the
directory doesnt exsist.
Im running this from the models folder of a rails app, so where might it
be running from? Ive tried going from RAILS_ROOT, ive even run it
independantly - in which scenario it works, however i can only presume
backgroundrb must be running from a different location?
i was wondering if it somhow might be running centered around the config
dir as thats where the backgroundrb config file is?
Any help would be greatly appreciated!
Cheers
Tim
On Sep 27, 2006, at 7:53 AM, Tim P. wrote:
might it
Cheers
Tim
Hey Tim-
I'm not sure exactly what you are asking? You are trying to run the
DriWatch from a bdrb worker class? If so just use either the absolute
path to the directory or RAILS_ROOT is available in your worker
classes so you can base the path on that. ie: RAILS_ROOT+’/foo/bar/baz’
-Ezra
Hey Ezra
Thanks for getting back to me. Yea thats exactly what im trying to do, i
just tried the following code…
in my controller
def start
begin
session[:job_key] = MiddleMan.new_worker(:class => :watch_worker,
:args => { :dir => RAILS_ROOT + “/hotfolders/in”, :delay => 2})
redirect_to(:action => ‘results’)
rescue
redirect_to(:action => ‘index’)
end
end
in my worker
def do_work(args)
@logger.error = ‘Booting hotfolder watcher…’
device_manager = Dir::DirectoryWatcher.new(args[:dir], args[:delay])
device_manager.name_regexp = /^[^.].*.xml$/
device_manager.on_add = Proc.new{ |the_file|
@logger.error “Hey, just found #{the_file.inspect}!”
}
end
It doesnt error and returns a DRB object that persists, so i can only
presume its working. However when i try to get it to log - so i can
“see” its working - i just get errors in the backgroundrb log like…
undefined method `error=’ for #Logger:0x223e0a8 - (NoMethodError)
OR
undefined method `debug=’ for #Logger:0x223e0a8 - (NoMethodError)
depending on the method call i use. In usual rails code we can write
logger.error(‘some error message’) and it gets logged to the enviroment
log. Whats the correct call i should be using to make it log correctly?