Scripts to retrieve logging information

This commit is contained in:
mike cullerton 2021-10-27 16:39:25 -04:00
parent c61fad752f
commit 6322353c88
2 changed files with 76 additions and 0 deletions

38
crc/scripts/get_logs.py Normal file
View File

@ -0,0 +1,38 @@
from crc import session
from crc.api.common import ApiError
from crc.models.task_log import TaskLogModel, TaskLogModelSchema
from crc.scripts.script import Script
class GetLogsByWorkflow(Script):
def get_description(self):
return """Script to retrieve logs for the current workflow.
Accepts an optional `code` argument that is used to filter the DB query.
"""
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if len(args) == 1 or 'code' in kwargs:
pass
else:
raise ApiError.from_task(code='missing_code',
message='You must include a `code` to use in the search.',
task=task)
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
code = None
if 'code' in kwargs:
code = kwargs['code']
elif len(args) > 0:
code = args[0]
if code is not None:
log_models = session.query(TaskLogModel).\
filter(TaskLogModel.code == code).\
filter(TaskLogModel.workflow_id == workflow_id).\
all()
else:
log_models = session.query(TaskLogModel). \
filter(TaskLogModel.workflow_id == workflow_id). \
all()
return TaskLogModelSchema(many=True).dump(log_models)

View File

@ -0,0 +1,38 @@
from crc import session
from crc.api.common import ApiError
from crc.models.task_log import TaskLogModel, TaskLogModelSchema
from crc.scripts.script import Script
class GetLogsByWorkflow(Script):
def get_description(self):
return """Script to retrieve logs for the current study.
Accepts an optional `code` argument that is used to filter the DB query.
"""
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
if len(args) == 1 or 'code' in kwargs:
pass
else:
raise ApiError.from_task(code='missing_code',
message='You must include a `code` to use in the search.',
task=task)
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
code = None
if 'code' in kwargs:
code = kwargs['code']
elif len(args) > 0:
code = args[0]
if code is not None:
log_models = session.query(TaskLogModel).\
filter(TaskLogModel.code == code).\
filter(TaskLogModel.study_id == study_id).\
all()
else:
log_models = session.query(TaskLogModel). \
filter(TaskLogModel.study_id == study_id). \
all()
return TaskLogModelSchema(many=True).dump(log_models)