Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Aug 28, 2024
1 parent 78a7747 commit 9e6d584
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ RUN apt-get update \
RUN python -m venv ${VIRTUAL_ENV}

COPY requirements requirements
COPY test.py test.py
COPY run_management_command.sh run_management_command.sh
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
RUN pip install --no-cache-dir -r requirements/test-requirements.txt

Expand Down Expand Up @@ -65,6 +67,7 @@ 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 src /srv/src
COPY --chown=gunicorn:gunicorn tests /srv/tests

RUN chmod +x docker-entrypoint.sh

USER gunicorn
Expand Down
24 changes: 24 additions & 0 deletions api/run_management_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
set -u

# Execute the command and capture standard output and error output
"$@" &
command_pid=$! # Capture the PID of the previous command

wait $command_pid

exit_code=$? # Capture the exit code of the previous command


# Print the exit code of the Python script
echo "The exit code of the command is: $exit_code and pid = $command_pid"

# Check if the exit code indicates an error (not equal to 0)
if [ $exit_code -ne 0 ] && [ "$ENV" = "staging" ]; then
# Execute the wget command in case of an error
echo "Error detected, sending a message to mattermost"
curl -i -X POST -H "Content-Type: application/json" -d "{\"text\": \"[TEST] Error cron api detected, check out logs with the following command: \`scalingo --region osc-secnum-fr1 --app data-inclusion-api-prod logs --lines 1000 -F one-off-$command_pid -f\`\"}" $MATTERMOST_HOOK
fi

# Return the exit code of the initial command
exit $exit_code
21 changes: 21 additions & 0 deletions api/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys


def main():
if len(sys.argv) != 2:
print("Usage: python script.py <0|1>")
sys.exit(1)

arg = sys.argv[1]

if arg == "1":
raise ValueError("An error occurred because the argument is 1")
elif arg == "0":
pass
else:
print("Invalid argument. Please use 0 or 1.")
sys.exit(1)


if __name__ == "__main__":
main()

0 comments on commit 9e6d584

Please sign in to comment.