Question

It seems that all SWF operations for getting execution state always also need the runId (their reference to the workflow execution), and I don't feel like storing that. I want to be able to do a lookup based on workflowId only (my id, not theirs). Is anything like that possible at all?

I mean, I guess I could add some tags to retrieve it by tags, but that seems a little awkward, if I already passed the workflowId as well.

Was it helpful?

Solution

Yes, according to ListOpenWorkflowExecutions API documentation the user can filter open executions by workflowId.

A Python example, using boto.swf (use 1. from this post to setup the domain):

$ ipython
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
Type "copyright", "credits" or "license" for more information.

In [1]: import boto.swf.layer2 as swf

In [2]: domain = swf.Domain(name='stackoverflow')

In [3]: domain.workflows()
Out[3]: [ WorkflowType 'MyWorkflow-1.0' at 0x32a44d0 ]

In [4]: myworkflow = domain.workflows()[0]

In [5]: execution = myworkflow.start(workflow_id='my_wf_id', task_list='default')

In [6]: other_execution = myworkflow.start(workflow_id='some_other_wf_id', task_list='default')

In [7]: domain.executions()
Out[7]: 
[ WorkflowExecution 'MyWorkflow-1.0' at 0x32a4910 ,
  WorkflowExecution 'MyWorkflow-1.0' at 0x32ac090 ,
  WorkflowExecution 'MyWorkflow-1.0' at 0x32ac210 ]

In [8]: execution.describe()
Out[8]: 
{'executionConfiguration': {'childPolicy': 'TERMINATE',
  'executionStartToCloseTimeout': '3600',
  'taskList': {'name': 'default'},
  'taskStartToCloseTimeout': '300'},
 'executionInfo': {'cancelRequested': False,
  'execution': {'runId': '...',
   'workflowId': 'my_wf_id'},
  'executionStatus': 'OPEN',
  'startTimestamp': 1374482188.063,
  'workflowType': {'name': 'MyWorkflow', 'version': '1.0'}},
 'openCounts': {'openActivityTasks': 0,
  'openChildWorkflowExecutions': 0,
  'openDecisionTasks': 1,
  'openTimers': 0}}

In [9]: domain.executions(workflow_id='my_wf_id')
Out[9]: [ WorkflowExecution 'MyWorkflow-1.0' at 0x344fad0 ]

In [10]: domain.executions(workflow_id='my_wf_id')[0].describe()
Out[10]: 
{'executionConfiguration': {'childPolicy': 'TERMINATE',
  'executionStartToCloseTimeout': '3600',
  'taskList': {'name': 'default'},
  'taskStartToCloseTimeout': '300'},
 'executionInfo': {'cancelRequested': False,
  'execution': {'runId': '...',
   'workflowId': 'my_wf_id'},
  'executionStatus': 'OPEN',
  'startTimestamp': 1374482188.063,
  'workflowType': {'name': 'MyWorkflow', 'version': '1.0'}},
 'openCounts': {'openActivityTasks': 0,
  'openChildWorkflowExecutions': 0,
  'openDecisionTasks': 1,
  'openTimers': 0}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top