]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/hold_targeter.pl
adding interlocks to protect against multiple runs -- only protects one machine!
[Evergreen.git] / Open-ILS / src / support-scripts / hold_targeter.pl
1 #!/usr/bin/perl
2 # ---------------------------------------------------------------------
3 # Usage:
4 #   hold_targeter.pl <config_file> <lock_file>
5 # ---------------------------------------------------------------------
6
7 use strict; 
8 use warnings;
9 use JSON;
10 use OpenSRF::System;
11
12 my $config = shift || die "bootstrap config required\n";
13 my $lockfile = shift || "/tmp/hold_targeter-LOCK";
14
15 if (-e $lockfile) {
16         open(F,$lockfile);
17         my $pid = <F>;
18         close F;
19
20         open(F,'/bin/ps axo pid|');
21         while ( my $p = <F>) {
22                 chomp($p);
23                 if ($p =~ s/\s*(\d+)$/$1/o && $p == $pid) {
24                         die "I seem to be running already at pid $pid.  If not, try again\n";
25                 }
26         }
27         close F;
28 }
29
30 open(F, ">$lockfile");
31 print F $$;
32 close F;
33
34 OpenSRF::System->bootstrap_client( config_file => $config );
35
36 my $r = OpenSRF::AppSession
37                 ->create( 'open-ils.storage' )
38                 ->request( 'open-ils.storage.action.hold_request.copy_targeter' => '24h' );
39
40 while (!$r->complete) { $r->recv };
41
42 unlink $lockfile;
43