TheSchwartzのexit_statusのこと
TheSchwartzを使ってみた。
なかなか便利そうなんだけど、job情報の取得の仕方がイマイチわからん。
メインのアプリ側からjobidをキーにして、exit_statusを参照したいだけなんだけど、それを簡単に出来るメソッドが見当たらない。
TheSchwartz::Jobクラスにexit_statusってメソッドがあるけど、jobテーブルから消えたら、もうインスタンス得られねーじゃんよ。
で、こんなんなった。
sub exit_status { my $jobid = shift; my $client = TheSchwartz->new(databases => $DATABASE_INFO); my ($hashdsn) = $client->shuffled_databases; my $handle_id = sprintf "%s-%s", $hashdsn, $jobid; $client->lookup_job($handle_id) and return 1; # still in the queue my $handle = $client->handle_from_string($handle_id); my $status = $handle->driver->lookup( 'TheSchwartz::ExitStatus' => $handle->jobid, ) or return; return { completion_time => $status->completion_time, status => $status->status, }; }
もっとスマートな方法はないのか、いやある筈だ。
だれか教えれ。