Created
October 16, 2010 18:27
-
-
Save masartz/630120 to your computer and use it in GitHub Desktop.
YAPC::Asia2010 Qudo::Hook::ForceQuitJob demo script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Qudo; | |
my $qudo = Qudo->new( | |
driver_class => 'Skinny', | |
databases => [+{ | |
dsn => 'dbi:mysql:qudo', | |
username => 'root', | |
password => '', | |
}], | |
); | |
$qudo->enqueue("MyApp::Worker::Normal", { arg => 'normal arg' }); | |
$qudo->enqueue("MyApp::Worker::Delay", { arg => 'delay arg' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Qudo; | |
use MyApp::Worker::Normal; | |
use MyApp::Worker::Delay; | |
my $qudo = Qudo->new( | |
driver_class => 'Skinny', | |
databases => [+{ | |
dsn => 'dbi:mysql:qudo', | |
username => 'root', | |
password => '', | |
}], | |
manager_abilities => [qw/ | |
MyApp::Worker::Normal | |
MyApp::Worker::Delay | |
/], | |
); | |
$qudo->manager->register_hooks(qw/Qudo::Hook::ForceQuitJob/); | |
#$qudo->manager->work_once; | |
$qudo->work; | |
package MyApp::Worker::Normal; | |
use strict; | |
use warnings; | |
use base qw/Qudo::Worker/; | |
sub grab_for{ 2 } | |
sub work { | |
my ($self , $job ) = @_; | |
sleep(1); | |
$job->completed(); | |
} | |
1; | |
package MyApp::Worker::Delay; | |
use strict; | |
use warnings; | |
use base qw/Qudo::Worker/; | |
sub grab_for{ 2 } | |
sub work { | |
my ($self , $job ) = @_; | |
sleep(3); | |
$job->completed(); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment