2 # ---------------------------------------------------------------------
4 # hold_targeter.pl <config_file> <lock_file>
5 # ---------------------------------------------------------------------
9 use OpenSRF::Utils::JSON;
11 use OpenSRF::Utils::SettingsClient;
12 use OpenSRF::MultiSession;
13 use OpenSRF::EX qw(:try);
15 my $config = shift || die "bootstrap config required\n";
16 my $lockfile = shift || "/tmp/hold_targeter-LOCK";
19 die "I seem to be running already. If not remove $lockfile, try again\n";
22 open(F, ">$lockfile");
30 OpenSRF::System->bootstrap_client( config_file => $config );
31 $settings = OpenSRF::Utils::SettingsClient->new;
32 $parallel = $settings->config_value( hold_targeter => 'parallel' ) || 1;
43 my $r = OpenSRF::AppSession
44 ->create( 'open-ils.storage' )
45 ->request( 'open-ils.storage.action.hold_request.copy_targeter' => '24h' );
47 while (!$r->complete) {
49 $r->recv(timeout => 3600);
50 last if (time() - $start) >= 3600;
54 warn "Failure in single-session targeter:\n$e\n";
60 my $multi_targeter = OpenSRF::MultiSession->new(
61 app => 'open-ils.storage',
64 session_hash_function => sub {
67 return $_[-1]; # last parameter is the ID of the metarecord associated with the
68 # request's target; using this as the hash function value ensures
69 # that parallel targeters won't try to simultaneously handle two
70 # hold requests that have overlapping pools of copies that could
75 my $storage = OpenSRF::AppSession->create("open-ils.storage");
77 my $r = $storage->request('open-ils.storage.action.hold_request.targetable_holds.id_list', '24h');
78 while ( my $h = $r->recv ) {
80 print $r->failed->stringify . "\n";
83 if (my $hold = $h->content) {
84 $multi_targeter->request( 'open-ils.storage.action.hold_request.copy_targeter', '', $hold->[0], $hold->[1]);
88 $storage->disconnect();
90 $multi_targeter->session_wait(1);
91 $multi_targeter->disconnect;
94 warn "Failure in multi-session targeter:\n$e\n";