Skip to content
Snippets Groups Projects
Commit dd5b76fc authored by Ben Morrice's avatar Ben Morrice
Browse files

Add logic to fail script if it's taking too long

parent bb3c34e4
No related branches found
No related tags found
No related merge requests found
Pipeline #6382707 passed
......@@ -5,9 +5,11 @@ import glob
import html
import json
import re
import signal
import subprocess
import sys
import tempfile
import time
from collections import ChainMap
from datetime import datetime
import dnf
......@@ -157,7 +159,13 @@ def get_upstream(token, feed):
offset = 0
packages = []
while True:
result = call_api(token, url, params={"limit": 100, "offset": offset})
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(30)
try:
result = call_api(token, url, params={"limit": 100, "offset": offset})
except TimeoutError:
print(f"Timeout occurred whilst trying to process {feed} with offset {offset}")
continue
try:
j = json.loads(result.content)
except json.decoder.JSONDecodeError:
......@@ -258,6 +266,10 @@ def format_release(p, f, token):
)
print(f" -- Payload sent: {payload}", flush=True)
def timeout_handler(num, stack):
""" function to handle timeouts for long running function """
print("Received SIGALRM")
raise TimeoutError
if __name__ == "__main__":
"""this is the main class, it's amazing."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment