Skip to content

Commit 0aa04b2

Browse files
authored
Merge pull request #418 from botify-labs/bug/DATA-17956/Simpleflow-handle-failures-in-format-encode-format-decode
2 parents 7058387 + dc9d047 commit 0aa04b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+965
-219
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ repos:
1212
- id: check-added-large-files
1313

1414
- repo: https://github.com/charliermarsh/ruff-pre-commit
15-
rev: 'v0.0.254'
15+
rev: 'v0.0.278'
1616
hooks:
1717
- id: ruff
1818
args: [ --fix, --exit-non-zero-on-fix ]
1919

2020
- repo: https://github.com/psf/black
21-
rev: 23.1.0
21+
rev: 23.7.0
2222
hooks:
2323
- id: black
2424
args: [--target-version=py37]

docs/src/features/error_handling.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ The `TaskFailureContext` currently have these members:
2424

2525
* a_task: failed `ActivityTask` or `WorkflowTask`
2626
* task_name: activity or workflow name
27-
* exception: raised exception (shortcut to future.exception)
27+
* exception_class: `TaskException` or `WorkflowException`
28+
* exception: raised exception (shortcut to future.exception); None for unfinished tasks
2829
* retry_count: current retry count (0 for first retry)
2930
* task_error: for a TaskFailed exception, name of the inner exception if available
31+
* reason: `TaskFailed.reason` or `str(exception)`
32+
* details: `TaskFailed.details` or None
3033
* future: failed future
3134
* event: quite opaque dict, experimental
3235
* history: History object, experimental
@@ -38,7 +41,7 @@ The `TaskFailureContext.decision` (nothing in common with SWF’s decisions) sho
3841
* none: default value, continue with default handling (potential retries then abort)
3942
* abort: use default abort strategy
4043
* ignore: discard the exception, consider the task finished; the future’s result may be user-modified
41-
* cancel: mark the future as cancelled
44+
* cancel: mark the future as canceled
4245
* retry: schedule the task again; its args and kwargs may be user-modified (well, the whole task)
4346
* retry_later: schedule the task after retry_wait_timeout seconds, with args and kwargs potentially altered
4447
* handled: `on_task_failure` somewhat handled the failure; use the future and task it has possibly modified (one

examples/canvas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run(self):
8282
)
8383
)
8484

85-
assert [None, 2, 6] == future.result, "Unexpected result {!r}".format(future.result)
85+
assert [None, 2, 6] == future.result, f"Unexpected result {future.result!r}"
8686
print(f"Chain ignoring failure: {future.result}")
8787

8888
# Failing inside a chain by default don't stop an upper chain
@@ -97,7 +97,7 @@ def run(self):
9797
)
9898
)
9999

100-
assert [[None], 2, 6] == future.result, "Unexpected result {!r}".format(future.result)
100+
assert [[None], 2, 6] == future.result, f"Unexpected result {future.result!r}"
101101
print(f"Chain with failure in subchain: {future.result}")
102102

103103
# But it can, too
@@ -116,7 +116,7 @@ def run(self):
116116
)
117117
)
118118

119-
assert [[[None]], 6] == future.result, "Unexpected result {!r}".format(future.result)
119+
assert [[[None]], 6] == future.result, f"Unexpected result {future.result!r}"
120120
print(f"Chain with failure in sub-subchain: {future.result}")
121121

122122
print("Finished!")

examples/child_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_workflow_id(cls, *args, **kwargs):
6262
return kwargs.get("my_id")
6363

6464
def run(self, my_id=None):
65-
print("ChildWorkflowWithGetId: id={}, workflow_id={}".format(my_id, self.get_run_context().get("workflow_id")))
65+
print(f"ChildWorkflowWithGetId: id={my_id}, workflow_id={self.get_run_context().get('workflow_id')}")
6666

6767

6868
class ParentWorkflow(Workflow):

