[ARVADOS] updated: 31506905a346552d6ef7a0b100c5fd203da7c2d8

git at public.curoverse.com git at public.curoverse.com
Thu Mar 20 17:23:38 EDT 2014


Summary of changes:
 sdk/cli/bin/crunch-job |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

       via  31506905a346552d6ef7a0b100c5fd203da7c2d8 (commit)
      from  32f8186abb06258d0cfe0f05e040365c4ec6b68a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 31506905a346552d6ef7a0b100c5fd203da7c2d8
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Mar 20 17:23:43 2014 -0400

    Use flock() to prevent sharing crunch-tmp with another job in local dev mode.

diff --git a/sdk/cli/bin/crunch-job b/sdk/cli/bin/crunch-job
index 15b86d4..c098268 100755
--- a/sdk/cli/bin/crunch-job
+++ b/sdk/cli/bin/crunch-job
@@ -80,6 +80,7 @@ use Getopt::Long;
 use Warehouse;
 use Warehouse::Stream;
 use IPC::System::Simple qw(capturex);
+use Fcntl ':flock';
 
 $ENV{"TMPDIR"} ||= "/tmp";
 unless (defined $ENV{"CRUNCH_TMP"}) {
@@ -331,6 +332,12 @@ else
 }
 
 
+if (!$have_slurm)
+{
+  must_lock_now("$ENV{CRUNCH_TMP}/.lock", "a job is already running here.");
+}
+
+
 my $build_script;
 
 
@@ -478,6 +485,12 @@ else
   Log (undef, "Install exited $?");
 }
 
+if (!$have_slurm)
+{
+  # Grab our lock again (we might have deleted and re-created CRUNCH_TMP above)
+  must_lock_now("$ENV{CRUNCH_TMP}/.lock", "a job is already running here.");
+}
+
 
 
 foreach (qw (script script_version script_parameters runtime_constraints))
@@ -1361,6 +1374,15 @@ sub ban_node_by_slot {
   Log (undef, "backing off node " . $slot[$slotid]->{node}->{name} . " for 60 seconds");
 }
 
+sub must_lock_now
+{
+  my ($lockfile, $error_message) = @_;
+  open L, ">", $lockfile or croak("$lockfile: $!");
+  if (!flock L, LOCK_EX|LOCK_NB) {
+    croak("Can't lock $lockfile: $error_message\n");
+  }
+}
+
 __DATA__
 #!/usr/bin/perl
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list