Skip to content

Commit

Permalink
temp send different alert
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Oct 2, 2024
1 parent cb4ccd9 commit d632ccb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions charts/tezos-reward-distributor/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ python src/main.py \
${EXTRA_TRD_ARGS} \
${dry_run_arg}

# if TRD fails, send a slack alert
# exit code 9 is PROVIDER_BUSY error which is usually temporary, so we ignore
if [ $? -ne 0 ] && [ $? -ne 9 ]; then
# if TRD fails or returns exit code 9, send a slack alert
exit_code=$?
if [ $exit_code -ne 0 ]; then
# check if bot token and channel are set
if [ -z "${SLACK_BOT_TOKEN}" ] || [ -z "${SLACK_CHANNEL}" ]; then
echo "TRD failed, but SLACK_BOT_TOKEN or SLACK_CHANNEL is not set, failing job"
Expand All @@ -38,6 +38,12 @@ import json
slack_bot_token = os.getenv('SLACK_BOT_TOKEN')
slack_channel = os.getenv('SLACK_CHANNEL')
baker_alias = os.getenv('BAKER_ALIAS')
exit_code = os.getenv('EXIT_CODE')
if exit_code == '9':
message = f'TRD returned exit code 9 (PROVIDER_BUSY) for Tezos baker {baker_alias}. This is a test alert.'
else:
message = f'TRD Payout failed for Tezos baker {baker_alias}'
response = requests.post(
'https://slack.com/api/chat.postMessage',
Expand All @@ -47,15 +53,15 @@ response = requests.post(
},
data=json.dumps({
'channel': slack_channel,
'text': f'TRD Payout failed for Tezos baker {baker_alias}'
'text': message
})
)
if not response.json().get('ok'):
print('Failed to send Slack alert')
print(response.json())
exit(1)
"
" EXIT_CODE=$exit_code
if [ $? -ne 0 ]; then
echo "Failed to send Slack alert"
exit 1
Expand Down

0 comments on commit d632ccb

Please sign in to comment.