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

Added heartbeat threshold, it's not reasonable to send heartbeat to server every second. #4058

Merged
merged 2 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"websocket_server": false,
"heartbeat_threshold": 10,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"heartbeat_threshold": 10,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"location": "SOME_LOCATION",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"encrypt_location": "",
"heartbeat_threshold": 10,
"tasks": [
{
"type": "HandleSoftBan"
Expand Down
9 changes: 8 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,14 @@ def _json_loader(filename):
type=float,
default=1
)

add_config(
parser,
load,
long_flag="--heartbeat_threshold",
help="A threshold between each heartbeat sending to server",
type=int,
default=10
)
# Start to parse other attrs
config = parser.parse_args()
if not config.username and 'username' not in load:
Expand Down
14 changes: 9 additions & 5 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __init__(self, config):
self.web_update_queue = Queue.Queue(maxsize=1)
self.web_update_thread = threading.Thread(target=self.update_web_location_worker)
self.web_update_thread.start()

self.heartbeat_threshold = self.config.heartbeat_threshold
self.heartbeat_counter = 0
def start(self):
self._setup_event_system()
self._setup_logging()
Expand Down Expand Up @@ -1008,10 +1009,13 @@ def heartbeat(self):
self.fort_timeouts = {id: timeout for id, timeout
in self.fort_timeouts.iteritems()
if timeout >= time.time() * 1000}
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.call()
self.heartbeat_counter = self.heartbeat_counter + 1
if self.heartbeat_counter >= self.heartbeat_threshold:
self.heartbeat_counter = 0
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.call()
try:
self.web_update_queue.put_nowait(True) # do this outside of thread every tick
except Queue.Full:
Expand Down