Skip to content

Commit 6ac7f65

Browse files
πŸ“Œ ISSUE-#23: Code improvement
1 parent 920fc2d commit 6ac7f65

File tree

14 files changed

+90
-25
lines changed

14 files changed

+90
-25
lines changed

β€Ž.flake8β€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
extend-ignore = E501,E501
3+
exclude =
4+
__pycache__,
5+
docs,
6+
dotflow/core/exception.py,
7+
setup.py,
8+
old,
9+
build,
10+
dist
11+
max-complexity = 10

β€Ž.github/workflows/python-app-code-quality.ymlβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ jobs:
2323
pip install flake8
2424
- name: πŸ“οΈ Code Scan
2525
run: |
26-
flake8 dotflow/ --count --show-source --statistics --ignore=E501
27-
flake8 tests/ --count --show-source --statistics --ignore=E501
26+
flake8

β€Ždotflow/__init__.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from .core.action import Action as action
66
from .core.context import Context
7-
from .core.decorators import retry # deprecated
87
from .core.workflow import DotFlow
8+
from .core.decorators import retry # deprecated
99

1010

1111
__all__ = [

β€Ždotflow/core/action.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def __call__(self, *args, **kwargs):
1919
else:
2020
return Context(storage=self._retry(*args))
2121

22-
def wrapper(*_args, **_kwargs):
22+
def action(*_args, **_kwargs):
2323
self.func = args[0]
2424
if self._has_context():
2525
context = _kwargs.get("previous_context") or Context()
2626
return Context(storage=self._retry(*_args, previous_context=context))
2727
else:
2828
return Context(storage=self._retry(*_args))
29-
return wrapper
29+
return action
3030

3131
def _retry(self, *args, **kwargs):
3232
attempt = 0

β€Ždotflow/core/controller.pyβ€Ž

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from typing import Callable, List
77

88
from dotflow.core.context import Context
9-
from dotflow.core.status.workflow import WorkflowStatus
9+
from dotflow.core.exception import ExecutionModeNotExist
10+
from dotflow.core.models import Execution, Status
1011
from dotflow.core.task import Task
1112
from dotflow.core.utils import exec
1213
from dotflow.core.decorators import time
@@ -19,7 +20,7 @@ def __init__(self,
1920
success: Callable = exec,
2021
failure: Callable = exec,
2122
keep_going: bool = False,
22-
mode: str = "sequential"):
23+
mode: Execution = Execution.SEQUENTIAL):
2324
self.workflow_id = uuid4()
2425
self.tasks = tasks
2526
self.success = success
@@ -28,28 +29,28 @@ def __init__(self,
2829
try:
2930
getattr(self, mode)(keep_going=keep_going)
3031
except AttributeError:
31-
raise Exception("Execution mode does not exist.") from AttributeError
32+
raise ExecutionModeNotExist()
3233

3334
def _callback_workflow(self, result: Task):
3435
final_status = [flow.status for flow in result]
35-
if WorkflowStatus.FAILED in final_status:
36+
if Status.FAILED in final_status:
3637
self.failure(content=result)
3738
else:
3839
self.success(content=result)
3940

4041
@time
4142
def _excution(self, task: Task, previous_context: Context):
4243
task.workflow_id = self.workflow_id
43-
task.set_status(WorkflowStatus.IN_PROGRESS)
44+
task.set_status(Status.IN_PROGRESS)
4445
task.set_previous_context(previous_context)
4546

4647
try:
4748
current_context = task.step(previous_context=previous_context)
48-
task.set_status(WorkflowStatus.COMPLETED)
49+
task.set_status(Status.COMPLETED)
4950
task.set_current_context(current_context)
5051

5152
except Exception as error:
52-
task.set_status(WorkflowStatus.FAILED)
53+
task.set_status(Status.FAILED)
5354
task.error.append(error)
5455

5556
task.callback(content=task)
@@ -66,7 +67,7 @@ def sequential(self, keep_going: bool = False):
6667
previous_context = task.current_context
6768

6869
if not keep_going:
69-
if task.status == WorkflowStatus.FAILED:
70+
if task.status == Status.FAILED:
7071
break
7172

7273
self._callback_workflow(result=self.tasks)

β€Ždotflow/core/decorators/retry.pyβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55

66
def retry(max_retry: int):
7-
warn("The 'retry' decorator is deprecated", DeprecationWarning, stacklevel=2)
7+
warn(
8+
message="The 'retry' decorator is deprecated",
9+
category=DeprecationWarning,
10+
stacklevel=2
11+
)
812

913
def inside(func):
1014

β€Ždotflow/core/decorators/time.pyβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
def time(func):
77
def inside(*args, **kwargs):
8-
start = datetime.now()
9-
task = func(*args, **kwargs)
10-
task.set_duration((datetime.now() - start).total_seconds())
11-
return task
8+
start = datetime.now()
9+
task = func(*args, **kwargs)
10+
task.set_duration((datetime.now() - start).total_seconds())
11+
return task
1212
return inside

β€Ždotflow/core/exception.pyβ€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Exception module"""
2+
3+
MESSAGE_MISSING_STEP_DECORATOR = "A step function necessarily needs an 'action' decorator to circulate in the workflow. For more implementation details, access the documentation: https://dotflow-io.github.io/dotflow/nav/getting-started/#3-task-function."
4+
MESSAGE_EXECUTION_NOT_EXIST = "The execution mode does not exist. Allowed parameter is 'sequential' and 'background'."
5+
6+
7+
class MissingStepDecorator(Exception):
8+
9+
def __init__(self):
10+
super(MissingStepDecorator, self).__init__(MESSAGE_MISSING_STEP_DECORATOR)
11+
12+
13+
class ExecutionModeNotExist(Exception):
14+
15+
def __init__(self):
16+
super(ExecutionModeNotExist, self).__init__(MESSAGE_EXECUTION_NOT_EXIST)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Types __init__ module."""
2+
3+
from dotflow.core.models.execution import Execution
4+
from dotflow.core.models.status import Status
5+
6+
7+
__all__ = [
8+
"Execution",
9+
"Status"
10+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Execution mode module"""
2+
3+
4+
class Execution:
5+
6+
SEQUENTIAL = "sequential"
7+
BACKGROUND = "background"
8+
PARALLEL = "parallel"
9+
DATA_STORE = "data_store"

0 commit comments

Comments
Β (0)