问题描述
我正在尝试在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秒。 一些帮助或指针将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)