[Backgroundrb-devel] Connection to backgroundrb is lost when exiting action method

Omer Enbar omer.enbar at gmail.com
Sun Sep 24 03:32:19 EDT 2006


Hey.

I've got this in environment.rb:

# define a worker class on the run with 'run_every 1.second, method'
# in backgroundrb there's only definition, while in the server it is
being spawned
def run_every delta, meth, singleton = true
  worker_class_name = "Worker#{Digest::SHA1.hexdigest(meth.to_s)}"
  if not Object.constants.member? worker_class_name
    Object.class_eval <<-METHOD_CODE
        class #{worker_class_name} < BackgrounDRb::Rails

         repeat_every #{delta}
         first_run Time.now

          def do_work(args)
            log :debug, "\#{Time.now} running: \#{args[:name]}"
            args[:method].call
          rescue => e
            puts "\#{e}"
#            kill
          end
        end
METHOD_CODE
    puts worker_class_name
  end
  MiddleMan.new_worker(:class => worker_class_name,
                       :singleton => singleton,
                       :args => {:method => meth, :name => meth.to_s})
unless $0 =~ /backgroundrb/
end

def blah
  puts "blah!"
end

def run_workers
  run_every 1.second, Object.method(:blah)
rescue DRb::DRbConnError
  run_backgroundrb
end


Now I have an action, support /localhost/test/drb

def drb
   run_workers
   sleep 5
end

When I run the action, I'll start seeing 'blah' for 5 seconds, and
once the execution leaves method drb, I'll have a connection error
druby://localhost:42531 - #<Errno::EBADF: Bad file descriptor - connect(2)
as printed in the body of the worker.

Thanks for the quick reply.
Omer.


On 9/24/06, Ezra Zygmuntowicz <ezmobius at gmail.com> wrote:
> Hey Omer-
>
> On Sep 23, 2006, at 11:03 AM, Omer Enbar wrote:
>
> > Hey.
> >
> > I have a very annoying problem, and was wondering what is wrong.
> > Suppose I have backgroundrb running, and then I have an action in some
> > controller. In the action I define a worker. When leaving the action,
> > suddenly the connection to backgroundrb is lost:
> > DRb URI: druby://localhost:22222
> > Pid: 3976
> > Autostart...
> > done
> > druby://localhost:42531 - #<Errno::EBADF: Bad file descriptor -
> > connect(2)>
> > druby://localhost:42531 - #<Errno::EBADF: Bad file descriptor -
> > connect(2)>
> > ...
> >
> > When I'm still in the action, for instance using 'sleep 10'. As long
> > I'm inside the action, there's no problem with the worker.
> >
> > Why is that?
> > Why would the connection to the worker be lost?
> >
> >
> > Thanks,
> > Omer.
>
>         Can you paste the code in question? I am not sure what you are
> trying to do that is causing you trouble.
>
> -Ezra
>


More information about the Backgroundrb-devel mailing list