Skip to content
Snippets Groups Projects
Commit 38590ddd authored by David Trattnig's avatar David Trattnig
Browse files

Gracefull handle duplicate playlog entries.

parent 798f8cd3
No related branches found
No related tags found
No related merge requests found
...@@ -147,9 +147,12 @@ class ApiService(): ...@@ -147,9 +147,12 @@ class ApiService():
if self.node_type == NodeType.MAIN or \ if self.node_type == NodeType.MAIN or \
(self.node_type == NodeType.SYNC and data.log_source == self.active_source): (self.node_type == NodeType.SYNC and data.log_source == self.active_source):
playlog = PlayLog(data) try:
playlog.save() playlog = PlayLog(data)
self.logger.debug("Stored playlog for '%s'" % playlog.track_start) playlog.save()
self.logger.debug("Stored playlog for '%s'" % playlog.track_start)
except sqlalchemy.exc.IntegrityError as e:
self.logger.info("Playlog for '%s' is already existing in local database. Skipping..." % playlog.track_start)
# Main Node: Push to Sync Node, if enabled # Main Node: Push to Sync Node, if enabled
if self.node_type == NodeType.MAIN and self.sync_host and self.api_playlog: if self.node_type == NodeType.MAIN and self.sync_host and self.api_playlog:
...@@ -164,7 +167,7 @@ class ApiService(): ...@@ -164,7 +167,7 @@ class ApiService():
playlog.is_synced = True playlog.is_synced = True
playlog.save() playlog.save()
else: else:
self.logger.error("Error while pushing playlog to sync-node: " + r.json()) self.logger.error("Error while pushing playlog to sync-node: " + str(r.json()))
except Exception as e: except Exception as e:
self.logger.error("Error while posting to sync-node API '%s'!\n%s" % (api_url, str(e))) self.logger.error("Error while posting to sync-node API '%s'!\n%s" % (api_url, str(e)))
else: else:
...@@ -253,7 +256,7 @@ class ApiService(): ...@@ -253,7 +256,7 @@ class ApiService():
playlog.is_synced = True playlog.is_synced = True
playlog.save() playlog.save()
else: else:
self.logger.error("Error while pushing healthlog to sync-node: " + r.json()) self.logger.error("Error while pushing healthlog to sync-node: " + str(r.json()))
except Exception as e: except Exception as e:
self.logger.error("Error while posting to sync-node API '%s'!" % (api_url), e) self.logger.error("Error while posting to sync-node API '%s'!" % (api_url), e)
else: else:
......
...@@ -105,13 +105,16 @@ class SyncJob(threading.Thread): ...@@ -105,13 +105,16 @@ class SyncJob(threading.Thread):
# Store unsynced entries locally # Store unsynced entries locally
for entry in entries: for entry in entries:
playlog = PlayLog(entry)
self.Session.add(playlog)
self.Session.commit()
self.logger.info("Stored synced playlog for '%s'" % playlog.track_start) try:
synced_entries += 1 playlog = PlayLog(entry)
self.Session.add(playlog)
self.Session.commit()
self.logger.info("Stored synced playlog for '%s'" % playlog.track_start)
synced_entries += 1
except sqlalchemy.exc.IntegrityError as e:
self.logger.info("Playlog for '%s' is already existing in local database. Skipping..." % playlog.track_start)
# Sleep a little to keep the effective load down low # Sleep a little to keep the effective load down low
time.sleep(self.config.get("sync_step_sleep")) time.sleep(self.config.get("sync_step_sleep"))
...@@ -152,7 +155,7 @@ class SyncJob(threading.Thread): ...@@ -152,7 +155,7 @@ class SyncJob(threading.Thread):
to_time = next_source.log_time to_time = next_source.log_time
try: try:
params = { "page": "0", "limit": self.sync_batch_size, "skip_synced": "true", "from": source.log_time, "to": to_time} params = { "page": "0", "limit": self.sync_batch_size, "skip_synced": "true", "from_date": source.log_time, "to_date": to_time}
url = self.get_url(source.source_number) url = self.get_url(source.source_number)
response = requests.get(url, params=params) response = requests.get(url, params=params)
if response.status_code == 200: if response.status_code == 200:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment