@@ -205,22 +205,23 @@ def fetch_job_configs(self, protocol):
205
205
to do their job.
206
206
"""
207
207
# find all the accounts we have access to:
208
- r = requests .get ('{}/accounts/?b={}' .format (self .backend_url , self .bot_token ))
208
+ requests_session = requests .Session ()
209
+ r = requests_session .get ('{}/accounts/?b={}' .format (self .backend_url , self .bot_token ))
209
210
if r .status_code != 200 :
210
211
raise Exception ("Invalid bot token or network error, got status {} while retrieving {}/accounts" .format (r .status_code , self .backend_url ))
211
212
j = r .json ()
212
213
accounts_ids = [a ["id" ] for a in j ["list" ]]
213
214
214
215
# find all entities for each of the accounts:
215
216
for account_id in accounts_ids :
216
- r = requests .get ('{}/accounts/{}/entities/?b={}' .format (self .backend_url , account_id , self .bot_token ))
217
+ r = requests_session .get ('{}/accounts/{}/entities/?b={}' .format (self .backend_url , account_id , self .bot_token ))
217
218
if r .status_code != 200 :
218
219
raise Exception ("Network error, got status {} while retrieving {}/accounts/{}/entities" .format (r .status_code , self .backend_url , account_id ))
219
220
j = r .json ()
220
221
entities_ids = [e ["id" ] for e in j ["list" ]]
221
222
222
223
for entity_id in entities_ids :
223
- r = requests .get ('{}/accounts/{}/entities/{}?b={}' .format (self .backend_url , account_id , entity_id , self .bot_token ))
224
+ r = requests_session .get ('{}/accounts/{}/entities/{}?b={}' .format (self .backend_url , account_id , entity_id , self .bot_token ))
224
225
if r .status_code != 200 :
225
226
raise Exception ("Network error, got status {} while retrieving {}/accounts/{}/entities/{}" .format (r .status_code , self .backend_url , account_id , entity_id ))
226
227
entity_info = r .json ()
@@ -236,7 +237,7 @@ def fetch_job_configs(self, protocol):
236
237
if not entity_info ["protocols" ][protocol ]["sensors" ]:
237
238
continue
238
239
239
- r = requests .get ('{}/accounts/{}/credentials/{}?b={}' .format (self .backend_url , account_id , credential_id , self .bot_token ))
240
+ r = requests_session .get ('{}/accounts/{}/credentials/{}?b={}' .format (self .backend_url , account_id , credential_id , self .bot_token ))
240
241
if r .status_code != 200 :
241
242
raise Exception ("Network error, got status {} while retrieving {}/accounts/{}/credentials/{}" .format (r .status_code , self .backend_url , account_id , credential_id ))
242
243
credential = r .json ()
@@ -245,7 +246,7 @@ def fetch_job_configs(self, protocol):
245
246
sensors = []
246
247
for sensor_info in entity_info ["protocols" ][protocol ]["sensors" ]:
247
248
sensor_id = sensor_info ["sensor" ]
248
- r = requests .get ('{}/accounts/{}/sensors/{}?b={}' .format (self .backend_url , account_id , sensor_id , self .bot_token ))
249
+ r = requests_session .get ('{}/accounts/{}/sensors/{}?b={}' .format (self .backend_url , account_id , sensor_id , self .bot_token ))
249
250
if r .status_code != 200 :
250
251
raise Exception ("Network error, got status {} while retrieving {}/accounts/{}/sensors/{}" .format (r .status_code , self .backend_url , account_id , sensor ["sensor" ]))
251
252
sensor = r .json ()
@@ -275,6 +276,8 @@ def fetch_job_configs(self, protocol):
275
276
276
277
yield entity_info
277
278
279
+ requests_session .close ()
280
+
278
281
def refresh_jobs (self ):
279
282
wanted_jobs = set ()
280
283
for job_id , intervals , job_func , job_data in self .jobs ():
0 commit comments