mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 05:08:32 +00:00
2. Added two api endpoints that will allow us to get all the logs for a specific workflow or study. 3. Assured that requests for logs are paginated, sortable, and can be limited to a specific code if needed. 4. Assure that we only use logging levels that match the log levels of Python.
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from crc import session
|
|
from crc.models.task_log import TaskLogModel, TaskLogModelSchema, TaskLogQuery
|
|
from crc.scripts.script import Script
|
|
from crc.services.task_logging_service import TaskLoggingService
|
|
|
|
|
|
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.
|
|
Accepts an optional 'size' otherwise will return the most recent 10 records.
|
|
"""
|
|
|
|
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
|
|
size = 10
|
|
if 'code' in kwargs:
|
|
code = kwargs['code']
|
|
elif len(args) > 0:
|
|
code = args[0]
|
|
if 'size' in kwargs:
|
|
size = kwargs['size']
|
|
elif len(args) > 1:
|
|
size = args[1]
|
|
|
|
query = TaskLogQuery(code=code, per_page=size)
|
|
log_models = TaskLoggingService.get_logs_for_study(study_id, query).items
|
|
return TaskLogModelSchema(many=True).dump(log_models)
|