Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(alerts): add alert on mattermost in case of cron failure #280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ RUN useradd --no-log-init -g gunicorn gunicorn
# Copy venv with compiled dependencies
COPY --chown=gunicorn:gunicorn --from=compile-image /srv/venv /srv/venv

COPY --chown=gunicorn:gunicorn ["docker-entrypoint.sh", "pyproject.toml", "alembic.ini", "/srv/"]
COPY --chown=gunicorn:gunicorn ["execute_and_notify.sh", "docker-entrypoint.sh", "pyproject.toml", "alembic.ini", "/srv/"]
COPY --chown=gunicorn:gunicorn src /srv/src
COPY --chown=gunicorn:gunicorn tests /srv/tests


RUN chmod +x docker-entrypoint.sh
RUN chmod +x execute_and_notify.sh

USER gunicorn
EXPOSE 8000
Expand Down
4 changes: 2 additions & 2 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' && data-inclusion-api load_inclusion_data",
"command": "30 * * * * TQDM_DISABLE=1 test $ENV = 'prod' && ./execute_and_notify.sh data-inclusion-api load_inclusion_data",
"size": "XL"
},
{
"command": "30 * * * * TQDM_DISABLE=1 test $ENV != 'prod' && data-inclusion-api load_inclusion_data",
"size": "S"
},
{
"command": "0 4 * * * vacuumdb --full --analyze --verbose --table api__structures --table api__services $DATABASE_URL",
"command": "0 4 * * * ./execute_and_notify.sh vacuumdb --full --analyze --verbose --table api__structures --table api__services $DATABASE_URL",
"size": "S"
}
]
Expand Down
14 changes: 14 additions & 0 deletions api/execute_and_notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -u

"$@" &
command_pid=$!
wait $command_pid

exit_code=$?
if [ $exit_code -ne 0 ] && [ "$ENV" = "prod" ]; then
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
Loading