not natively, but you could use a script for it: ```bash #!/bin/bash # Exit immediately if a comman
not natively, but you could use a script for it:
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Check if workflow name and status are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <workflow-name> <status>"
echo "Status can be: queued, running, succeeded, failed"
exit 1
fi
WORKFLOW_NAME="$1"
STATUS="$2"
while true; do
# Get workflow instances with specified status
output=$(npx wrangler workflows instances list "$WORKFLOW_NAME" --status="$STATUS" 2>/dev/null)
ids=$(echo "$output" | awk -F '│' '{gsub(/ /, "", $2); if ($2 ~ /^[a-f0-9-]+$/) print $2}')
instance_count=$(echo "$ids" | wc -w | tr -d ' ')
if [ "$instance_count" -eq 0 ]; then
echo "No more instances found with status '$STATUS'"
break
fi
echo "Found $instance_count instances with status '$STATUS'"
# Process in batches
BATCH_SIZE=5
echo "$ids" | xargs -n$BATCH_SIZE -P$BATCH_SIZE -I{} sh -c '
id="$1"
workflow="$2"
if ! npx wrangler workflows instances terminate "$workflow" "$id" >/dev/null 2>&1; then
echo "Failed to terminate instance $id"
exit 1
fi
echo "Terminated $id"
' -- {} "$WORKFLOW_NAME"
echo "Batch complete, checking for remaining instances..."
done
echo "Done terminating all instances"#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Check if workflow name and status are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <workflow-name> <status>"
echo "Status can be: queued, running, succeeded, failed"
exit 1
fi
WORKFLOW_NAME="$1"
STATUS="$2"
while true; do
# Get workflow instances with specified status
output=$(npx wrangler workflows instances list "$WORKFLOW_NAME" --status="$STATUS" 2>/dev/null)
ids=$(echo "$output" | awk -F '│' '{gsub(/ /, "", $2); if ($2 ~ /^[a-f0-9-]+$/) print $2}')
instance_count=$(echo "$ids" | wc -w | tr -d ' ')
if [ "$instance_count" -eq 0 ]; then
echo "No more instances found with status '$STATUS'"
break
fi
echo "Found $instance_count instances with status '$STATUS'"
# Process in batches
BATCH_SIZE=5
echo "$ids" | xargs -n$BATCH_SIZE -P$BATCH_SIZE -I{} sh -c '
id="$1"
workflow="$2"
if ! npx wrangler workflows instances terminate "$workflow" "$id" >/dev/null 2>&1; then
echo "Failed to terminate instance $id"
exit 1
fi
echo "Terminated $id"
' -- {} "$WORKFLOW_NAME"
echo "Batch complete, checking for remaining instances..."
done
echo "Done terminating all instances"
