Aug. 29th, 2010

karzilla: a green fist above the word SMASH! (Default)

Bug counts: resolved 229, assigned 23, needs-review 19



Continuing on the subject of things that weren't as hard as I feared: making a gearman worker.

Here's your basic gearman worker in its entirety:
use LJ::Worker::Gearman;
gearman_decl( 'name-of-worker'  => \&worker );
gearman_work();
sub worker {
    # stuff what needs doing
}

And then you call it with something like LJ::gearman_client()->dispatch_background( 'name-of-worker', ...) (at least for my purposes, which were "go do this other time-consuming thing somewhere else and don't tell me what happens.")

The only real voodoo, AFAICT, is that you have to use Storable methods (freeze/thaw) for passing the function arguments from the web execution to the worker execution. I just did a copy and paste of code from someone else's worker script and it worked like a charm.

Later on I get to either write more gearman workers or overcome my fear of TheSchwartz, depending on whether or not gearman can do everything I need for delivering vgifts.
Page generated Feb. 16th, 2026 06:28 am
Powered by Dreamwidth Studios