Skip to content

Commit

Permalink
Delete working dir after upload to s3 finished
Browse files Browse the repository at this point in the history
  • Loading branch information
MediaMarco committed May 22, 2024
1 parent 6bfbd6c commit 34ac137
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lambda/src/main/java/de/otto/jlineup/lambda/JLineupHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.otto.jlineup.browser.ScreenshotContext;
import de.otto.jlineup.config.JobConfig;
import de.otto.jlineup.config.RunStep;
import de.otto.jlineup.file.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
Expand Down Expand Up @@ -84,8 +85,15 @@ public void handleRequest(InputStream input, OutputStream output, Context contex
throw new RuntimeException("Environment variable JLINEUP_LAMBDA_S3_BUCKET not set! Please create a bucket and set the environment variable to contain it's name.");
}
CompletableFuture<CompletedDirectoryUpload> uploadStatus = transferManager.uploadDirectory(r -> r.bucket(bucketName).source(workingDir)).completionFuture();
output.write(("Upload status: " + uploadStatus.get().toString() + "\n").getBytes(StandardCharsets.UTF_8));

//Block until upload is completed
CompletedDirectoryUpload completedDirectoryUpload = uploadStatus.get();

output.write(("Upload status: " + completedDirectoryUpload.toString() + "\n").getBytes(StandardCharsets.UTF_8));
output.write(("Ok! (Retries: " + retries + ")\n").getBytes(StandardCharsets.UTF_8));

FileUtils.deleteDirectory(workingDir);

} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 34ac137

Please sign in to comment.