Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add *args to WorkContext.start() #409

Merged
merged 5 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be concatenated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks okay, will print e.g. "start('arg1', 'arg2')" (self.args is a tuple)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zakaprov indeed, as @azawlocki stated


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