From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Wed, 11 Nov 2009 02:04:45 +0000 (+0000)
Subject: Unlink the lock file as soon as possible if 1) we have not already looked at it and... 
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=69eeb132290ba29196861f943a03255c6e302757;p=contrib%2FConifer.git

Unlink the lock file as soon as possible if 1) we have not already looked at it and 2) it contains our pid.  This is to allow multiple, concurrent runners where possible, after the find-events phase

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14863 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/src/support-scripts/action_trigger_runner.pl b/Open-ILS/src/support-scripts/action_trigger_runner.pl
index 393fa65719..1e502bb134 100755
--- a/Open-ILS/src/support-scripts/action_trigger_runner.pl
+++ b/Open-ILS/src/support-scripts/action_trigger_runner.pl
@@ -141,7 +141,16 @@ sub run_pending {
     return unless $opt_run_pending;
     my $ses = OpenSRF::AppSession->create('open-ils.trigger');
     my $req = $ses->request('open-ils.trigger.event.run_all_pending' => $opt_granularity);
+
+    my $check_lockfile = 1;
     while(my $resp = $req->recv(timeout => 7200)) {
+        if ($check_lockfile && -e $opt_lockfile) {
+            open LF, $opt_lockfile;
+            my $contents = <LF>;
+            close LF;
+            unlink $opt_lockfile if ($contents == $$);
+            $check_lockfile = 0;
+        }
         if($opt_debug_stdout) {
             print OpenSRF::Utils::JSON->perl2JSON($resp->content) . "\n";
         }
@@ -166,7 +175,10 @@ try {
     warn "$e\n";
 };
 
-unlink $opt_lockfile;
-
-
+if (-e $opt_lockfile) {
+    open LF, $opt_lockfile;
+    my $contents = <LF>;
+    close LF;
+    unlink $opt_lockfile if ($contents == $$);
+}