Skip to content

Commit

Permalink
add *args to WorkContext.start() (#409)
Browse files Browse the repository at this point in the history
* add `*args` to `WorkContext.start()`

Co-authored-by: azawlocki <[email protected]>
  • Loading branch information
shadeofblue and azawlocki authored May 28, 2021
1 parent 112c3ba commit dcd50c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 18 additions & 1 deletion tests/executor/test_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):
self._on_download_executed = False

@staticmethod
def _get_work_context(storage):
def _get_work_context(storage=None):
return WorkContext(factory.Faker("pystr"), node_info=NodeInfoFactory(), storage=storage)

@staticmethod
Expand Down Expand Up @@ -126,3 +126,20 @@ async def test_download_json(self):
await steps.post()
self._assert_src_path(steps, src_path)
assert self._on_download_executed

@pytest.mark.parametrize(
"args",
(
("foo", 42),
(),
),
)
def test_start(self, args):
ctx = self._get_work_context()
ctx.start(*args)
steps = ctx.commit()

c = CommandContainer()
steps.register(c)

assert c.commands() == [{"start": {"args": args}}]
18 changes: 15 additions & 3 deletions yapapi/executor/ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self):
def commands(self):
return self._commands

def __repr__(self):
return f"commands: {self._commands}"

def __getattr__(self, item):
def add_command(**kwargs) -> int:
kwargs = dict(
Expand Down Expand Up @@ -57,8 +60,14 @@ def register(self, commands: CommandContainer):


class _Start(Work):
def __init__(self, *args: str):
self.args = args

def __repr__(self):
return f"start{self.args}"

def register(self, commands: CommandContainer):
commands.start()
commands.start(args=self.args)


class _SendWork(Work, abc.ABC):
Expand Down Expand Up @@ -240,6 +249,9 @@ def __init__(self, *steps: Work, timeout: Optional[timedelta] = None):
self._steps: Tuple[Work, ...] = steps
self._timeout: Optional[timedelta] = timeout

def __repr__(self):
return f"{self.__class__.__name__}: {self._steps}"

@property
def timeout(self) -> Optional[timedelta]:
"""Return the optional timeout set for execution of all steps."""
Expand Down Expand Up @@ -309,9 +321,9 @@ def deploy(self):
self._implicit_init = False
self._pending_steps.append(_Deploy())

def start(self):
def start(self, *args: str):
self._implicit_init = False
self._pending_steps.append(_Start())
self._pending_steps.append(_Start(*args))

def send_json(self, json_path: str, data: dict):
"""Schedule sending JSON data to the provider.
Expand Down

0 comments on commit dcd50c4

Please sign in to comment.