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

Store sync state for playlogs.

parent 25b2bf79
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,7 @@ class PlayLog(db.Model):
timeslot_id = Column(Integer)
show_name = Column(String(256))
log_source = Column(Integer)
is_synced = Column(Boolean)
......@@ -62,7 +63,8 @@ class PlayLog(db.Model):
self.track_type = data.track_type
self.timeslot_id = data.timeslot_id
self.show_name = data.show_name
self.log_source = data.log_source
self.log_source = data.log_source # The play-out source this log is coming from (e.g. engine1, engine2)
self.is_synced = False # Only relevant for main nodes, in a multi-node setup
def save(self):
......@@ -177,6 +179,7 @@ class TrackSchema(ma.SQLAlchemySchema):
class ActivityLog(db.Model):
"""
Table holding a log of play-out source active and sync states.
Only used in "SYNC" deployment mode.
"""
__tablename__ = 'activity_log'
......@@ -218,7 +221,7 @@ class HealthHistory(db.Model):
health_info = Column(String(2048))
def __init__(self, data):
def __init__(self, source_number):
"""
Initializes an health entry.
"""
......
......@@ -139,24 +139,26 @@ class ApiService():
playlog = PlayLog(data)
playlog.save()
self.logger.info("Stored playlog for '%s'" % playlog.track_start)
self.logger.debug("Stored playlog for '%s'" % playlog.track_start)
# Push to sync node if configured
if self.sync_host:
# Main Node: Push to Sync Node, if enabled
if self.node_type = NodeType.MAIN and self.sync_host:
playlog_schema = PlayLogSchema()
json_playlog = playlog_schema.dump(playlog)
try:
api_url = self.sync_host + self.config.get("sync_api_store_playlog")
r = requests.post(api_url, json=json_playlog)
if r.status_code == 200:
self.logger.info("Successfully pushed playlog for '%s' to '%s'" % (playlog.track_start, self.sync_host))
playlog.is_synced = True
playlog.save()
else:
self.logger.error("Error while pushing playlog to sync-node: " + r.json())
except Exception as e:
self.logger.error("Error while posting to sync-node API '%s'!" % (api_url), e)
def clock_info(self):
"""
Retrieves the currently playing playlist.
......
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