[open-ils-commits] r15379 - branches/rel_1_6/Open-ILS/src/support-scripts (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jan 25 12:42:06 EST 2010
Author: miker
Date: 2010-01-25 12:42:03 -0500 (Mon, 25 Jan 2010)
New Revision: 15379
Modified:
branches/rel_1_6/Open-ILS/src/support-scripts/action_trigger_runner.pl
Log:
Backporting r15378: provide a --max-sleep=<seconds> option for use in --process-hooks mode to wait on the lock file to go away, and default to 1 hour (3600)
Modified: branches/rel_1_6/Open-ILS/src/support-scripts/action_trigger_runner.pl
===================================================================
--- branches/rel_1_6/Open-ILS/src/support-scripts/action_trigger_runner.pl 2010-01-25 17:38:38 UTC (rev 15378)
+++ branches/rel_1_6/Open-ILS/src/support-scripts/action_trigger_runner.pl 2010-01-25 17:42:03 UTC (rev 15379)
@@ -25,6 +25,7 @@
my $opt_lockfile = '/tmp/action-trigger-LOCK';
my $opt_osrf_config = '/openils/conf/opensrf_core.xml';
my $opt_custom_filter = '/openils/conf/action_trigger_filters.json';
+my $opt_max_sleep = 3600; # default to 1 hour
my $opt_run_pending = 0;
my $opt_debug_stdout = 0;
my $opt_help = 0;
@@ -36,12 +37,14 @@
'run-pending' => \$opt_run_pending,
'hooks=s' => \$opt_hooks,
'process-hooks' => \$opt_process_hooks,
+ 'max-sleep' => \$opt_max_sleep,
'debug-stdout' => \$opt_debug_stdout,
'custom-filters=s' => \$opt_custom_filter,
'lock-file=s' => \$opt_lockfile,
'help' => \$opt_help,
);
+my $max_sleep = $opt_max_sleep;
# typical passive hook filters
my $hook_handlers = {
@@ -88,6 +91,10 @@
--process-hooks
Create hook events
+ --max-sleep=<seconds>
+ When in process-hooks mode, wait up to <seconds> for the lock file to
+ go away. Defaults to 3600 (1 hour).
+
--hooks=hook1[,hook2,hook3,...]
Define which hooks to create events for. If none are defined,
it defaults to the list of hooks defined in the --custom-filters option.
@@ -150,8 +157,17 @@
help() and exit if $opt_help;
help() and exit unless ($opt_run_pending or $opt_process_hooks);
-# check / set the lockfile
-die "I'm already running with lockfile $opt_lockfile\n" if -e $opt_lockfile;
+# check the lockfile
+if (-e $opt_lockfile) {
+ die "I'm already running with lockfile $opt_lockfile\n" if (!$opt_process_hooks);
+ # sleeping loop if we're in --process-hooks mode
+ do { last unless ( -e $opt_lockfile ); $max_sleep--; } while ($max_sleep >= 0 && sleep(1));
+}
+
+# there's a tiny race condition here ... oh well
+die "Someone else has been holding the lockfile $opt_lockfile for at least $opt_max_sleep. Giving up now ...\n" if (-e $opt_lockfile);
+
+# set the lockfile
open(F, ">$opt_lockfile") or die "Unable to open lockfile $opt_lockfile for writing\n";
print F $$;
close F;
More information about the open-ils-commits
mailing list