Skip to content

Commit

Permalink
Adding a heartbeat to the analytics (#2709)
Browse files Browse the repository at this point in the history
* Adding a heartbeat to the analytics

* Heartbeat every 30 seconds, not every 5
  • Loading branch information
elicwhite authored Aug 7, 2016
1 parent f114be6 commit 0b319bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def main():
tree = TreeConfigBuilder(bot, config.raw_tasks).build()
bot.workers = tree
bot.metrics.capture_stats()
bot.health_record = health_record

bot.event_manager.emit(
'bot_start',
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _register_events(self):
self.event_manager.register_event('unset_pokemon_nickname')

def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()
self.tick_count += 1

Expand Down
10 changes: 10 additions & 0 deletions pokemongo_bot/health_record/bot_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import uuid
import requests
import time

class BotEvent(object):
def __init__(self, config):
Expand All @@ -30,13 +31,16 @@ def __init__(self, config):
logging = False,
context = {}
)
self.heartbeat_wait = 30 # seconds
self.last_heartbeat = time.time()

def capture_error(self):
if self.config.health_record:
self.client.captureException()

def login_success(self):
if self.config.health_record:
self.last_heartbeat = time.time()
track_url('/loggedin')

def login_failed(self):
Expand All @@ -51,6 +55,12 @@ def logout(self):
if self.config.health_record:
track_url('/logout')

def heartbeat(self):
if self.config.health_record:
current_time = time.time()
if current_time - self.heartbeat_wait > self.last_heartbeat:
self.last_heartbeat = current_time
track_url('/heartbeat')

def track_url(path):
data = {
Expand Down

0 comments on commit 0b319bc

Please sign in to comment.