Skip to content

Commit 9c478db

Browse files
committed
Rename things, comment others
A pass at using "workflow_class", not "workflow", when this is what we use. (We unfortunately can't use "workflow_type" since it's a term of art on SWF). Also, add some [PEP 484](https://www.python.org/dev/peps/pep-0484/) type hints. Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 09ee246 commit 9c478db

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

simpleflow/command.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
from simpleflow.utils import json_dumps
2727
from simpleflow import __version__
2828

29+
if False:
30+
from typing import Text, Type
31+
from simpleflow import Workflow
32+
from swf.models import WorkflowType
33+
34+
2935
logger = logging.getLogger(__name__)
3036

3137

3238
def get_workflow(clspath):
39+
# type: (Text) -> Type[Workflow]
3340
"""
3441
Import a workflow class.
3542
:param clspath: class path
36-
:type clspath: str
3743
:return:
38-
:rtype: simpleflow.workflow.Workflow
3944
"""
4045
modname, clsname = clspath.rsplit('.', 1)
4146
module = __import__(modname, fromlist=['*'])
@@ -78,19 +83,17 @@ def cli(ctx, header, format):
7883
ctx.params['header'] = header
7984

8085

81-
def get_workflow_type(domain_name, workflow):
86+
def get_workflow_type(domain_name, workflow_class):
87+
# type: (Text, Type[Workflow]) -> WorkflowType
8288
"""
83-
Get or create the given workflow.
89+
Get or create the given workflow on SWF.
8490
:param domain_name:
85-
:type domain_name: str
86-
:param workflow:
87-
:type workflow: simpleflow.workflow.Workflow
91+
:param workflow_class:
8892
:return:
89-
:rtype: swf.models.WorkflowType
9093
"""
9194
domain = swf.models.Domain(domain_name)
9295
query = swf.querysets.WorkflowTypeQuerySet(domain)
93-
return query.get_or_create(workflow.name, workflow.version)
96+
return query.get_or_create(workflow_class.name, workflow_class.version)
9497

9598

9699
def load_input(input_fp):
@@ -164,24 +167,24 @@ def start_workflow(workflow,
164167
input,
165168
input_file,
166169
local):
167-
workflow_definition = get_workflow(workflow)
170+
workflow_class = get_workflow(workflow)
168171

169172
wf_input = get_or_load_input(input_file, input)
170173

171174
if local:
172175
from .local import Executor
173176

174-
Executor(workflow_definition).run(wf_input)
177+
Executor(workflow_class).run(wf_input)
175178

176179
return
177180

178181
if not domain:
179182
raise ValueError('*domain* must be set when not running in local mode')
180183

181-
workflow_type = get_workflow_type(domain, workflow_definition)
184+
workflow_type = get_workflow_type(domain, workflow_class)
182185
execution = workflow_type.start_execution(
183186
workflow_id=workflow_id,
184-
task_list=task_list or workflow_definition.task_list,
187+
task_list=task_list or workflow_class.task_list,
185188
execution_timeout=execution_timeout,
186189
input=wf_input,
187190
tag_list=tags,

simpleflow/executor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
from ._decorators import deprecated
55

6+
7+
if False:
8+
from typing import Text, Type
9+
from simpleflow import Workflow
10+
611
__all__ = ['Executor']
712

813

@@ -33,7 +38,8 @@ class Executor(object):
3338
"""
3439
__metaclass__ = abc.ABCMeta
3540

36-
def __init__(self, workflow):
41+
def __init__(self, workflow_class):
42+
# type: (Type[Workflow]) -> None
3743
"""
3844
Binds the workflow's definition.
3945
@@ -42,7 +48,7 @@ def __init__(self, workflow):
4248
as a program, the workflow, and an interpreter, the executor.
4349
4450
"""
45-
self._workflow = workflow(self)
51+
self._workflow = workflow_class(self)
4652

4753
@property
4854
def workflow(self):

simpleflow/local/executor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Executor(executor.Executor):
2222
Executes all tasks synchronously in a single local process.
2323
2424
"""
25-
def __init__(self, workflow):
26-
super(Executor, self).__init__(workflow)
25+
def __init__(self, workflow_class):
26+
super(Executor, self).__init__(workflow_class)
2727
self.nb_activities = 0
2828
self.signals_sent = set()
2929

@@ -111,6 +111,8 @@ def run(self, input=None):
111111
self.before_replay()
112112
result = self.run_workflow(*args, **kwargs)
113113

114+
# Hack: self._history must be available to the callback as a
115+
# simpleflow.history.History, not a swf.models.history.builder.History
114116
self._history = History(self._history)
115117
self._history.parse()
116118
self.after_replay()

simpleflow/swf/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class Executor(executor.Executor):
161161
162162
"""
163163

164-
def __init__(self, domain, workflow, task_list=None, repair_with=None,
164+
def __init__(self, domain, workflow_class, task_list=None, repair_with=None,
165165
force_activities=None):
166-
super(Executor, self).__init__(workflow)
166+
super(Executor, self).__init__(workflow_class)
167167
self._history = None
168168
self._execution_context = {}
169169
self.domain = domain

0 commit comments

Comments
 (0)