Can you write a python script that re-executes failed step-functions workflows? This…
- User
Can you write a python script that re-executes failed step-functions workflows? This script will use argparse to read parameters, will then fetch all the failed workflows, retrieve their inputs and names and then re-execute them by using the same input as the original workflow and the same name but adding a "retry" suffix at the end.
- Assistant
import boto3 import argparse import json import time
def get_failed_workflows(): client = boto3.client('stepfunctions') paginator = client.get_paginator('list_state_machines') for page in paginator.paginate(): for state_machine_arn in page['StateMachines']: response = client.describe_state_machine(SnapshotArn=state_machine_arn) if response['FailedStepsCount'] > 0: yield state_machine_arn
def reexecute_workflows(workflow_arns, max_retries=3): client = boto3.client('stepfunctions') for workflow_arn in workflow_arns: for attempt in range(max_retries): retry_name = f"{workflow_arn.split('/')[-1]}{attempt}" response = client.start_execution( stateMachineArn=workflow_arn, name=retry_name, input=json.dumps({}) ) execution_arn = response['executionArn'] print(f"Attempt {attempt+1}: Re-executing workflow {workflow_arn} with name {retry_name}") time.sleep(10) # Wait for the workflow to complete before checking status status = client.describe_execution(ExecutionArn=execution_arn)['status'] if status == 'SUCCEEDED': print(f"Workflow {workflow_arn} succeeded on attempt {attempt+1}") break elif status == 'FAILED': print(f"Workflow {workflow_arn} failed on attempt {attempt+1}") else: print(f"Workflow {workflow_arn} is still running on attempt {attempt+1}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.