-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Access task inputs in state handler #3921
Comments
Hi @mianos you are attempting to access prefect Parameter values in your state handler and you are not passing any parameters into your flow. I believe you actually want to access your task's inputs in the handler but task inputs are not one of the values that are placed into context. I don't believe the task inputs are currently accessible in the state handler but I think it is something that could be accomplished. |
Thanks Josh, yes this is what I mean. Somehow get the task input so I can properly handle the timeouts in the handler. I can probably do the same thing by replacing the item, similarly to above, then in the next task, iterate through the original list of items and the result at the same time and make a new list that has the failures with their item index and the good ones. |
ps, in case anyone else cares (I notice this has been asked on slack a few times), the following satisfies this in the meantime: class CaughtTimeout:
pass
def ignore_timeout_handler(task, old_state, new_state):
if new_state.is_failed() and isinstance(new_state, state.TimedOut):
return state.Success(result=CaughtTimeout())
else:
return new_state
@prefect.task
def combine_failed(item_list, results):
rvals = list()
for ii, oo in zip(item_list, results):
if isinstance(oo, CaughtTimeout):
rvals.append({'item': ii, 'status': 'timeout'})
else:
rvals.append({'item': ii, 'status': 'OK'})
return rvals
with Flow("Slow flow") as flow:
slow_task = SlowTask(timeout=5, state_handlers=[ignore_timeout_handler])
nrange = produce_range()
t_result = slow_task.map(item=nrange,
sleep_time=nrange)
result = combine_failed(nrange, t_result) |
This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment. |
This issue was closed because it has been stale for 14 days with no activity. If this issue is important or you have more to add feel free to re-open it. |
Description
I would like to receive task
parametersinputs in a state_handlers *edit: change parameters to inputs.Expected Behavior
Maybe I am not doing this correctly but, as per the title, in my example below, setting
state_handlers=[ignore_timeout_handler]
I would expect:When exercised with:
to print the item number and sleep time but it is empty:
Reproduction
Environment
Same under ubuntu 20.04
The text was updated successfully, but these errors were encountered: