2 # ---------------------------------------------------------------------
4 # hold_targeter.pl <config_file> <lock_file>
5 # ---------------------------------------------------------------------
9 use OpenSRF::Utils::JSON;
11 use OpenSRF::Utils::SettingsClient;
12 use OpenSRF::MultiSession;
14 my $config = shift || die "bootstrap config required\n";
15 my $lockfile = shift || "/tmp/hold_targeter-LOCK";
18 die "I seem to be running already. If not remove $lockfile, try again\n";
21 open(F, ">$lockfile");
25 OpenSRF::System->bootstrap_client( config_file => $config );
26 my $settings = OpenSRF::Utils::SettingsClient->new;
27 my $parallel = $settings->config_value( hold_targeter => 'parallel' ) || 1;
31 my $r = OpenSRF::AppSession
32 ->create( 'open-ils.storage' )
33 ->request( 'open-ils.storage.action.hold_request.copy_targeter' => '24h' );
35 while (!$r->complete) {
37 $r->recv(timeout => 3600);
38 last if (time() - $start) >= 3600;
43 my $multi_targeter = OpenSRF::MultiSession->new(
44 app => 'open-ils.storage',
47 session_hash_function => sub {
50 return $_[-1]; # last parameter is the ID of the metarecord associated with the
51 # request's target; using this as the hash function value ensures
52 # that parallel targeters won't try to simultaneously handle two
53 # hold requests that have overlapping pools of copies that could
58 my $storage = OpenSRF::AppSession->create("open-ils.storage");
59 my $holds = $storage->request('open-ils.storage.action.hold_request.targetable_holds.id_list', '24h')->gather();
60 $storage->disconnect();
62 foreach my $hold (@$holds) {
63 $multi_targeter->request( 'open-ils.storage.action.hold_request.copy_targeter', '', $hold->[0], $hold->[1]);
66 $multi_targeter->session_wait(1);
67 $multi_targeter->disconnect;