make grace period a command line parameter
[Evergreen.git] / Open-ILS / src / support-scripts / fine_generator.pl
1 #!/usr/bin/perl
2 # ---------------------------------------------------------------------
3 # Generic databse object dumper.
4 # ./object_dumper.pl <bootstrap_config> <type>, <type>, ...
5 # ./object_dumper.pl /openils/conf/opensrf_core.xml permission.grp_tree
6 # ---------------------------------------------------------------------
7
8 use strict; 
9 use warnings;
10 use OpenSRF::Utils::JSON;
11 use OpenSRF::System;
12
13 my $config = shift || die "bootstrap config required\n";
14 my $lockfile = shift || "/tmp/generate_fines-LOCK";
15 my $grace = int(shift()) || 1;
16
17 if (-e $lockfile) {
18         open(F,$lockfile);
19         my $pid = <F>;
20         close F;
21
22         open(F,'/bin/ps axo pid|');
23         while ( my $p = <F>) {
24                 chomp($p);
25                 if ($p =~ s/\s*(\d+)$/$1/o && $p == $pid) {
26                         die "I seem to be running already at pid $pid.  If not, try again\n";
27                 }
28         }
29         close F;
30 }
31
32 open(F, ">$lockfile");
33 print F $$;
34 close F;
35
36 OpenSRF::System->bootstrap_client( config_file => $config );
37
38 my $r = OpenSRF::AppSession
39                 ->create( 'open-ils.storage' )
40                 ->request( 'open-ils.storage.action.circulation.overdue.generate_fines' => $grace );
41
42 while (!$r->complete) { $r->recv };
43
44 unlink $lockfile;