script/release

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def execute(command: list[str], ignore: bool = False, log: bool = False, dry_run
5555
:return: command output
5656
"""
5757
if log or dry_run:
58-
print("{}execute: {}".format("would " if dry_run else "", " ".join(quote(c) for c in command)))
58+
print(f"{'would ' if dry_run else ''}execute: {' '.join(quote(c) for c in command)}")
5959
if dry_run:
6060
return ""
6161
env = os.environ.copy()
@@ -254,7 +254,7 @@ def input_new_version(current: Version) -> Version:
254254
try:
255255
new_version = Version(new_version_str)
256256
except InvalidVersion as ex:
257-
print("{}; Should be PEP 440-compatible (for instance in the form: 1.2.3)".format(ex))
257+
print(f"{ex}; Should be PEP 440-compatible (for instance in the form: 1.2.3)")
258258
else:
259259
new_version = default_new_version
260260
return new_version
@@ -325,10 +325,11 @@ def main():
325325
release_tag(new_version, changes, dry_run)
326326

327327
# push package to pypi
328-
step("Generate and push package to {}".format(args.repository or args.repository_url or "pypi"))
329-
execute(["python", "-m", "build", "--wheel"], log=True)
328+
step(f"Generate and push package to {args.repository or args.repository_url or 'pypi'}")
329+
execute(["python", "-m", "build"], log=True)
330330
wheel = f"dist/simpleflow-{new_version}-py3-none-any.whl"
331-
cmd = ["twine", "upload", wheel]
331+
tar_gz = f"dist/simpleflow-{new_version}.tar.gz"
332+
cmd = ["twine", "upload", wheel, tar_gz]
332333
if args.repository:
333334
cmd += ["--repository", args.repository]
334335
elif args.repository_url:

simpleflow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from .signal import WaitForSignal # NOQA
66
from .workflow import Workflow # NOQA
77

8-
__version__ = "0.32.0"
8+
__version__ = "0.32.1dev1"
99
__author__ = "Greg Leclercq"
1010
__license__ = "MIT"

simpleflow/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def name(self):
138138
return ".".join([prefix, name])
139139

140140
def __repr__(self):
141-
return "Activity(name={}, version={}, task_list={})".format(self.name, self.version, self.task_list)
141+
return f"Activity(name={self.name}, version={self.version}, task_list={self.task_list})"
142142

143143
def propagate_attribute(self, attr, val):
144144
setattr(self, attr, val)

simpleflow/canvas.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,9 @@ def count_finished_activities(self):
107107
return sum(1 if a.finished else 0 for a in self.futures)
108108

109109
def __repr__(self):
110-
return "<{} at {:#x}, state={state}, exception={exception}, activities={activities}, futures={futures}>".format(
111-
self.__class__.__name__,
112-
id(self),
113-
state=self._state,
114-
exception=self._exception,
115-
activities=self.activities,
116-
futures=self.futures,
110+
return (
111+
f"<{self.__class__.__name__} at {id(self):#x}, state={self._state}, exception={self._exception},"
112+
f" activities={self.activities}, futures={self.futures}>"
117113
)
118114

119115

@@ -185,7 +181,7 @@ def submit(self, executor):
185181
)
186182

187183
def __repr__(self):
188-
return "<{} at {:#x}, activities={!r}>".format(self.__class__.__name__, id(self), self.activities)
184+
return f"<{self.__class__.__name__} at {id(self):#x}, activities={self.activities!r}>"
189185

190186
def propagate_attribute(self, attr, val):
191187
"""

simpleflow/command.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,7 @@ def start_workflow(
206206
tag_list=tags,
207207
decision_tasks_timeout=decision_tasks_timeout,
208208
)
209-
print(
210-
"{workflow_id} {run_id}".format(
211-
workflow_id=execution.workflow_id,
212-
run_id=execution.run_id,
213-
)
214-
)
209+
print(f"{execution.workflow_id} {execution.run_id}")
215210
return execution
216211

217212

@@ -252,12 +247,7 @@ def restart_workflow(domain, workflow_id, run_id):
252247
tag_list=ex.tag_list,
253248
decision_tasks_timeout=ex.decision_tasks_timeout,
254249
)
255-
print(
256-
"{workflow_id} {run_id}".format(
257-
workflow_id=new_ex.workflow_id,
258-
run_id=new_ex.run_id,
259-
)
260-
)
250+
print(f"{new_ex.workflow_id} {new_ex.run_id}")
261251

262252

263253
def with_format(ctx):

simpleflow/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _check_binary_present(self):
6767
return os.access(self.local_location, os.X_OK)
6868

6969
def _download_binary(self):
70-
logger.info("Downloading binary: {} -> {}".format(self.remote_location, self.local_location))
70+
logger.info(f"Downloading binary: {self.remote_location} -> {self.local_location}")
7171
bucket, path = self.remote_location.replace("s3://", "", 1).split("/", 1)
7272
# with FileLock(dest):
7373
pull(bucket, path, self.local_location)

0 commit comments

Comments
 (0)