简体   繁体   English

如何每 n 秒检查一次列表中的作业状态,直到所有作业完成?

[英]How to check status for jobs in list each n seconds till all jobs finished?

I'm having a problem with checking the status for all my Transcription job before start another step.在开始另一个步骤之前,我在检查所有转录作业的状态时遇到问题。 I need to know when all jobs in myList are COMPLTETED or FAILED , if it is false retry again 5 seconds later, but currently it keeps forever running, there is my python script:我需要知道myList中的所有作业何时为COMPLTETEDFAILED ,如果它是错误的 5 秒后重试,但目前它一直在运行,有我的 python 脚本:

while True:
    final_list = []
    for job in myList:
        status = transcribe.get_transcription_job(TranscriptionJobName=job)
        final_list.append(status.get('TranscriptionJob').get('TranscriptionJobStatus'))

    if all(status in final_list for status in ['COMPLETED', 'FAILED']):
        break
    time.sleep(5)

Edit 1 Possible response status can be QUEUED , IN_PROGRESS , FAILED , COMPLETED编辑 1可能的响应状态可以是QUEUEDIN_PROGRESSFAILEDCOMPLETED

Edit 2 Omar was right I'm not extracting corretly the status of each job response but script still running forever.编辑 2 Omar 是对的,我没有正确提取每个作业响应的状态,但脚本仍然永远运行。

Response syntax of get_transcription_job method is: get_transcription_job方法的响应语法是:

{
    'TranscriptionJob': {
        'TranscriptionJobName': 'string',
        'TranscriptionJobStatus': 'QUEUED'|'IN_PROGRESS'|'FAILED'|'COMPLETED',
        ...
    }
}

So instead of adding 'status' object which contains other fields, you need to append status.get('TranscriptionJob').get('TranscriptionJobStatus')因此,不要添加包含其他字段的“状态”object,而是需要 append status.get('TranscriptionJob').get('TranscriptionJobStatus')

Change:改变:

final_list.append(status)

By:经过:

final_list.append(status.get('TranscriptionJob').get('TranscriptionJobStatus'))

Reference:参考:

Boto3 get_transcription_job Boto3 get_transcription_job

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM