2017-06-28 8 views

答えて

1

Boto3には組み込み関数がありません。しかし、あなたは自分のウェイターを書くことができます。

参照:cluster_idstep_iddescribe_step

コールdescribe_step。レスポンスは、ステップの詳細を含む辞書です。キーの1つはステップ状態に関する情報を持つ「状態」です。状態が完了していない場合は、数秒待ってからCOMPLETEDになるか、待ち時間が上限を超えるまで再試行してください。

'State': 'PENDING'|'CANCEL_PENDING'|'RUNNING'|'COMPLETED'|'CANCELLED'|'FAILED'|'INTERRUPTED' 
0

私は、次のコード(あなたが0以下にmax_attemptsを設定した場合、何のランニング/保留中のステップは存在しないであろうまで、それは単に待機しますTHEN)を思い付いた:

def wait_for_steps_completion(emr_client, emr_cluster_id, max_attempts=0): 
    sleep_seconds = 30 
    num_attempts = 0 

    while True: 
     response = emr_client.list_steps(
      ClusterId=emr_cluster_id, 
      StepStates=['PENDING', 'CANCEL_PENDING', 'RUNNING'] 
     ) 
     num_attempts += 1 
     active_aws_emr_steps = response['Steps'] 

     if active_aws_emr_steps: 
      if 0 < max_attempts <= num_attempts: 
       raise Exception(
        'Max attempts exceeded while waiting for AWS EMR steps completion. Last response:\n' 
        + json.dumps(response, indent=3, default=str) 
       ) 
      time.sleep(sleep_seconds) 
     else: 
      return 
関連する問題