我正在尝试在 lambda 中启动异步转录作业。我配置了一个 cloudwatch 事件,该事件应在转录作业完成时触发;这样我就可以在不同的 lambda 中对作业完成执行一些操作。但问题是异步转录作业已成功启动,日志中有以下 jobResult,但作业从未完成,并且未触发作业完成事件。
jobResult = java.util.concurrent.CompletableFuture@481a996b[Not completed, 1 dependents]
我的代码在以下几行 -
public class APIGatewayTranscriptHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
S3Client s3Client = S3Client.create();
String fileUrl = s3Client.utilities().getUrl(GetUrlRequest.builder().bucket("srcBucket").key("fileName").build()).toString();
Media media = Media.builder().mediaFileUri(fileUrl).build();
StartTranscriptionJobRequest request = StartTranscriptionJobRequest.builder().
languageCode(LanguageCode.ES_ES)
.media(media).outputBucketName("destBucket")
.transcriptionJobName("jobName")
.mediaFormat("mp3")
.settings(Settings.builder().showSpeakerLabels(true).maxSpeakerLabels(2).build())
.build();
TranscribeAsyncClient transcribeAsyncClient = TranscribeAsyncClient.create();
CompletableFuture<StartTranscriptionJobResponse> jobResult = transcribeAsyncClient.startTranscriptionJob(request);
logger.log("jobResult = " + jobResult.toString());
jobResult.whenComplete((jobResponse, err) -> {
try {
if (jobResponse != null) {
logger.log("CompletableFuture : response = " + jobResponse.toString());
} else {
logger.log("CompletableFuture : NULL response: error = " + err.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
}
});
//Job is completed only if Thread is made to sleep
/*try {
Thread.sleep(50000);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
response.setStatusCode(200);
Map<String, String> responseBody = new HashMap<String, String>();
responseBody.put("Status", jobResult.toString());
String responseBodyString = new JSONObject(responseBody).toJSONString();
response.setBody(responseBodyString);
return response;
}
}
我已经验证,音频文件存在于源存储桶中。
仅当我在启动作业后在 lambda 中添加一些睡眠时间时,才会触发上述作业并触发作业完成事件。
例如,
Thread.sleep(50000);
如果添加睡眠时间,每件事都会按预期工作。但是如果没有 Thread.sleep(),这项工作永远不会完成。lambda 的超时配置为 60 秒。一些帮助或指示将不胜感激。