Skip to content

Commit

Permalink
Fix Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dakanji committed Dec 26, 2024
1 parent 44b6d7d commit f94136b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ runs:
echo "${{ inputs.sleep_time }} Second Pause for Rate Limit"
sleep ${{ inputs.sleep_time }}
fi
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,46 @@ runs:
CURRENT_TIME=$(date +%s)
WAIT_PERIOD=$(( RESET_TIME - CURRENT_TIME ))
if [[ "$REMAINING_CALLS" -gt 9 ]]; then
if (( REMAINING_CALLS > 9 )); then
SLEEP_TIME=0
elif [[ "$REMAINING_CALLS" -gt 1 ]]; then
elif (( REMAINING_CALLS > 1 )); then
SLEEP_TIME=$(( WAIT_PERIOD / REMAINING_CALLS ))
else
SLEEP_TIME=$(( WAIT_PERIOD + 60 ))
fi
# Ensure a minimum sleep time to mitigate secondary rate limits.
if [[ "$SLEEP_TIME" -lt "$MIN_TIME" ]]; then
if (( SLEEP_TIME < MIN_TIME )); then
SLEEP_TIME=$MIN_TIME
fi
}
handle_secondary_rate_limit() {
while [[ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]]; do
while (( RETRY_COUNT < MAX_RETRIES )); do
RESPONSE=$(curl -s -I -H "Authorization: Bearer $TOKEN" $RATE_LIMIT_URL)
RETRY_BASE=$(echo "$RESPONSE" | grep -i 'retry-after' | awk '{print $2}' | tr -d '\r')
if [[ -n "$RETRY_BASE" ]]; then
if [[ "$RETRY_BASE" -lt "$BASE_TIME" ]]; then
RETRY_BASE=$BASE_TIME
fi
SCALE_FACTOR=$(( RETRY_COUNT + 1 ))
RETRY_AFTER=$(( RETRY_BASE * SCALE_FACTOR * SCALE_FACTOR ))
echo "Secondary Rate Limit is Active"
echo "Wait $RETRY_AFTER seconds for reset..."
sleep "$RETRY_AFTER"
((RETRY_COUNT++))
else
if [[ ! -n "$RETRY_BASE" ]]; then
break
fi
done
if [[ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]]; then
echo "Exceeded $MAX_RETRIES max retries for secondary rate limits ... Exiting."
exit 1
fi
if (( RETRY_BASE < BASE_TIME )); then
RETRY_BASE=$BASE_TIME
fi
SCALE_FACTOR=$(( RETRY_COUNT + 1 ))
RETRY_AFTER=$(( RETRY_BASE * SCALE_FACTOR * SCALE_FACTOR ))
RETRY_COUNT=$SCALE_FACTOR
echo "Secondary Rate Limit is Active"
echo "Wait $RETRY_AFTER seconds for reset..."
sleep "$RETRY_AFTER"
if (( RETRY_COUNT >= MAX_RETRIES )); then
break
fi
done
}
# Check for secondary rate limits
Expand All @@ -72,5 +74,5 @@ runs:
# Calculate sleep time for primary rate limits
calculate_sleep_time
echo "::set-output name=sleep_time::$SLEEP_TIME"
echo "sleep_time=$SLEEP_TIME" >> $GITHUB_OUTPUT
shell: bash
2 changes: 2 additions & 0 deletions .github/workflows/issues-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:

if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'stale'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- name: Check Rate Limit
id: rate-limit-check01
Expand Down
33 changes: 23 additions & 10 deletions .github/workflows/issues-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ permissions:
concurrency:
group: lock

# Workflow-wide environment variable
env:
JOB_CONDITION: ${{ github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock' }}

# Lock Threads - https://github.com/dakanji/lock-threads
jobs:

lock-threads-01:
name: Lock Resolved Issues
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check01
uses: ./.github/actions/check-rate-limit
Expand Down Expand Up @@ -59,8 +57,11 @@ jobs:
needs: [lock-threads-01]
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check02
uses: ./.github/actions/check-rate-limit
with:
Expand Down Expand Up @@ -90,8 +91,11 @@ jobs:
needs: [lock-threads-02]
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check03
uses: ./.github/actions/check-rate-limit
with:
Expand Down Expand Up @@ -122,8 +126,11 @@ jobs:
needs: [lock-threads-03]
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check04
uses: ./.github/actions/check-rate-limit
with:
Expand Down Expand Up @@ -153,8 +160,11 @@ jobs:
needs: [lock-threads-04]
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check05
uses: ./.github/actions/check-rate-limit
with:
Expand Down Expand Up @@ -186,8 +196,11 @@ jobs:
needs: [lock-threads-05]
runs-on: ubuntu-24.04

if: env.JOB_CONDITION
if: github.event_name == 'schedule' || github.event.inputs.job_id == 'all' || github.event.inputs.job_id == 'lock'
steps:
- name: Repository Checkout
uses: actions/checkout@v4

- id: rate-limit-check06
uses: ./.github/actions/check-rate-limit
with:
Expand Down

0 comments on commit f94136b

Please sign in to comment.