Skip to content

Commit

Permalink
fix after victor's comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Aug 29, 2024
1 parent 170e8e8 commit 0ca81da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions api/cron.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"jobs": [
{
"command": "30 * * * * TQDM_DISABLE=1 test $ENV = 'prod' && sh run_management_command.sh data-inclusion-api load_inclusion_data",
"command": "30 * * * * TQDM_DISABLE=1 test $ENV = 'prod' && sh execute_and_notify.sh data-inclusion-api load_inclusion_data",
"size": "XL"
},
{
"command": "30 * * * * TQDM_DISABLE=1 test $ENV != 'prod' && sh run_management_command.sh data-inclusion-api load_inclusion_data",
"command": "30 * * * * TQDM_DISABLE=1 test $ENV != 'prod' && data-inclusion-api load_inclusion_data",
"size": "S"
},
{
"command": "0 4 * * * sh run_management_command.sh vacuumdb --full --analyze --verbose --table api__structures --table api__services $DATABASE_URL",
"command": "0 4 * * * sh execute_and_notify.sh vacuumdb --full --analyze --verbose --table api__structures --table api__services $DATABASE_URL",
"size": "S"
}
]
Expand Down
7 changes: 3 additions & 4 deletions api/execute_and_notify.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# FIXME: Even with the right chmod in the dockerfile, the script is not executable. It works launching it with sh command thought.
set -u

"$@" &
Expand All @@ -7,10 +8,8 @@ wait $command_pid

exit_code=$?
if [ $exit_code -ne 0 ] && [ "$ENV" = "prod" ]; then
# Execute the curl command in case of an error
escaped_command="\`$@\`"
echo "Error with exit code \`$exit_code\` in command $escaped_command, sending message to Mattermost"
curl -i -X POST -H "Content-Type: application/json" -d "{\"text\": \"Error with exit code \`$exit_code\` in command $escaped_command: \nLogs: \`scalingo --region osc-secnum-fr1 --app data-inclusion-api-prod logs --lines 1000 -F $CONTAINER -f\`\"}" $MATTERMOST_HOOK
echo "Error with exit code \`$exit_code\` in command \`$*\`, sending message to Mattermost"
curl -i -X POST -H "Content-Type: application/json" -d "{\"text\": \"Error with exit code \`$exit_code\` in command \`$*\`: \nLogs: \`scalingo --region osc-secnum-fr1 --app data-inclusion-api-prod logs --lines 1000 -F $CONTAINER -f\`\"}" $MATTERMOST_HOOK
fi

exit $exit_code

0 comments on commit 0ca81da

Please sign in to comment.