@@ -16,11 +16,11 @@ class LmioCtrlApi:
16
16
_FAILED_AUTH = 'Response failed authentication validation'
17
17
_NO_TICKETS = 'No tickets available'
18
18
19
- def __init__ (self , url , key , mid , timeout ):
19
+ def __init__ (self , url , key , mid , connect_timeout , read_timeout ):
20
20
self ._url = url
21
21
self ._key = key .encode ('utf-8' )
22
22
self ._mid = mid
23
- self ._timeout = timeout if timeout > 0.0 else None
23
+ self ._timeout = ( connect_timeout , read_timeout )
24
24
25
25
def _get_body_hmac (self , body ):
26
26
return hmac .HMAC (self ._key , body , 'sha1' ).hexdigest ()
@@ -52,7 +52,7 @@ def _validate_response(self, body, timestamp, headers):
52
52
53
53
def get_session (self ):
54
54
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 )
56
56
adapter = requests .adapters .HTTPAdapter (max_retries = retry )
57
57
session .mount ('http://' , adapter )
58
58
session .mount ('https://' , adapter )
@@ -146,8 +146,8 @@ def get_machine_id():
146
146
all_macs = subprocess .check_output ("cat /sys/class/net/*/address | sort" , shell = True )
147
147
return hashlib .sha1 (all_macs ).hexdigest ()
148
148
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 )
151
151
while True :
152
152
session = api .get_session ()
153
153
api .do_ping (session )
@@ -166,18 +166,25 @@ def main_loop(url, key, mid, poll_frequency, timeout, exit_event):
166
166
parser .add_argument ('-f' , '--poll-frequency' , default = 60.0 , type = float ,
167
167
help = 'frequency of server check-in, in seconds' )
168
168
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' )
170
171
parser .add_argument ('url' , nargs = '?' , default = 'https://ctrl.lmio.lt/olimp/api' ,
171
172
help = 'url of control api base' )
172
173
173
174
args = parser .parse_args ()
174
175
if args .url [- 1 ] == '/' :
175
176
args .url = args .url [:- 1 ]
176
177
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
+
177
183
shutdown_event = threading .Event ()
178
184
sigterm_handler = lambda sig , stack : shutdown_event .set ()
179
185
180
186
signal .signal (signal .SIGINT , sigterm_handler )
181
187
signal .signal (signal .SIGTERM , sigterm_handler )
182
188
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