-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |