Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Commit bda044b

Browse files
author
memelyfe
committed
[simulation] handle exception in heartbeat
1 parent 14c8422 commit bda044b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ def heartbeat(api_endpoint, access_token, response):
229229
heartbeat.ParseFromString(payload)
230230
return heartbeat
231231

232+
def safe_heartbeat(api_endpoint, access_token, response):
233+
h = None
234+
while h is None:
235+
try:
236+
h = heartbeat(api_endpoint, access_token, response)
237+
except:
238+
print('[-] Missed a heartbeat')
239+
time.sleep(1)
240+
continue
241+
return h
242+
243+
232244
def main():
233245
pokemons = json.load(open('pokemon.json'))
234246
parser = argparse.ArgumentParser()
@@ -283,13 +295,13 @@ def main():
283295
original_long = FLOAT_LONG
284296
parent = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)).parent(15)
285297

286-
h = heartbeat(api_endpoint, access_token, response)
298+
h = safe_heartbeat(api_endpoint, access_token, response)
287299
hs = [h]
288300
seen = set([])
289301
for child in parent.children():
290302
latlng = LatLng.from_point(Cell(child).get_center())
291303
set_location_coords(latlng.lat().degrees, latlng.lng().degrees, 0)
292-
hs.append(heartbeat(api_endpoint, access_token, response))
304+
hs.append(safe_heartbeat(api_endpoint, access_token, response))
293305
set_location_coords(original_lat, original_long, 0)
294306

295307
visible = []

0 commit comments

Comments
 (0)