in src/main/java/com/company/demoapplication/TaskPublisher.java [21:49]
static void publishImageTransformTask(Integer numOfTasks) {
try {
List<String> list = listImagesOnS3();
if (list.isEmpty()) {
Main.logger().info("No images in bucket. Uploading example image...");
Main.sharedS3.putObject(Main.bucketName, Main.sampleImagesFolder + "example-image.png", new File("src/main/resources/example-image.png"));
return;
}
Main.logger().debug("Starting...");
Main.logger().debug(list);
IntStream
.range(0, numOfTasks)
.mapToObj(i -> list.get(randomGenerator.nextInt(list.size())))
.forEach(key -> {
try {
Main.sharedSqs.sendMessage(createRequest(Main.sqsQueueUrl, key));
} catch (RuntimeException e) {
Main.logger().debug("Exception while sending task to SQS: " + e);
}
Main.logger().debug("Sent task to SQS.");
});
} catch (Exception e) {
// since this runs async, easiest way to catch errors is to fail hard!
e.printStackTrace();
System.exit(1);
}
}