Skip to content

Commit 42d0593

Browse files
committed
Split timeouts and adjust them
1 parent 0d4c460 commit 42d0593

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

debian/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
olimp-control (1.3-1) unstable; urgency=low
2+
3+
* Split timeouts into connection and read
4+
* Adjust the parameters
5+
6+
-- LMIO TC <lio-tech@googlegroups.com> Fri, 03 May 2024 14:23:00 +0000
7+
18
olimp-control (1.2-1) unstable; urgency=low
29

310
* Use session object with retry and shorter timeout

makedeb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# https://www.debian.org/doc/manuals/maint-guide/
77
# https://wiki.debian.org/Packaging
88

9-
ver='1.2'
9+
ver='1.3'
1010
projdir="olimp-control-${ver}"
1111
projtar="olimp-control_${ver}.orig.tar.gz"
1212
builddir="build"

olimp-control.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class LmioCtrlApi:
1616
_FAILED_AUTH = 'Response failed authentication validation'
1717
_NO_TICKETS = 'No tickets available'
1818

19-
def __init__(self, url, key, mid, timeout):
19+
def __init__(self, url, key, mid, connect_timeout, read_timeout):
2020
self._url = url
2121
self._key = key.encode('utf-8')
2222
self._mid = mid
23-
self._timeout = timeout if timeout > 0.0 else None
23+
self._timeout = (connect_timeout, read_timeout)
2424

2525
def _get_body_hmac(self, body):
2626
return hmac.HMAC(self._key, body, 'sha1').hexdigest()
@@ -52,7 +52,7 @@ def _validate_response(self, body, timestamp, headers):
5252

5353
def get_session(self):
5454
session = requests.Session()
55-
retry = requests.adapters.Retry(connect=5, backoff_factor=0.5)
55+
retry = requests.adapters.Retry(connect=5, backoff_factor=0.1)
5656
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
5757
session.mount('http://', adapter)
5858
session.mount('https://', adapter)
@@ -146,8 +146,8 @@ def get_machine_id():
146146
all_macs = subprocess.check_output("cat /sys/class/net/*/address | sort", shell=True)
147147
return hashlib.sha1(all_macs).hexdigest()
148148

149-
def main_loop(url, key, mid, poll_frequency, timeout, exit_event):
150-
api = LmioCtrlApi(url, key, mid, timeout)
149+
def main_loop(url, key, mid, poll_frequency, connect_timeout, read_timeout, exit_event):
150+
api = LmioCtrlApi(url, key, mid, connect_timeout, read_timeout)
151151
while True:
152152
session = api.get_session()
153153
api.do_ping(session)
@@ -166,18 +166,25 @@ def main_loop(url, key, mid, poll_frequency, timeout, exit_event):
166166
parser.add_argument('-f', '--poll-frequency', default=60.0, type=float,
167167
help='frequency of server check-in, in seconds')
168168
parser.add_argument('-k', '--key-file', default='/etc/olimp-control/key', help='path to key file')
169-
parser.add_argument('-t', '--timeout', default=20.0, type=float, help='timeout for API operations, in seconds')
169+
parser.add_argument('--connect-timeout', default=5.0, type=float, help='timeout for connections, in seconds')
170+
parser.add_argument('--read-timeout', default=20.0, type=float, help='timeout for read, in seconds')
170171
parser.add_argument('url', nargs='?', default='https://ctrl.lmio.lt/olimp/api',
171172
help='url of control api base')
172173

173174
args = parser.parse_args()
174175
if args.url[-1] == '/':
175176
args.url = args.url[:-1]
176177

178+
if args.connect_timeout <= 0.0:
179+
args.connect_timeout = None
180+
if args.read_timeout <= 0.0:
181+
args.read_timeout = None
182+
177183
shutdown_event = threading.Event()
178184
sigterm_handler = lambda sig, stack: shutdown_event.set()
179185

180186
signal.signal(signal.SIGINT, sigterm_handler)
181187
signal.signal(signal.SIGTERM, sigterm_handler)
182188

183-
main_loop(args.url, get_key(args.key_file), get_machine_id(), args.poll_frequency, args.timeout, shutdown_event)
189+
main_loop(args.url, get_key(args.key_file), get_machine_id(), args.poll_frequency, args.connect_timeout,
190+
args.read_timeout, shutdown_event)

0 commit comments

Comments
 (0)