Skip to content

Commit

Permalink
Read workflow runner from config
Browse files Browse the repository at this point in the history
* Only count hybrid/cloud as valid options

GitOrigin-RevId: e1f3af88ce923c336233ffd7ad82012d16229fbc
  • Loading branch information
mckornfield committed Nov 29, 2023
1 parent 08598dd commit d084f67
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gretel_client/cli/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def get_workflows_api() -> WorkflowsApi:
return get_session_config().get_v1_api(WorkflowsApi)


def determine_runner_mode() -> str:
default_runner = get_session_config().default_runner
if not default_runner:
return RunnerMode.RUNNER_MODE_CLOUD
return RunnerMode.from_str(default_runner)


@workflows.command(help="Create a new workflow.")
@click.option("--name", metavar="NAME", help="Workflow name.")
@project_option
Expand All @@ -45,7 +52,7 @@ def get_workflows_api() -> WorkflowsApi:
"--runner_mode",
metavar="NAME",
help="The RunnerMode to use by default when running this workflow.",
default=RunnerMode.RUNNER_MODE_CLOUD.value,
default=determine_runner_mode,
)
@pass_session
def create(
Expand All @@ -55,7 +62,6 @@ def create(
project: str,
runner_mode: str = RunnerMode.RUNNER_MODE_CLOUD.value,
):

with open(config, encoding="utf-8") as file:
workflow_config = yaml.safe_load(file)

Expand Down
4 changes: 4 additions & 0 deletions src/gretel_client/workflows/runner_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ def from_str(
"hybrid": RUNNER_MODE_HYBRID,
},
) -> RunnerMode:
if unstrict not in _string_map:
raise ValueError(
f"Workflows only supported for 'cloud' or 'hybrid', not '{unstrict}'"
)
return _string_map[unstrict]
26 changes: 26 additions & 0 deletions tests/gretel_client/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,29 @@ def test_get_agent_env_var_passing_fails(
print(cmd.output)
get_agent_mock.assert_not_called()
assert cmd.exit_code == 1


@patch("gretel_client.cli.workflows.get_session_config")
def test_workflows_read_from_env_manual(
get_session_config: MagicMock,
get_project: MagicMock,
runner: CliRunner,
):
client_config = ClientConfig()
client_config.default_runner = "manual"
get_session_config.return_value = client_config
cmd = runner.invoke(
cli,
[
"workflows",
"create",
"--config",
"not-there",
],
)

assert (
cmd.output
== "ERROR: Workflows only supported for 'cloud' or 'hybrid', not 'manual'\n"
)
assert cmd.exit_code == 1

0 comments on commit d084f67

Please sign in to comment.