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

Get Engine Status via API.

parent 036652af
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
import logging import logging
import os, os.path import os, os.path
import subprocess
import json
from datetime import datetime, date, timedelta from datetime import datetime, date, timedelta
...@@ -109,6 +111,7 @@ class EngineApi: ...@@ -109,6 +111,7 @@ class EngineApi:
spec.components.schema("Report", schema=ReportSchema) spec.components.schema("Report", schema=ReportSchema)
spec.components.schema("Schedule", schema=ScheduleSchema) spec.components.schema("Schedule", schema=ScheduleSchema)
spec.components.schema("Clock", schema=ClockDataSchema) spec.components.schema("Clock", schema=ClockDataSchema)
spec.components.schema("Status", schema=StatusSchema)
# TODO Generates HTML for specification # TODO Generates HTML for specification
#self.logger.info(spec.to_yaml()) #self.logger.info(spec.to_yaml())
...@@ -129,7 +132,7 @@ class EngineApi: ...@@ -129,7 +132,7 @@ class EngineApi:
self.api.add_resource(ReportResource, config.api_prefix + "/report/<string:year_month>") self.api.add_resource(ReportResource, config.api_prefix + "/report/<string:year_month>")
self.api.add_resource(UpcomingSchedulesResource, config.api_prefix + "/schedule/upcoming") self.api.add_resource(UpcomingSchedulesResource, config.api_prefix + "/schedule/upcoming")
self.api.add_resource(ClockDataResource, config.api_prefix + "/clock") self.api.add_resource(ClockDataResource, config.api_prefix + "/clock")
self.api.add_resource(ClockDataResource, config.api_prefix + "/status") self.api.add_resource(StatusResource, config.api_prefix + "/status")
self.logger.info("Engine API routes successfully set!") self.logger.info("Engine API routes successfully set!")
...@@ -283,8 +286,11 @@ class ReportSchema(ma.Schema): ...@@ -283,8 +286,11 @@ class ReportSchema(ma.Schema):
class StatusSchema(ma.Schema): class StatusSchema(ma.Schema):
class Meta: class Meta:
fields = ( fields = (
"is_liquidsoap_running", "engine",
"is_core_running" "soundsystem",
"api",
"redis_ready",
"audio_store"
) )
...@@ -420,12 +426,9 @@ class StatusResource(Resource): ...@@ -420,12 +426,9 @@ class StatusResource(Resource):
self.logger = logging.getLogger("engine-api") self.logger = logging.getLogger("engine-api")
def get(self): def get(self):
status = subprocess.check_output(["python3", "guru.py", "-s", "-q"])
# FIXME Not yet implemented! status = status.decode("utf-8").replace("'", '"')
status = json.loads(status, strict=False)
# #ss = SoundSystem(cr)
# return "check removed!" #ss.auraengine_state()
status = None
if not status: if not status:
return abort(204) # No content available return abort(204) # No content available
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
import sys import sys
import time import time
import json
import redis import redis
import logging import logging
import threading import threading
...@@ -159,7 +160,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger): ...@@ -159,7 +160,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
elif item["data"] == "get_status": elif item["data"] == "get_status":
def get_status_string(): def get_status_string():
status = self.soundsystem.monitoring.get_status() status = self.soundsystem.monitoring.get_status()
return str(status) return json.dumps(status)
self.execute(RedisChannel.GS_REPLY.value, get_status_string) self.execute(RedisChannel.GS_REPLY.value, get_status_string)
...@@ -186,6 +187,8 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger): ...@@ -186,6 +187,8 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
elif item["data"] == "recreate_db": elif item["data"] == "recreate_db":
self.execute(RedisChannel.RDB_REPLY.value, self.scheduler.recreate_database) self.execute(RedisChannel.RDB_REPLY.value, self.scheduler.recreate_database)
elif item["data"] == "status":
return True
else: else:
raise RedisConnectionException("ServerRedisAdapter Cannot understand command: " + item["data"]) raise RedisConnectionException("ServerRedisAdapter Cannot understand command: " + item["data"])
......
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