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

Settings for deployment mode.

parent 85872d54
No related branches found
No related tags found
No related merge requests found
......@@ -20,3 +20,21 @@ debug_flask="false"
[api]
api_port=8008
[federation]
# Engine API supports two deployment models:
#
# - "main": Deployed together with some `engine` (Single instance or for redundant engines)
# - "sync": Independent deployment, in charge of syncing data of two main-nodes
#
# The `synch_host` identifies the host where data is gathered from/synced to, depended on the
# chosen `node_type`.
#
node_type="main"
sync_host="http://localhost:8010"
; node_type="sync"
; main_host_1="http://localhost:8008"
; main_host_2="http://localhost:8009"
......@@ -19,9 +19,18 @@
import datetime
from enum import Enum
from models import PlayLog, TrackSchema
class NodeType(Enum):
"""
Types of API Server deployment models.
"""
MAIN = "main"
SYNC = "sync"
class ApiService():
"""
......@@ -30,12 +39,35 @@ class ApiService():
config = None
logger = None
node_type = None
sync_host = None
main_hosts = None
def __init__(self, config, logger):
"""
Initialize Service.
"""
self.config = config
self.logger = logger
# Evaluate deployment mode
node_type = config.get("node_type")
if not node_type == NodeType.MAIN.value:
self.node_type = NodeType.SYNC
self.main_hosts = [ config.get("main_host_1"), config.get("main_host_2") ]
self.logger.info("Running in 'SYNC' mode. Syncing data of '%s'" % (self.main_hosts))
else:
self.node_type = NodeType.MAIN
# Validate sync host
self.sync_host = config.get("sync_host")
if not self.sync_host:
raise ValueError("Invalid sync_host '%s'!" % self.sync_host)
self.logger.info("Running in 'MAIN' mode. Pushing data to '%s'" % (self.sync_host))
def current_track(self):
"""
......@@ -71,9 +103,9 @@ class ApiService():
Get paginated playlog entries for since the given timestamp.
Args:
since_time (datetime): Get entries after this timestamp (e.g. '2020-08-29T09:12:33.001Z')
page (Integer): The number of items to skip before starting to collect the result set
size (Integer): The numbers of items to return per page
since_time (datetime): Optionally, get entries after this timestamp (e.g. "2020-08-29T09:12:33.001Z")
Returns:
(List[PlayLogEntry])
......
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