Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Fix the problem when the subpath does not exists in lambda (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
realstraw committed Dec 3, 2020
1 parent a8de708 commit 59a1661
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ object S3FileHandler extends Logging {
final val TmpDirectory = "/tmp/starport"

def getTempDirectory(baseDir: Option[String]): File = {
if (Lambda.isLambda()) {
new File(TmpDirectory)
} else {
// TODO change this to "/mnt/tmp/starport"
// and delete the file afterwards
val tempDir = new File(baseDir.getOrElse(s"${System.getProperty("user.home")}/.starport"))
if (!tempDir.exists()) tempDir.mkdir()
tempDir
}
val tempDir =
if (Lambda.isLambda())
new File(TmpDirectory)
else
new File(baseDir.getOrElse(s"${System.getProperty("user.home")}/.starport"))

if (!tempDir.exists()) tempDir.mkdirs()

tempDir
}

def getFileFromS3(s3spec: String, baseDir: Option[String] = None): File = {
Expand All @@ -30,7 +30,8 @@ object S3FileHandler extends Logging {

val bucket = s3Uri.getHost()
val key = s3Uri.getPath().stripPrefix("/")
val localFile = File.createTempFile("starport_", "_" + key.split('/').last, getTempDirectory(baseDir))
val localFile =
File.createTempFile("starport_", "_" + key.split('/').last, getTempDirectory(baseDir))

logger.info(s"Downloading $s3spec to ${localFile.getAbsolutePath()}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,36 @@ class SubmitHandler extends RequestHandler[SubmitRequest, SubmitResponse] with L

val args: Array[String] = input.getArgs

try {
args.head match {
case "deleteTmpDir" => {
status = 255
logger.error(s"received call to delete ${S3FileHandler.TmpDirectory}")
logger.error(deleteTmpDir())
}
case _ => SubmitPipeline.main(args)
}
} catch {
case caughtExit: LambdaExitException => {
status = caughtExit.status
logger.error("exit:", caughtExit)
logger.error(scanTmpFiles())
}
case unhandled: Throwable => {
status = 255
logger.error("exception:", unhandled)
logger.error(scanTmpFiles())
}
} finally {
outPrintStream.flush()
errPrintStream.flush()
outString = outCapture.toString
errString = errCapture.toString
outCapture.reset()
errCapture.reset()
lambdaOut.print(outString)
lambdaErr.print(errString)
}
try {
args.head match {
case "deleteTmpDir" =>
status = 255
logger.error(s"received call to delete ${S3FileHandler.TmpDirectory}")
logger.error(deleteTmpDir())
case _ =>
SubmitPipeline.main(args)
}
} catch {
case caughtExit: LambdaExitException =>
status = caughtExit.status
logger.error("exit:", caughtExit)
logger.error(scanTmpFiles())
case unhandled: Throwable =>
status = 255
logger.error("exception:", unhandled)
logger.error(scanTmpFiles())
} finally {
outPrintStream.flush()
errPrintStream.flush()
outString = outCapture.toString
errString = errCapture.toString
outCapture.reset()
errCapture.reset()
lambdaOut.print(outString)
lambdaErr.print(errString)
}

SubmitResponse(outString, errString, status, input)
SubmitResponse(outString, errString, status, input)

}

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "7.4.0"
version in ThisBuild := "7.4.1"

0 comments on commit 59a1661

Please sign in to comment.