Skip to content

Commit a4ed0fe

Browse files
author
bdribault
committed
Abort when unable to start
1 parent 8746a28 commit a4ed0fe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import signal
44
import time
5+
import sys
56
from threading import Event
67

78
from prometheus_client import start_http_server
@@ -32,13 +33,20 @@ async def main():
3233
process = Process(config)
3334

3435
retry_time = 5
36+
retry_count = 0
3537
while not STOP_EVENT.is_set():
3638
try:
3739
now = time.time()
3840
await process.load(int(now))
3941
break
4042
except PrometheusException as exc:
4143
logger.error(exc)
44+
45+
retry_count += 1
46+
if retry_count > 5:
47+
logger.critical(f"Unable to initialize, aborting!")
48+
return 1
49+
4250
logger.error(f"Retrying in {retry_time} seconds...")
4351
await asyncio.sleep(retry_time)
4452
retry_time += 5
@@ -61,7 +69,10 @@ async def main():
6169
wait_time = REFRESH_INTERVAL - overshot
6270
time_target += REFRESH_INTERVAL
6371

72+
return 0
73+
6474

6575
if __name__ == "__main__":
6676
loop = asyncio.get_event_loop()
6777
res = loop.run_until_complete(main())
78+
sys.exit(res)

0 commit comments

Comments
 (0)