Skip to content

Commit

Permalink
fix: update python client with by_path methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Aug 24, 2023
1 parent 5bf6479 commit 8a25a86
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion python-client/wmill/wmill/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def create_client(
global _client
if _client is None:
_client = AuthenticatedClient(
base_url=base_url_, token=token_, timeout=30, verify_ssl=False
base_url=base_url_,
token=token_,
timeout=30,
verify_ssl=False,
follow_redirects=True,
raise_on_unexpected_status=False,
)
return _client

Expand Down Expand Up @@ -111,6 +116,47 @@ def run_script_sync(
return get_result(job_id)


def run_script_by_path_async(
path: str,
args: Dict[str, Any] = {},
scheduled_in_secs: Union[None, int] = None,
) -> str:
"""
Launch the run of a script and return immediately its job id
"""
from windmill_api.api.job import run_script_by_path

from windmill_api.models.run_script_by_path_json_body import RunScriptByPathJsonBody

return run_script_by_path.sync_detailed(
client=create_client(),
workspace=get_workspace(),
path=path,
json_body=RunScriptByPathJsonBody.from_dict(args),
scheduled_in_secs=scheduled_in_secs,
parent_job=os.environ.get("DT_JOB_ID"),
).content.decode("us-ascii")


def run_script_by_path_sync(
path: str, args: Dict[str, Any] = {}, verbose: bool = False
) -> Dict[str, Any]:
"""
Run a script, wait for it to complete and return the result of the launched script
"""
job_id = run_script_by_path_async(path, args, None)
nb_iter = 0
while get_job_status(job_id) != JobStatus.COMPLETED:
if verbose:
print(f"Waiting for {job_id} to complete...")
if nb_iter < 10:
sleep(2.0)
else:
sleep(5.0)
nb_iter += 1
return get_result(job_id)


def get_job_status(job_id: str) -> JobStatus:
"""
Returns the status of a queued or completed job
Expand Down

0 comments on commit 8a25a86

Please sign in to comment.