[Backgroundrb-devel] worker cleanup

Jason LaPier jason.lapier at gmail.com
Wed Dec 12 16:29:40 EST 2007

I was using an older version of backgroundrb and today I started to
play with the most recent release. First up, I'd like to say, thanks
so much for this library and thanks for making it more stable. From
the looks of things, I think it's going to be easier to use now than
it was several months ago when I first started using it.

I'd like to make sure I'm using everything the way it was intended, so
let me give a brief overview of what I use bdrb for:
Periodically, a user will need to perform a specific function that's
initiated by a long-running task. This task is specific to each user,
so what I did before was create a new worker each time the task was
started (from within a Rails Controller) and give the worker a key
based on the user's id (something like :key =>
"task_worker_#{user.id}"). Then, in other controller methods, I could
check the status of the task by looking up that key. If the task was
complete, I would delete the worker.

The biggest problem with this workflow is that I'm relying on a
controller action to delete the worker. If, for some reason, the
worker never gets deleted, the next time the user tries to perform the
same task, my controller is going to see that the worker with that key
already exists, causing me some problems. The only "fix" I can think
of is to give each worker a unique ID, and store that in the User
model, so I can avoid looking up an old worker.

With the newest release of bdrb, I'm looking at how the workers are
slightly different, and I think I still want to create a new instance
of my worker for each user, each time this task is invoked. If I'm
going to continue to do it this way, is there a way I can have the
worker delete itself when the work is done? Is this a bad idea? Or
should I be thinking about a way to use a single worker to handle the
multiple user tasks?

Thanks again,

- Jason L.

My Rails and Linux Blog: http://offtheline.net

More information about the Backgroundrb-devel mailing list