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

Run sync job in sync mode only.

parent 9099fda7
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ import connexion ...@@ -27,6 +27,7 @@ import connexion
from base.config import AuraConfig from base.config import AuraConfig
from base.logger import AuraLogger from base.logger import AuraLogger
from base.node import NodeType
from rest import encoder from rest import encoder
from service import ApiService from service import ApiService
from sync import SyncJob from sync import SyncJob
...@@ -76,10 +77,20 @@ with app.app_context(): ...@@ -76,10 +77,20 @@ with app.app_context():
Initialize Server. Initialize Server.
""" """
db.create_all() db.create_all()
service = ApiService(config, logger)
# Evaluate deployment mode
node_type = NodeType.MAIN
if config.get("host_id") == 0:
node_type = NodeType.SYNC
service = ApiService(config, logger, node_type)
app.config['SERVICE'] = service app.config['SERVICE'] = service
sync_job = SyncJob(config, logger, app)
sync_job.start() # Run sync job only in SYNC NODE mode
if node_type == NodeType.SYNC:
sync_job = SyncJob(config, logger, app)
sync_job.start()
atexit.register(shutdown) atexit.register(shutdown)
logger.info("Engine API server initialized.") logger.info("Engine API server initialized.")
......
#
# Aura Engine API (https://gitlab.servus.at/aura/engine-api)
#
# Copyright (C) 2020 - The Aura Engine Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from enum import Enum
from models import PlayLog, PlayLogSchema, TrackSchema, ActivityLog, HealthHistory, HealthHistorySchema
class NodeType(Enum):
"""
Types of API Server deployment models.
"""
MAIN = "main"
SYNC = "sync"
\ No newline at end of file
...@@ -18,22 +18,13 @@ ...@@ -18,22 +18,13 @@
import datetime import datetime
import requests
from enum import Enum from base.node import NodeType
from models import PlayLog, PlayLogSchema, TrackSchema, ActivityLog, HealthHistory, HealthHistorySchema from models import PlayLog, PlayLogSchema, TrackSchema, ActivityLog, HealthHistory, HealthHistorySchema
class NodeType(Enum):
"""
Types of API Server deployment models.
"""
MAIN = "main"
SYNC = "sync"
class ApiService(): class ApiService():
""" """
Service handling for API actions. Service handling for API actions.
...@@ -49,19 +40,13 @@ class ApiService(): ...@@ -49,19 +40,13 @@ class ApiService():
api_healthlog = None api_healthlog = None
def __init__(self, config, logger): def __init__(self, config, logger, node_type):
""" """
Initialize Service. Initialize Service.
""" """
self.config = config self.config = config
self.logger = logger self.logger = logger
# Evaluate deployment mode
node_type = NodeType.MAIN
host_id = config.get("host_id")
if host_id == 0:
node_type = NodeType.SYNC
# Configured as Sync Node # Configured as Sync Node
if not node_type == NodeType.MAIN: if not node_type == NodeType.MAIN:
self.node_type = NodeType.SYNC self.node_type = NodeType.SYNC
...@@ -181,7 +166,7 @@ class ApiService(): ...@@ -181,7 +166,7 @@ class ApiService():
else: else:
self.logger.error("Error while pushing playlog to sync-node: " + r.json()) self.logger.error("Error while pushing playlog to sync-node: " + 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'!\n%s" % (api_url, str(e)))
else: else:
self.logger.info("Ditching playlog sent from an inactive source") self.logger.info("Ditching playlog sent from an inactive source")
......
...@@ -161,7 +161,7 @@ class SyncJob(threading.Thread): ...@@ -161,7 +161,7 @@ class SyncJob(threading.Thread):
else: else:
self.logger.error("Invalid status code while getting unsynced entries from remote API: " + str(response.status_code)) self.logger.error("Invalid status code while getting unsynced entries from remote API: " + str(response.status_code))
except Exception as e: except Exception as e:
self.logger.error("Error while getting unsynced entries from remote API '%s'!" % (url), e) self.logger.error("Error while getting unsynced entries from remote API '%s'!\n%s" % (url, str(e)))
raise e raise e
......
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