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

Documentation request: How do I handle a Run from Python? #343

Open
adamryczkowski opened this issue Apr 6, 2024 · 3 comments
Open

Documentation request: How do I handle a Run from Python? #343

adamryczkowski opened this issue Apr 6, 2024 · 3 comments

Comments

@adamryczkowski
Copy link

I know how to start a Hatchet worker. Now I am trying to use it.

I am trying unsuccessfully get the answer for the following problems relating to scheduling workflow runs using Hatchet's Python SDK:

  1. How do I check if the Workflow is defined on the server in the first place?
  2. How do I schedule a workflow run (with passing input data)?
  3. How do I check, that my run (identified by the messageID I presume) is done? (I know that hatchet supports progress updates via its streaming API, but that I will postpone once I figure out this)
  4. How do I pull the results of the run?

And thank you for doing this very promising project. :-)

@adamryczkowski
Copy link
Author

adamryczkowski commented Apr 7, 2024

I understood, that this streaming syntax is actually the way to do:

        from hatchet_sdk import StepRunEventType
        event:StepRunEventType

        for event in self._hatchet.client.listener.stream(self._messageID):
            print(event.payload)

The problem is, that if the event does not seem to be caught if the run has already been finished before the for loop starts executing.

How do I check if the run has already been computed and get its payload? The payload is there, because it is accessible via the Web UI.

@adamryczkowski
Copy link
Author

adamryczkowski commented Apr 7, 2024

One would hope to have the following code do the trick:

        from hatchet_sdk import WorkflowRun

        workflow_run:WorkflowRun = self._hatchet.client.rest_client.workflow_run_get(self._messageID)

        print(workflow_run.status)

Except, that it does not. The workflow_run_get errors with

Traceback (most recent call last):
  File "/snap/pycharm-professional/384/plugins/python/helpers-pro/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code
    result = func()
             ^^^^^^
  File "<input>", line 1, in <module>
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/hatchet_sdk/clients/rest_client.py", line 58, in workflow_run_get
    return self.workflow_api.workflow_run_get(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/pydantic/validate_call_decorator.py", line 58, in wrapper_function
    return validate_call_wrapper(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/pydantic/_internal/_validate_call.py", line 81, in __call__
    res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/hatchet_sdk/clients/rest/api/workflow_api.py", line 1476, in workflow_run_get
    response_data = self.api_client.call_api(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/hatchet_sdk/clients/rest/api_client.py", line 269, in call_api
    response_data = self.rest_client.request(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/hatchet_sdk/clients/rest/rest.py", line 243, in request
    r = self.pool_manager.request(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/urllib3/_request_methods.py", line 136, in request
    return self.request_encode_url(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/urllib3/_request_methods.py", line 183, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/urllib3/poolmanager.py", line 433, in urlopen
    conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.cache/pypoetry/virtualenvs/stan-runner-1qcHgIo7-py3.12/lib/python3.12/site-packages/urllib3/poolmanager.py", line 295, in connection_from_host
    raise LocationValueError("No host specified.")
urllib3.exceptions.LocationValueError: No host specified.

Upon inspection, the url of the underlying REST api call indeed lacks the hostname. It consists purely of the path, such as /api/v1/tenants/707d0855-80ab-4e1f-a156-f1c4546cbf52/workflow-runs/e5e3eadd-e91f-43af-a399-67c54d1aeb31.

@abelanger5
Copy link
Contributor

Hey @adamryczkowski, the empty hostname likely means that you haven't set the HATCHET_CLIENT_TOKEN environment variable. And could you share the version of the Python SDK you're using? I believe we patched the py SDK recently to fix the rest_client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants