[Backgroundrb-devel] accessing session data in worker
Bill Walton
bill.walton at charter.net
Tue Oct 17 12:26:39 EDT 2006
Hi Michael,
Michael D'Auria wrote:
> I was accessing the Session model directly
> from within a worker and it was working:
I don't seem to be able to access my models at all. I've got two AR models
in this little sandbox app: Session and Emrec. I thought I'd start with the
Emrec model (haven't tried to access the Session model yet). In the
controller, before starting up the worker, I create an Emrec. In the
worker, I want to delete it. I was trying to pass in the id of the record I
want but couldn't get that to work. I figured it was a problem with how I
was trying to access the record id, so I tried to hardcode the delete. My
worker looks like...
----------- worker ---------
class FooWorker < BackgrounDRb::Rails
attr_reader :time_remaining
def do_work(args)
@time_remaining = 7
calculate_the_meaning_of_life(args)
end
def calculate_the_meaning_of_life(args)
while @time_remaining > 0
# calculations here
@time_remaining -= 1
sleep(1)
end
Emrec.delete(1)
end
end
--------- end of worker ---------
The emrec is not getting deleted. Any idea what I'm doing wrong here?
Also, assuming I get the hardcoded version working, what's the syntax for
accessing the values passed in the args hash?
Thanks,
Bill
More information about the Backgroundrb-devel
mailing list