cr-connect-workflow/crc/scripts/get_logs_for_study.py

39 lines
1.4 KiB
Python

from crc import session
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):
log_model = TaskLogModel(level='info',
code='mocked_code',
message='This is my logging message',
study_id=study_id,
workflow_id=workflow_id,
task=task.get_name())
return TaskLogModelSchema(many=True).dump([log_model])
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)