Hi team - I am trying to run a local agent from a ...
# prefect-community
b
Hi team - I am trying to run a local agent from a virtualenv alongside the new server, but when I try and trigger a flow from the UI, my agent reports
[2020-04-07 22:52:35,213] ERROR - agent | Error while deploying flow: FileNotFoundError(2, "No such file or directory: 'prefect'")
I tried dialling up the logging but found nothing more
c
Hey @Brad! I’ve seen this error before whenever one runs the agent by directly sourcing from a virtual env like
/.../venv/prefect_env_name/prefect agent start
You need to make sure you actually activate the prefect virtual environment, as the agent will pass down the environment that it is running with
b
ahhh - nice pick up
of course.
that’s done it - thank you @Chris White for your incredibly timely response
c
👍 anytime!
b
One more @Chris White - I’m trying to use a local agent with some local flows using the server
but getting some weird errors
Copy code
[2020-04-08 04:24:50,068] ERROR - prefect.CloudTaskRunner | Unexpected error: KeyError('state')
Traceback (most recent call last):
  File "/venv/lib/python3.7/site-packages/prefect/engine/runner.py", line 48, in inner
    new_state = method(self, state, *args, **kwargs)
  File "/venv/lib/python3.7/site-packages/prefect/engine/cloud/task_runner.py", line 226, in check_task_is_cached
    for key, res in (candidate_state.cached_inputs or {}).items()
  File "/venv/lib/python3.7/site-packages/prefect/engine/cloud/task_runner.py", line 226, in <dictcomp>
    for key, res in (candidate_state.cached_inputs or {}).items()
KeyError: 'state'
is it expected that my local agent would be using the CloudTaskRunner?
and I would actually like to use my own subclass of TaskRunner that includes some caching, is this config something I can set with environment variables on the local agent? (via
PREFECT__ENGINE__TASK_RUNNER__DEFAULT_CLASS
?)
c
I’m honestly not sure where that
KeyError
is coming from, I’d need to look deeper to better understand it; for changing the default task runner class, yes you can do that! You’ll need to start your agent like so:
Copy code
prefect agent start -e PREFECT__ENGINE__TASK_RUNNER__DEFAULT_CLASS="full.importable.path.to.your.runner.class"
but note that you’ll want to subclass the
CloudTaskRunner
as it knows how to update states through the Prefect API
b
Cheers - I think something funky was going on in my subclass. All resolved now - thanks @Chris White
💯 1