From a454ee5fa4938f60f60975e943db9433d52a3916 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Fri, 6 Apr 2012 14:39:28 -0400 Subject: [PATCH] Error Checking for Hold Targeter Because having it leave lock files around is annoying. Signed-off-by: Thomas Berezansky Signed-off-by: Ben Shum --- Open-ILS/src/support-scripts/hold_targeter.pl | 101 +++++++++++------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/Open-ILS/src/support-scripts/hold_targeter.pl b/Open-ILS/src/support-scripts/hold_targeter.pl index cd62227dba..2ca196e1ae 100755 --- a/Open-ILS/src/support-scripts/hold_targeter.pl +++ b/Open-ILS/src/support-scripts/hold_targeter.pl @@ -10,6 +10,7 @@ use OpenSRF::Utils::JSON; use OpenSRF::System; use OpenSRF::Utils::SettingsClient; use OpenSRF::MultiSession; +use OpenSRF::EX qw(:try); my $config = shift || die "bootstrap config required\n"; my $lockfile = shift || "/tmp/hold_targeter-LOCK"; @@ -22,54 +23,76 @@ open(F, ">$lockfile"); print F $$; close F; -OpenSRF::System->bootstrap_client( config_file => $config ); -my $settings = OpenSRF::Utils::SettingsClient->new; -my $parallel = $settings->config_value( hold_targeter => 'parallel' ) || 1; +my $settings; +my $parallel; -if ($parallel == 1) { +try { + OpenSRF::System->bootstrap_client( config_file => $config ); + $settings = OpenSRF::Utils::SettingsClient->new; + $parallel = $settings->config_value( hold_targeter => 'parallel' ) || 1; +} otherwise { + my $e = shift; + warn "$e\n"; + unlink $lockfile; + exit 1; +}; - my $r = OpenSRF::AppSession - ->create( 'open-ils.storage' ) - ->request( 'open-ils.storage.action.hold_request.copy_targeter' => '24h' ); +if ($parallel == 1) { - while (!$r->complete) { - my $start = time; - $r->recv(timeout => 3600); - last if (time() - $start) >= 3600; + try { + my $r = OpenSRF::AppSession + ->create( 'open-ils.storage' ) + ->request( 'open-ils.storage.action.hold_request.copy_targeter' => '24h' ); + + while (!$r->complete) { + my $start = time; + $r->recv(timeout => 3600); + last if (time() - $start) >= 3600; + }; + } otherwise { + my $e = shift; + warn "Failure in single-session targeter:\n$e\n"; }; } else { - my $multi_targeter = OpenSRF::MultiSession->new( - app => 'open-ils.storage', - cap => $parallel, - api_level => 1, - session_hash_function => sub { - my $ses = shift; - my $req = shift; - return $_[-1]; # last parameter is the ID of the metarecord associated with the - # request's target; using this as the hash function value ensures - # that parallel targeters won't try to simultaneously handle two - # hold requests that have overlapping pools of copies that could - # fill those requests - } - ); - - my $storage = OpenSRF::AppSession->create("open-ils.storage"); - - my $r = $storage->request('open-ils.storage.action.hold_request.targetable_holds.id_list', '24h'); - while ( my $h = $r->recv ) { - die $r->failed->stringify . "\n" if $r->failed; - if (my $hold = $h->content) { - $multi_targeter->request( 'open-ils.storage.action.hold_request.copy_targeter', '', $hold->[0], $hold->[1]); + try { + my $multi_targeter = OpenSRF::MultiSession->new( + app => 'open-ils.storage', + cap => $parallel, + api_level => 1, + session_hash_function => sub { + my $ses = shift; + my $req = shift; + return $_[-1]; # last parameter is the ID of the metarecord associated with the + # request's target; using this as the hash function value ensures + # that parallel targeters won't try to simultaneously handle two + # hold requests that have overlapping pools of copies that could + # fill those requests + } + ); + + my $storage = OpenSRF::AppSession->create("open-ils.storage"); + + my $r = $storage->request('open-ils.storage.action.hold_request.targetable_holds.id_list', '24h'); + while ( my $h = $r->recv ) { + if ($r->failed) { + print $r->failed->stringify . "\n"; + last; + } + if (my $hold = $h->content) { + $multi_targeter->request( 'open-ils.storage.action.hold_request.copy_targeter', '', $hold->[0], $hold->[1]); + } } + + $storage->disconnect(); + + $multi_targeter->session_wait(1); + $multi_targeter->disconnect; + } otherwise { + my $e = shift; + warn "Failure in multi-session targeter:\n$e\n"; } - - $storage->disconnect(); - - $multi_targeter->session_wait(1); - $multi_targeter->disconnect; - } unlink $lockfile; -- 2.43.2