Fine generator server-side parallel
authorBill Erickson <berickxx@gmail.com>
Wed, 19 Jul 2017 15:02:16 +0000 (11:02 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 19 Jul 2017 15:02:27 +0000 (11:02 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/support-scripts/fine_generator.pl

index c6118f2..a3d52d4 100644 (file)
@@ -153,11 +153,17 @@ __PACKAGE__->register_method(
 # of transaction the ID refers to without having to query the DB.
 # skip_no_fines - filter out transactions which will never be billed, 
 # e.g. circs with a $0 max fine or $0 recurring fine.
+#
+# parallel_count -- number of parallel processes handling these circs
+# parallel_slot  -- which batch of parallel circs to process.  
+#     value is 1..$parallel_count
 sub overdue_circs {
     my $upper_interval = shift || '1 millennium';
     my $idlist = shift;
     my $partition = shift;
     my $skip_no_fines = shift;
+    my $parallel_count = shift || 1;
+    my $parallel_slot = shift || 1;
 
     # Only retrieve ID's in the initial query if that's all the caller needs.
     my $contents = $idlist ? 'id' : '*';
@@ -165,6 +171,12 @@ sub overdue_circs {
     my $fines_filter = $skip_no_fines ? 
         'AND recurring_fine <> 0 AND max_fine <> 0' : '';
 
+    my $id_filter = '';
+    if ($parallel_count > 1) {
+        $parallel_slot--; # translate to zero-based slot numbers
+        $id_filter = "AND MOD(id, $parallel_count) = $parallel_slot";
+    }
+
     my $c_t = action::circulation->table;
 
     my $sql = <<"    SQL";
@@ -172,6 +184,7 @@ sub overdue_circs {
           FROM  $c_t
           WHERE stop_fines IS NULL
             $fines_filter
+            $id_filter
             AND due_date < ( CURRENT_TIMESTAMP - grace_period )
             AND fine_interval < ?::INTERVAL
     SQL
@@ -202,6 +215,9 @@ sub overdue_circs {
 
     push @circs, map { $idlist ? $_->{id} : booking::reservation->construct($_) } $sth->fetchall_hash;
 
+    $logger->info("parallel=$parallel_count slot=$parallel_slot ".
+        "processing ".scalar(@circs)." transactions");
+
     return @circs;
 }
 
@@ -998,6 +1014,8 @@ sub generate_fines {
     my $self = shift;
     my $client = shift;
     my $circ_id = shift;
+    my $parallel_count = shift || 1;
+    my $parallel_slot = shift;
 
     my $circs;
     my $editor = new_editor;
@@ -1014,7 +1032,8 @@ sub generate_fines {
             $circs = $editor->search_booking_reservation->search_where( { id => $circ_id, return_time => undef, cancel_time => undef } );
         }
     } else {
-        $circs = [overdue_circs(undef, 1, 1, 1)];
+        $circs = 
+            [overdue_circs(undef, 1, 1, 1, $parallel_count, $parallel_slot)];
     }
 
     return OpenILS::Application::Circ::CircCommon->generate_fines({circs => $circs, conn => $client})
index 5d0ac8e..fd030a9 100755 (executable)
@@ -58,16 +58,15 @@ if ($parallel == 1) {
         api_level => 1,
     );
 
-    my $storage = OpenSRF::AppSession->create("open-ils.storage");
-    my $r = $storage->request('open-ils.storage.action.circulation.overdue.id_list');
-    while (my $resp = $r->recv(timeout => 600)) {
-        my $circ_id = $resp->content;
-        $multi_generator->request( 'open-ils.storage.action.circulation.overdue.generate_fines', $circ_id );
+    for my $slot (1..$parallel) {
+        $multi_generator->request(
+            'open-ils.storage.action.circulation.overdue.generate_fines',
+            undef, $parallel, $slot
+        );
     }
-    $storage->disconnect();
+
     $multi_generator->session_wait(1);
     $multi_generator->disconnect;
-
 }
 
 unlink $lockfile;