craftbeerpi4-pione/core/controller/system_controller.py

34 lines
1.1 KiB
Python
Raw Normal View History

2018-11-01 19:50:04 +01:00
from aiohttp import web
from aiojobs.aiohttp import get_scheduler_from_app
from core.api.decorator import request_mapping
class SystemController():
2018-11-01 21:25:42 +01:00
def __init__(self, cbpi):
self.cbpi = cbpi
self.service = cbpi.actor
self.cbpi.register(self, "/system")
2018-11-01 19:50:04 +01:00
2018-11-04 01:55:54 +01:00
@request_mapping("/restart", method="POST", name="RestartServer", auth_required=False)
def restart(self, request):
# TODO implement restart
return web.Response(text="NOT IMPLEMENTED")
@request_mapping("/shutdown", method="POST", name="ShutdownSerer", auth_required=False)
def restart(self, request):
# TODO implement restart
return web.Response(text="NOT IMPLEMENTED")
@request_mapping("/jobs", method="GET", name="get_jobs", auth_required=False)
2018-11-01 19:50:04 +01:00
def get_all_jobs(self, request):
2018-11-01 21:25:42 +01:00
scheduler = get_scheduler_from_app(self.cbpi.app)
2018-11-18 15:40:10 +01:00
result = []
2018-11-01 19:50:04 +01:00
for j in scheduler:
2018-11-18 15:40:10 +01:00
try:
result.append(dict(name=j.name, type=j.type, time=j.start_time))
except:
pass
2018-11-01 19:50:04 +01:00
# await j.close()
2018-11-18 15:40:10 +01:00
return web.json_response(data=result)