May 05, 2007
Gearman::UtilとGearman::WorkerをRubyに移植
追記:元のソースを愚直に書き写しただけなのでRubyっぽくないです。
ちゃんとしたのがciされたようなので用済みです!
http://code.sixapart.com/svn/gearman/trunk/api/ruby/lib/
http://dan-erat.livejournal.com/83941.html
----
http://la.ma.la/misc/ruby/gearman/util.rb
http://la.ma.la/misc/ruby/gearman/worker.rb
RubyでGearmanのWorkerを書いて。
require 'gearman/worker'
worker = Gearman::Worker.new
worker.debug = 1
worker.job_servers("127.0.0.1")
worker.register_function("sum"){|job|
(a, b) = job.arg.split(",")
a + b
}
worker.work
Perlの側でこんな風に呼び出せる。
use strict;
use Gearman::Client;
my $gc = Gearman::Client->new;
$gc->job_servers("127.0.0.1");
my $ts = $gc->new_task_set;
for my $i(1..20){
$ts->add_task("sum" => "3,4", {
on_complete => sub{
print "$i:". ${$_[0]}. "\n"
}
});
}
$ts->wait;
3+4が34って言われます。
とりあえず動いてるんだけど、なんかタスク追加したあとにselect待ちの状態になってくれないでビジーループになっちゃう。
あとで直す。もしくは誰か直して。
Edit this entry...
wikieditish message: Ready to edit this entry.
A quick preview will be rendered here when you click "Preview" button.