Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Qudoを使ったJob queue system

shibayu36
March 18, 2012

Qudoを使ったJob queue system

Kyoto.pm Tech Talks #01で

shibayu36

March 18, 2012
Tweet

More Decks by shibayu36

Other Decks in Technology

Transcript

  1. QFSMͰͷ KPCRVFVFTZTUFN w 2VEP OFLPLBL͞Μ NBTBSU[͞Μ w ܰྔKPCRVFVFTZTUFN w +POL

    w ࠷௿ݶͷKPCRVFVF"1*Λ࣮૷ w $MVUDI w EJTUSJCVUFEKPCRVFVF w DMJFOU͕ॲཧ͢ΔXPSLFSΛܾఆ 2012೥3݄18೔೔༵೔
  2. $MJFOU package Sample::Qudo::Client; use parent qw(Qudo); sub new { my

    ($class, $args) = @_; $class->SUPER::new( databases => [+{ dsn => 'dbi:mysql:qudo_sample', username => 'root', password => '', }], default_hooks => ['Qudo::Hook::Serialize::JSON'], ); } 2012೥3݄18೔೔༵೔
  3. 8PSLFS package Sample::Qudo::Worker::Echo; use parent qw(Qudo::Worker); sub work { my

    ($self , $job ) = @_; my $arg = $job->arg; my $message = $arg->{message}; sleep 2; # heavy task... warn $message; $job->completed(); # or $job->abort } 2012೥3݄18೔೔༵೔
  4. 8PSLFS.BOBHFS # worker.pl my $qudo = Qudo->new( databases => [+{

    dsn => 'dbi:mysql:qudo_sample', username => 'root', password => '', }], default_hooks => ['Qudo::Hook::Serialize::JSON'], manager_abilities => [qw/Sample::Qudo::Worker::Echo/], ); $qudo->work; 2012೥3݄18೔೔༵೔
  5. 8PSLFS.BOBHFS QBSBMMFM my $manager = Qudo::Parallel::Manager->new( databases => ..., default_hooks

    => ..., manager_abilities => ..., work_delay => 5, max_workers => 3, min_spare_workers => 3, auto_load_worker => 1, ); $manager->run; 2012೥3݄18೔೔༵೔
  6. EFQMPZ EBFNPOUPPMT # run.sh #!/bin/sh exec 2>&1 cd /path/Sample-Worker ||

    exit 1 exec setuidgid app /usr/bin/perl worker.pl svc -u /etc/service/Sample-Worker #start svc -d /etc/service/Sample-Worker #stop 2012೥3݄18೔೔༵೔