dranxo
dranxo

Reputation: 3388

Amazon EMR --wait-for-steps

I'm writing a bash script that runs an aws emr command (aws emr version 1.5.2).

How do I tell my script to wait until the emr job finishes before proceeding? The --wait-for-steps option is depreciated now.

via jq I got this, but it just seems like the wrong approach:

STEP_STATUS_STATE=$(aws emr list-steps --cluster-id ${CLUSTER_ID} | jq '.Steps[0].Status.State' | tr -d '"')
while [[ ${STEP_STATUS_STATE} == PENDING ]] || [[ ${STEP_STATUS_STATE} == RUNNING ]]; do
    STEP_STATUS_STATE=$(aws emr list-steps --cluster-id ${CLUSTER_ID} | jq '.Steps[0].Status.State' | tr -d '"')
    echo $(date) ${STEP_STATUS_STATE}
    sleep 10
done

Upvotes: 7

Views: 2663

Answers (2)

Dhawal shah
Dhawal shah

Reputation: 41

Try using AWS emr wait step-complete option. Have a reference here.

Upvotes: 2

Sandesh Deshmane
Sandesh Deshmane

Reputation: 2305

I use AWS java api to wait till job is finished like below. Hope this helps

 public static final List<JobFlowExecutionState> DONE_STATES = Arrays
        .asList(new JobFlowExecutionState[] {
                JobFlowExecutionState.COMPLETED,
                JobFlowExecutionState.FAILED,
                JobFlowExecutionState.TERMINATED });

...

  public static boolean isDone(String value) {
    JobFlowExecutionState state = JobFlowExecutionState.fromValue(value);
    return Constants.DONE_STATES.contains(state);
}

   .
   .
  STATUS_LOOP: while (true) {
        DescribeJobFlowsRequest desc = new DescribeJobFlowsRequest(
                Arrays.asList(new String[] { result.getJobFlowId() }));
        DescribeJobFlowsResult descResult = emr.describeJobFlows(desc);
        for (JobFlowDetail detail : descResult.getJobFlows()) {
            String state = detail.getExecutionStatusDetail().getState();
            if (isDone(state)) {
                logger.info("Job " + state + ": " + detail.toString());

                if(loadToDailyDB && state.equalsIgnoreCase("COMPLETED"))
                {

                    //Do something
                }
                if(!state.equalsIgnoreCase("COMPLETED"))
                {

                }

                break STATUS_LOOP;
            } else if (!lastState.equals(state)) {
                lastState = state;
                logger.info("Job " + state + " at "
                        + new Date().toString());
            }
        }
        Thread.sleep(75000);

Upvotes: 2

Related Questions