Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat decoupled from tasks. #5243

Merged
merged 10 commits into from
Sep 7, 2016
6 changes: 5 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(self, db, config):
self.heartbeat_threshold = self.config.heartbeat_threshold
self.heartbeat_counter = 0
self.last_heartbeat = time.time()
self.hb_locked = False # lock hb on snip

self.capture_locked = False # lock catching while moving to VIP pokemon

Expand Down Expand Up @@ -919,6 +920,7 @@ def login(self):
level='info',
formatted="Login successful."
)
self.heartbeat()

def get_encryption_lib(self):
if _platform == "Windows" or _platform == "win32":
Expand Down Expand Up @@ -1263,7 +1265,7 @@ def heartbeat(self):
in self.fort_timeouts.iteritems()
if timeout >= now * 1000}

if now - self.last_heartbeat >= self.heartbeat_threshold:
if now - self.last_heartbeat >= self.heartbeat_threshold and not self.hb_locked:
self.last_heartbeat = now
request = self.api.create_request()
request.get_player()
Expand Down Expand Up @@ -1307,6 +1309,8 @@ def heartbeat(self):
except Queue.Full:
pass

threading.Timer(self.heartbeat_threshold, self.heartbeat).start()

def update_web_location_worker(self):
while True:
self.web_update_queue.get()
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ def snipe(self, pokemon):
pokemon: Pokemon to snipe.
"""
last_position = self.bot.position[0:2]
self.bot.heartbeat()
self.bot.hb_locked = True
self._teleport_to(pokemon)
catch_worker = PokemonCatchWorker(pokemon, self.bot, self.config)
api_encounter_response = catch_worker.create_encounter_api_call()
time.sleep(self.config.get('snipe_sleep_sec', 2))
self._teleport_back(last_position)
self.bot.api.set_position(last_position[0], last_position[1], self.alt, False)
time.sleep(self.config.get('snipe_sleep_sec', 2))
self.bot.heartbeat()
self.bot.hb_locked = False
catch_worker.work(api_encounter_response)
self.add_caught(pokemon)
return WorkerResult.SUCCESS
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/random_alive_pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def _sleep(self):
self._last_call = now
return False

self.bot.heartbeat()
if self.bot.config.replicate_gps_xy_noise or self.bot.config.replicate_gps_z_noise: # Adding some noise
lat, lng, alt = self.bot.api.get_position()
self.bot.api.set_position(lat, lng, alt) # Just set the same _actual_ values. set_position will add noise itself
Expand Down
2 changes: 0 additions & 2 deletions pokemongo_bot/walkers/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def step(self):
'distance_unit': ''
}
)
self.bot.heartbeat()
# This step is implicitlly teleporting...
# and since now we have variable speeds it can be quite often that self.dist < self.speed
# especially for the polyline
Expand All @@ -95,7 +94,6 @@ def step(self):
'distance_unit': ''
}
)
self.bot.heartbeat()

sleep(1) # sleep one second plus a random delta
# self._work_at_position(
Expand Down