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

Wait for yagna apis to be listening before starting agents #335

Merged
merged 3 commits into from
Nov 13, 2020
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
7 changes: 6 additions & 1 deletion goth/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ async def _start_nodes(self):
node_names=node_names, assertions_module=self.api_assertions_module
)
self.proxy.start()
# Wait for proxy to start. TODO: wait for a log line?
await asyncio.sleep(2.0)

# Collect all agent enabled probes and start them in parallel
awaitables = []
for probe in self.get_probes(probe_type=AgentMixin):
probe.start_agent()
awaitables.append(probe.start_agent())
await asyncio.gather(*awaitables)

@property
def host_address(self) -> str:
Expand Down
16 changes: 14 additions & 2 deletions goth/runner/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,15 @@ def __init__(
):
super().__init__(runner, client, config, log_config)

def start_agent(self):
async def start_agent(self):
"""Start the requestor agent and attach to its log stream."""

self._logger.info("Waiting for yagna API to be listening.")
await self.container.logs.wait_for_entry(
"Starting .* service on .*.", timeout=300
Copy link
Contributor

Choose a reason for hiding this comment

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

The timeout here is different from the one in provider agent. Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the requestor is requesting funds, while the provider is not

)
self._logger.info("Starting ya-requestor")

pkg_spec = self.task_package.format(
web_server_addr=self.runner.host_address,
web_server_port=self.runner.web_server_port,
Expand Down Expand Up @@ -260,9 +266,15 @@ def __init__(
super().__init__(runner, client, config, log_config)
self.agent_preset = agent_preset

def start_agent(self) -> None:
async def start_agent(self):
"""Start the provider agent and attach to its log stream."""

self._logger.info("Waiting for yagna apis to be listening...")
await self.container.logs.wait_for_entry(
"Starting .* service on .*.", timeout=10
)
Comment on lines +272 to +275
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is copy-pasted between the two agents, maybe it's better to push it into their base class (i.e. AgentMixin)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the only differences are the timeout and the name of the starting binary, so can do :)

self._logger.info("Starting ya-provider")

if self.agent_preset:
self.container.exec_run(f"ya-provider preset activate {self.agent_preset}")

Expand Down