File: _install_wait.py

package info (click to toggle)
nc-py-api 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,320 kB
  • sloc: python: 12,415; makefile: 238; xml: 100; javascript: 56; sh: 14
file content (23 lines) | stat: -rw-r--r-- 663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import re
from sys import argv
from time import sleep

from requests import get


def check_heartbeat(url: str, regexp: str, n_tries: int, wait_interval: float) -> int:
    for _ in range(n_tries):
        try:
            result = get(url)
            if result.text and re.search(regexp, result.text, re.IGNORECASE) is not None:
                return 0
        except Exception as _:
            _ = _
        sleep(wait_interval)
    return 2


# params: app heartbeat url, string to check, number of tries, time to sleep between retries
if __name__ == "__main__":
    r = check_heartbeat(str(argv[1]), str(argv[2]), int(argv[3]), float(argv[4]))
    exit(r)