Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created April 26, 2018 18:40
Show Gist options
  • Save mekhami/b7b60c1b0c308bf304f4f106ab6e5863 to your computer and use it in GitHub Desktop.
Save mekhami/b7b60c1b0c308bf304f4f106ab6e5863 to your computer and use it in GitHub Desktop.
@resource_op
def query_workflow_definitions(filters=None, deep_copy=False, params=None,
ignore_deleted=True, session=None, agent=None, return_dict=True):
filters = filters or {}
# Tags
q = session.query(Tag)
tags = q.all()
# Workflows
q = session.query(Workflow)
ws = q.all()
# Get the WorkflowDefinitions
q = session.query(WorkflowDefinition)
if ignore_deleted:
q = q.filter(WorkflowDefinition.archived == False)
q = q.options(
# lazyload('instances'),
joinedload(WorkflowDefinition.workflow_protocols) # joinedload faster
.joinedload(WorkflowProtocol.protocol) # joinedload faster
.subqueryload(Protocol.head.of_type(ProtocolDefinition)),
joinedload(WorkflowDefinition.step_lims_vars) # joinedload faster
.subqueryload(StepLimsVar.variable),
joinedload('workflow_sample_types')
.subqueryload('sample_type')
.subqueryload('head'),
)
# Load Workflows/Protocols
if not return_dict:
return q.all()
wf_dicts = [wf.as_dict(deep_copy, params) for wf in q.all()]
return wf_dicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment