Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save xtetsuji/9739049 to your computer and use it in GitHub Desktop.

Select an option

Save xtetsuji/9739049 to your computer and use it in GitHub Desktop.
Clutch, a perl one of jobqueue system's sample.

Clutchはデータベースのセットアップは必要ありません。 いわばGearmanのような揮発的なジョブキューです。 しかもGearmanのgearmandのような中間デーモンが必要ない、ワーカーがジョブ管理もする という簡潔な構造が特徴です。

Clutch does not need any database (RDBMS). It is volatilly job queue system like Gearman. And more, Clutch does not need middle daemon like gearmand. Clutch is simple that its worker manages job too.

実行サンプル (execution sample):

$ ./clutch-worker.pl &
[5] 55882
$ ./clutch-client.pl 
missing args at ./clutch-client.pl line 9.
$ ./clutch-client.pl hello
55882:hello

See http://search.cpan.org/dist/Clutch for detail.

#!/usr/bin/env perl
use strict;
use warnings;
use Clutch::Client;
my $worker_ip = '127.0.0.1';
my $worker_port = '5963';
my $args = shift || die 'missing args';
my $client = Clutch::Client->new(
servers => [ "$worker_ip:$worker_port" ],
);
my $res = $client->request('echo', $args);
print $res, "\n";
#!/usr/bin/env perl
# worker start script by single process
use strict;
use warnings;
use My::ClutchWorker;
my $ip = '127.0.0.1';
my $port = '5963';
My::ClutchWorker->new(
{
address => "$ip:$port",
}
)->run(); # stop by TERM signal to this process
package My::ClutchWorker;
use strict;
use warnings;
use Clutch::Worker;
register_function(
'echo' => sub {
my $args = shift;
$$ .':'. $args; # return worker process response.
}
);
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment