我相信您需要调用Aws\MediaConvert\Exception\MediaConvertException
并捕获 MediaConvert 特定的错误。我没有看到您的任何使用语句,但我认为代码如下所示。
请注意,我正在捕获所有 MediaConvert 客户端错误,但我相信您可以通过以下方式专门调出 NotFoundExceptionAws\MediaConvert\Exception\MediaConvertException\NotFoundException
use Aws\MediaConvert\MediaConvertClient;
use Aws\Exception\AwsException;
use Aws\MediaConvert\Exception\MediaConvertException as MediaConvertError;
function get_aws_job_id_status($job_id)
{
$result = [];
$client = \App::make('aws')->createClient('MediaConvert', [
// 'profile' => 'default',
// 'version' => '2017-08-29',
'region' => 'region',
'endpoint' => "endpoint"
]);
try {
$result = $client->getJob([
'Id' => $job_id,
]);
return $result;
} catch (MediaConvertError $e) {
/*Oh no, the job id provided ca not be found.
Let us log the job id and the message and return it back up to the main application
Note this assumes the main application is iterating through a list of JobIDs and
can handle this and log that job id was not found and will not have the normal Job
JSON structure.
*/
$error = array("Id"=>$job_id, "Message"=>"Job Id Not found");
$result = json_encode($error);
return $result;
}
}
还要记住,如果您正在轮询工作状态,如果您的列表变得太大,您可能会受到限制。您需要捕获 TooManyRequestsException [1] 并尝试使用退避阈值 [2] 进行轮询。
最具可扩展性的解决方案是使用 CloudWatch Events 并根据 STATUS_UPDATE、COMPLETE 和 ERROR 状态跟踪作业。[3]
[1] https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.MediaConvert.Exception.MediaConvertException.html
[2] https://docs.aws.amazon.com /general/latest/gr/api-retries.html
[3] https://docs.aws.amazon.com/mediaconvert/latest/ug/monitoring-overview.html