def get_schedule(request):
"""
Return the information for the given schedule from schedules table
:Example: curl -X GET http://localhost:8082/foglamp/schedule/ac6dd55d-f55d-44f7-8741-984604bf2384
"""
try:
schedule_id = request.match_info.get('schedule_id', None)
if not schedule_id:
raise web.HTTPBadRequest(reason='Schedule ID is required.')
try:
assert uuid.UUID(schedule_id)
except ValueError as ex:
raise web.HTTPNotFound(reason="Invalid Schedule ID {}".format(schedule_id))
sch = await server.Server.scheduler.get_schedule(uuid.UUID(schedule_id))
schedule = {
'id': str(sch.schedule_id),
'name': sch.name,
'process_name': sch.process_name,
'type': Schedule.Type(int(sch.schedule_type)).name,
'repeat': sch.repeat.total_seconds() if sch.repeat else 0,
'time': (sch.time.hour * 60 * 60 + sch.time.minute * 60 + sch.time.second) if sch.time else 0,
'day': sch.day,
'exclusive': sch.exclusive
}
return web.json_response(schedule)
except (ValueError, ScheduleNotFoundError) as ex:
raise web.HTTPNotFound(reason=str(ex))
评论列表
文章目录