Skip to content

Commit

Permalink
[backend] fixup cloudupload code
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Dec 18, 2017
1 parent d576032 commit 006eb25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/backend/bs_clouduploadserver
Expand Up @@ -46,6 +46,7 @@ $port = $1 if $BSConfig::clouduploadserver =~ /:(\d+)$/;

my $rundir = $BSConfig::rundir || "$BSConfig::bsdir/run";
my $jobdir = "$BSConfig::bsdir/cloudupload";
my $eventdir = "$BSConfig::bsdir/events";

my $maxchild = $BSConfig::cloudupload_maxchild || $BSConfig::cloudupload_maxchild || 5;

Expand Down Expand Up @@ -154,6 +155,7 @@ sub cloudupload_upload {
delete $job->{'details'};
writexml("$jobdir/.$jobid$$", "$jobdir/$jobid", $job, $BSXML::clouduploadjob);
close F;
BSUtil::ping("$eventdir/clouduploadworker/.ping");
return $BSStdServer::return_ok;
}

Expand Down
14 changes: 10 additions & 4 deletions src/backend/bs_clouduploadworker
Expand Up @@ -30,7 +30,7 @@ my $maxchild = 4;
$maxchild = $BSConfig::clouduploadworker_maxchild if defined $BSConfig::clouduploadworker_maxchild;

my $myeventdir = "$eventdir/clouduploadworker";
my $jobdonedir = "$jobdir/cloudupload/done";
my $jobdonedir = "$jobdir/done";

sub lsjobs {
return sort {$a <=> $b} grep {/^\d+$/} ls($jobdir);
Expand All @@ -54,18 +54,23 @@ sub startupload {
exec("upload", $job->{'user'}, $job->{'target'}, "$jobdir/$jobid.file", "$jobdir/$jobid.data", "$jobdir/$jobid.log");
die("upload: $!\n");
}
my $ex;
while (1) {
if (!waitpid($pid, 0)) {
next if $! == POSIX::EINTR;
if (waitpid($pid, 0)) {
$ex = $?;
last;
}
if ($! != POSIX::EINTR) {
$ex = 1; # hmm
last;
}
}
my $ex = $?;
local *JOBLOCK;
$job = BSUtil::lockopenxml(\*JOBLOCK, '<', "$jobdir/$jobid", $BSXML::clouduploadjob);
if ($job->{'state'} eq 'uploading') {
if ($ex) {
$job->{'state'} = 'failed';
$job->{'details'} = "exit status ".($ex >> 8);
} else {
$job->{'state'} = 'succeeded';
}
Expand Down Expand Up @@ -182,6 +187,7 @@ my $conf = {
'eventdir' => $myeventdir,
'dispatches' => [],
'maxchild' => $maxchild,
'maxchild_user' => 2,
'run' => \&run,
};

Expand Down

0 comments on commit 006eb25

Please sign in to comment.