Skip to content

Commit

Permalink
#39: Added appVersion arg
Browse files Browse the repository at this point in the history
  • Loading branch information
vlkv committed May 26, 2013
1 parent 9d80565 commit 00a1f35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 13 additions & 1 deletion reggata-stats/main.py
Expand Up @@ -6,12 +6,14 @@

class Event(ndb.Model):
appInstanceId = ndb.StringProperty(indexed=True)
appVersion = ndb.StringProperty(indexed=True)
name = ndb.StringProperty(indexed=True)
dateCreated = ndb.DateTimeProperty(auto_now_add=True)


class AppInstance(ndb.Model):
id = ndb.StringProperty(indexed=True)
appVersion = ndb.StringProperty(indexed=True)
dateCreated = ndb.DateTimeProperty(auto_now_add=True)


Expand All @@ -24,8 +26,13 @@ def get(self):

class RegisterApp(webapp2.RequestHandler):
def get(self):
appVersion = self.request.get("app_version", None)
if appVersion is None:
self.response.write("app_version argument is missing")
return
ai = AppInstance()
ai.id = str(uuid4())
ai.appVersion = appVersion
ai.put()
self.response.headers['Content-Type'] = 'text/plain'
self.response.write(ai.id)
Expand All @@ -34,23 +41,28 @@ def get(self):
class PutEvent(webapp2.RequestHandler):
def get(self):
appInstanceId = self.request.get("app_instance_id", None)
appVersion = self.request.get("app_version", None)
name = self.request.get("name", None)

self.response.headers['Content-Type'] = 'text/plain'
if appInstanceId is None:
self.response.write("app_instance_id argument is missing")
return
if appVersion is None:
self.response.write("app_version argument is missing")
return
if name is None:
self.response.write("name argument is missing")
return
appInstances = AppInstance.query(AppInstance.id == appInstanceId).fetch()
if len(appInstances) == 0:
self.response.write("app_instance_id is not found in database. Application instance is not registered")
self.response.write("app_instance_id='" + appInstanceId + "' is not found in database. Application instance is not registered")
return
appInstanceId = appInstances[0].id

e = Event()
e.appInstanceId = appInstanceId
e.appVersion = appVersion
e.name = name
e.put()
self.response.write("ok")
Expand Down
2 changes: 2 additions & 0 deletions reggata/main.py
Expand Up @@ -34,6 +34,7 @@
import reggata.logging_default_conf as logging_default_conf
from reggata.gui.main_window import MainWindow
from gui.user_dialogs_facade import UserDialogsFacade
import time


logger = logging.getLogger(consts.ROOT_LOGGER + "." + __name__)
Expand Down Expand Up @@ -116,6 +117,7 @@ def main():

if stats.isSendStatisticsAllowed() and not stats.isReggataInstanceRegistered():
stats.registerReggataInstance()
time.sleep(1)

stats.sendEvent("reggata_started")

Expand Down
9 changes: 5 additions & 4 deletions reggata/statistics.py
Expand Up @@ -9,6 +9,7 @@
from reggata import consts
import logging
import re
import reggata


logger = logging.getLogger(consts.ROOT_LOGGER + "." + __name__)
Expand All @@ -26,7 +27,8 @@ def isReggataInstanceRegistered():
def registerReggataInstance():
try:
timeoutSec = 5
with urllib.request.urlopen(consts.STATISTICS_SERVER + "/register_app", None, timeoutSec) as f:
with urllib.request.urlopen(consts.STATISTICS_SERVER + "/register_app?app_version={}"
.format(reggata.__version__), None, timeoutSec) as f:
response = f.read()
instanceId = response.decode("utf-8")
mobj = re.match(r"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", instanceId)
Expand Down Expand Up @@ -55,9 +57,8 @@ def isSendStatisticsAllowed():
def _sendEvent(instanceId, name):
print("_sendEvent started")
timeoutSec = 5
with urllib.request.urlopen(consts.STATISTICS_SERVER + "/put_event?app_instance_id={}&name={}"
.format(instanceId, name),
None, timeoutSec) as f:
with urllib.request.urlopen(consts.STATISTICS_SERVER + "/put_event?app_instance_id={}&name={}&app_version={}"
.format(instanceId, name, reggata.__version__), None, timeoutSec) as f:
response = f.read()
# TODO: remove this print call
print(str(response))
Expand Down

0 comments on commit 00a1f35

Please sign in to comment.