my $have_slurm = exists $ENV{SLURM_JOBID} && exists $ENV{SLURM_NODELIST};
my $job_has_uuid = $jobspec =~ /^[-a-z\d]+$/;
+my $local_job = !$job_has_uuid;
$SIG{'HUP'} = sub
$metastream->clear;
$metastream->write_start('log.txt');
-my $User = {};
+my $User = $arv->{'users'}->{'current'}->execute;
+
my $Job = {};
my $job_id;
my $dbh;
if ($job_has_uuid)
{
$Job = $arv->{'jobs'}->{'get'}->execute('uuid' => $jobspec);
- $User = $arv->{'users'}->{'current'}->execute;
if (!$force_unlock) {
- if ($Job->{'is_locked_by'}) {
- croak("Job is locked: " . $Job->{'is_locked_by'});
+ if ($Job->{'is_locked_by_uuid'}) {
+ croak("Job is locked: " . $Job->{'is_locked_by_uuid'});
}
if ($Job->{'success'} ne undef) {
croak("Job 'success' flag (" . $Job->{'success'} . ") is not null");
qw(script script_version script_parameters);
}
- if (!defined $Job->{'uuid'}) {
- my $hostname = `hostname -s`;
- chomp $hostname;
- $Job->{'uuid'} = sprintf ("%s-t%d-p%d", $hostname, time, $$);
- }
+ $Job->{'is_locked_by_uuid'} = $User->{'uuid'};
+ $Job->{'started_at'} = gmtime;
+
+ $Job = $arv->{'jobs'}->{'create'}->execute('job' => $Job);
+
+ $job_has_uuid = 1;
}
$job_id = $Job->{'uuid'};
{
# Claim this job, and make sure nobody else does
- $Job->{'is_locked_by'} = $User->{'uuid'};
+ $Job->{'is_locked_by_uuid'} = $User->{'uuid'};
$Job->{'started_at'} = gmtime;
$Job->{'running'} = 1;
$Job->{'success'} = undef;
'running' => 0,
'done' => 0 };
if ($job_has_uuid) {
- unless ($Job->save() && $Job->{'is_locked_by'} == $User->{'uuid'}) {
+ unless ($Job->save() && $Job->{'is_locked_by_uuid'} == $User->{'uuid'}) {
croak("Error while updating / locking job");
}
}
my $build_script;
-do {
- local $/ = undef;
- $build_script = <DATA>;
-};
$ENV{"CRUNCH_SRC_COMMIT"} = $Job->{script_version};
-my $skip_install = (!$job_has_uuid && $Job->{script_version} =~ m{^/});
+my $skip_install = ($local_job && $Job->{script_version} =~ m{^/});
if ($skip_install)
{
$ENV{"CRUNCH_SRC"} = $Job->{script_version};
}
else
{
+ do {
+ local $/ = undef;
+ $build_script = <DATA>;
+ };
Log (undef, "Install revision ".$Job->{script_version});
my $nodelist = join(",", @node);
my @execargs = qw(sh);
my $build_script_to_send = "";
my $command =
- "mkdir -p $ENV{CRUNCH_TMP}/revision "
+ "mkdir -p $ENV{CRUNCH_WORK} $ENV{CRUNCH_TMP} "
."&& cd $ENV{CRUNCH_TMP} ";
if ($build_script)
{
release_allocation();
freeze();
+$Job->reload;
$Job->{'output'} = &collate_output();
+$Job->{'running'} = 0;
$Job->{'success'} = $Job->{'output'} && $success;
+$Job->{'finished_at'} = gmtime;
$Job->save if $job_has_uuid;
if ($Job->{'output'})
# Load new tasks
my $newtask_list = $arv->{'job_tasks'}->{'list'}->execute(
'where' => {
- 'created_by_job_task' => $Jobstep->{'arvados_task'}->{uuid}
+ 'created_by_job_task_uuid' => $Jobstep->{'arvados_task'}->{uuid}
},
'order' => 'qsequence'
);
sub cleanup
{
return if !$job_has_uuid;
- $Job->reload if $job_has_uuid;
+ $Job->reload;
$Job->{'running'} = 0;
$Job->{'success'} = 0;
$Job->{'finished_at'} = gmtime;
- $Job->save if $job_has_uuid;
+ $Job->save;
}