Skip to content

Commit

Permalink
chore:throtting
Browse files Browse the repository at this point in the history
  • Loading branch information
codernesty committed Aug 22, 2024
1 parent be28343 commit b92df09
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,40 @@ jobs:
echo "Error: Service ARN not found for service name ${{ secrets.APP_RUNNER_SERVICE_NAME_BACKEND }}."
exit 1
fi

# Set retry logic with adaptive mode and a maximum of 10 attempts
export AWS_RETRY_MODE='adaptive'
export AWS_MAX_ATTEMPTS=10

# Update the backend service in AWS App Runner
aws apprunner update-service \
--service-arn "$SERVICE_ARN" \
--source-configuration "$(cat <<EOF
{
"CodeRepository": {
"RepositoryUrl": "${{ secrets.REPOSITORY_URL }}",
"SourceCodeVersion": {
"Type": "BRANCH",
"Value": "master"
},
"SourceDirectory": "linguaphoto"

# Retry logic with exponential backoff
RETRY_COUNT=0
MAX_RETRIES=15
BACKOFF_TIME=5 # Initial backoff time in seconds

while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if aws apprunner update-service \
--service-arn "$SERVICE_ARN" \
--source-configuration "$(cat <<EOF
{
"CodeRepository": {
"RepositoryUrl": "${{ secrets.REPOSITORY_URL }}",
"SourceCodeVersion": {
"Type": "BRANCH",
"Value": "master"
},
"SourceDirectory": "linguaphoto"
}
}
}
EOF
)"
EOF
)"; then
echo "Service updated successfully."
exit 0
else
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Update failed. Attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in $BACKOFF_TIME seconds..."
sleep $BACKOFF_TIME
BACKOFF_TIME=$((BACKOFF_TIME * 2)) # Exponential backoff
fi
done

echo "Failed to update the service after $MAX_RETRIES attempts."
exit 1

# Job for deploying the frontend service
deploy-frontend:
Expand Down

0 comments on commit b92df09

Please sign in to comment.