Skip to content

Commit 1ac5cfc

Browse files
committed
optimized job
1 parent bff56f1 commit 1ac5cfc

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

.github/workflows/aws-mq-cleanup.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
name: Cleanup MQ Configurations
2-
permissions:
3-
id-token: write
4-
contents: read
52
on:
63
workflow_dispatch:
74
inputs:
8-
aws_region-updatecli-ref:
5+
aws_region:
96
description: "AWS region where MQ configurations need to be cleaned up"
107
type: string
118
default: eu-west-1
129
schedule:
13-
- cron: '0 0 1 * *'
14-
10+
- cron: '23 5 1 * *'
11+
permissions:
12+
id-token: write
13+
contents: read
14+
env:
15+
RETENTION_DAYS: 30
1516
jobs:
1617
delete-mq-configs:
18+
1719
runs-on: ubuntu-latest
1820
steps:
1921

@@ -27,18 +29,19 @@ jobs:
2729

2830
- name: Delete old MQ configurations (using pagination)
2931
run: |
30-
set -e
31-
retention_days=30
32-
threshold_epoch=$(date -d "$retention_days days ago" +"%s")
32+
set -o pipefail
33+
threshold_epoch=$(date -d "$RETENTION_DAYS days ago" +"%s")
3334
next_token=""
3435
35-
echo "Checking for MQ configurations older than $retention_days days..."
36+
echo "Checking for MQ configurations older than $RETENTION_DAYS days..."
3637
3738
while true; do
39+
list_configurations_cmd="aws mq list-configurations --max-results 100 --output json"
40+
3841
if [ -z "$next_token" ]; then
39-
response=$(aws mq list-configurations --max-results 100 --output json)
42+
response=$($list_configurations_cmd )
4043
else
41-
response=$(aws mq list-configurations --max-results 100 --next-token "$next_token" --output json)
44+
response=$($list_configurations_cmd --next-token "$next_token" )
4245
fi
4346
4447
configs=$(echo "$response" | jq -c '.Configurations[]?')
@@ -54,9 +57,8 @@ jobs:
5457
fi
5558
5659
created=$(jq -r '.LatestRevision.Created' <<< "$config")
57-
created_clean="${created%%.*}"
58-
created_epoch=$(date -d "$created_clean" +"%s" 2>/dev/null || \
59-
date -j -f "%Y-%m-%dT%H:%M:%S" "$created_clean" +"%s" || echo 0)
60+
created_epoch=$(date -d "${created%%.*}" +"%s" || echo 0)
61+
6062
6163
age_days=$(( ( $(date -u +"%s") - created_epoch ) / 86400 ))
6264

0 commit comments

Comments
 (0)