forked from DGNum/stateless-uptime-kuma
Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
d378d1ce00 | |||
|
7dcf83dc4a |
1 changed files with 18 additions and 1 deletions
|
@ -1,9 +1,11 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import click_log
|
import click_log
|
||||||
|
import uptime_kuma_api
|
||||||
from uptime_kuma_api import UptimeKumaApi
|
from uptime_kuma_api import UptimeKumaApi
|
||||||
|
|
||||||
from .hydratation import hydrate_http_probes
|
from .hydratation import hydrate_http_probes
|
||||||
|
@ -14,6 +16,20 @@ logger = logging.getLogger(__name__)
|
||||||
click_log.basic_config()
|
click_log.basic_config()
|
||||||
|
|
||||||
|
|
||||||
|
def get_api_with_retries(host, retries=5):
|
||||||
|
delay = 5
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
return UptimeKumaApi(host)
|
||||||
|
except uptime_kuma_api.exceptions.UptimeKumaException:
|
||||||
|
logger.warn(f"Error while connectiong, retrying in {delay}s.")
|
||||||
|
if retries == 0:
|
||||||
|
raise
|
||||||
|
retries -= 1
|
||||||
|
time.sleep(delay)
|
||||||
|
delay *= 4
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
|
@ -76,7 +92,8 @@ def apply_json(
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Flags value:\n - scrape_http_keywords: {scrape_http_keywords}\n - no_autocreate_tags: {no_autocreate_tags}\n - keywords_fallback: {keywords_fallback}"
|
f"Flags value:\n - scrape_http_keywords: {scrape_http_keywords}\n - no_autocreate_tags: {no_autocreate_tags}\n - keywords_fallback: {keywords_fallback}"
|
||||||
)
|
)
|
||||||
with UptimeKumaApi(host) as api:
|
|
||||||
|
with get_api_with_retries(host) as api:
|
||||||
logging.debug("Reading json")
|
logging.debug("Reading json")
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
logging.debug("Parsing json")
|
logging.debug("Parsing json")
|
||||||
|
|
Loading…
Reference in a new issue