[英]check if transcribe job exists if it exists delete it
Hello I'm using the aws cli with pyhon.您好,我正在使用带有 pyhon 的 aws cli。 I need to delete previous jobs from the transcription service to prevent a high invoice.
我需要从转录服务中删除以前的工作以防止高额发票。 My problem remains when the script starts because yet there isn't any job, I need delete if it exist and if it doesn't exists do nothing.
当脚本启动时我的问题仍然存在,因为还没有任何工作,如果它存在我需要删除,如果它不存在则什么也不做。
transcribe_client = boto3.client('transcribe', aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, region_name=AWS_DEFAULT_REGION)
JOB_NAME = "Example-job"
try:
transcribe_client.delete_transcription_job(TranscriptionJobName=JOB_NAME)
except ClientError as e:
raise Exception( "boto3 client error el job doesnt exists: " + e.__str__())
except Exception as e:
raise Exception( "Unexpected error deleting job: " + e.__str__())
When the program starts it's throwing a exception because there isn't any job.程序启动时会抛出异常,因为没有任何工作。 I need to check if this exists and the delete it, and if this job doesn't exists do nothing and should not exists crashes.
我需要检查它是否存在并删除它,如果这个作业不存在则什么也不做,不应该存在崩溃。
Also I don't know if this jobs has a price, if this jobs doesn't have cost/price I will generate many jobs with unique id and of this way I should prevent crashes.我也不知道这个工作是否有价格,如果这个工作没有成本/价格,我会生成许多具有唯一 ID 的工作,这样我应该可以防止崩溃。
any idea guys to solve this problem I will appreciate.解决这个问题的任何想法,我将不胜感激。 thanks so much.
非常感谢。
You can call list_transcription_jobs to retrieve a list of transcription jobs that match the specified criteria, or a list of all transcription jobs if you don't specify criteria.您可以调用list_transcription_jobs来检索符合指定条件的转录作业列表,或者如果您未指定条件,则检索所有转录作业的列表。 You can then iterate over the results and decide which jobs need to be deleted.
然后您可以遍历结果并决定需要删除哪些作业。
Alternatively, You can call get_transcription_job which, according to the docs, will throw TranscribeService.Client.exceptions.NotFoundException.或者,您可以调用get_transcription_job ,根据文档,这将抛出 TranscribeService.Client.exceptions.NotFoundException。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.