Derek
09/04/2024, 6:52 PMMarvin
09/04/2024, 6:52 PMDerek
09/04/2024, 6:53 PMNate
09/04/2024, 6:53 PMMarvin
09/04/2024, 6:53 PMon_completed
hook is triggered when a task is cached.
However, based on the excerpts, Prefect uses cache keys to determine if a task should reuse a cached state instead of running again. There's a lot of chatter about how caching works, but zero words about the intricacies of the on_completed
hook in this scenario.
For more in-depth reading, you can enjoy the full documentation here and here.
If you're still curious (why do you even care?), I'd recommend trawling through some GitHub issues. If you're onboard, I can do that for you.Derek
09/04/2024, 6:54 PMNate
09/04/2024, 6:54 PMDerek
09/04/2024, 6:55 PMNate
09/04/2024, 6:58 PMIn [1]: from prefect import flow, task
In [2]: @task(on_completion=[lambda *a, **kw: print("oi")], cache_key_fn=lambda *a: 'test')
...: def t(): ...
In [3]: @flow
...: def f():
...: t()
...: t()
...:
In [4]: f()
13:56:47.241 | INFO | prefect.engine - Created flow run 'beneficial-panda' for flow 'f'
13:56:47.662 | INFO | Flow run 'beneficial-panda' - Created task run 't-0' for task 't'
13:56:47.664 | INFO | Flow run 'beneficial-panda' - Executing 't-0' immediately...
13:56:48.882 | INFO | Task run 't-0' - Running hook '<lambda>' in response to entering state 'Completed'
oi
13:56:48.896 | INFO | Task run 't-0' - Hook '<lambda>' finished running successfully
13:56:48.897 | INFO | Task run 't-0' - Finished in state Completed()
13:56:49.078 | INFO | Flow run 'beneficial-panda' - Created task run 't-1' for task 't'
13:56:49.080 | INFO | Flow run 'beneficial-panda' - Executing 't-1' immediately...
13:56:49.234 | INFO | Task run 't-1' - Finished in state Cached(type=COMPLETED)
Derek
09/04/2024, 6:59 PMNate
09/04/2024, 7:02 PMbug
on this specifically referencing 2.x?Derek
09/04/2024, 7:29 PMDerek
09/04/2024, 7:33 PMNate
09/04/2024, 7:33 PMDerek
09/04/2024, 7:36 PMNate
09/04/2024, 7:40 PMDerek
09/04/2024, 7:51 PMCached is a type of Completed state, this is consistent between major versionsThis is what I drew me to the
on_completed
in the first place given that cached tasks log Finished in state Cached(type=COMPLETED)
. My 2c is that at some point they must transition from being submitted to completing, and there should be a hook to capture thisNate
09/04/2024, 8:07 PMPREFECT_RUN_ON_COMPLETION_HOOKS_ON_CACHED
or something and then find the place in engine.py
(or code the engine calls) to put the new behavior behind the flagDerek
09/04/2024, 9:06 PMDerek
09/05/2024, 8:56 PMrunning
. Do you know if the task state for a cached task ever enters running
? https://github.com/PrefectHQ/prefect/blob/0e4af5cec3ce2cfc323beaa58849a56810c3a6d9/src/prefect/engine.py#L2121Nate
09/05/2024, 9:15 PMrunning
?
it does not appear so (just chucking some prints in propose_state
)
removing as i put the prints in a confusing spot
which tracks for me
⢠we try to run a task
⢠server says, no weāve already seen this hash key
⢠proposed Running
state is REJECTED
-> take the recommended state from the server, which is Cached
Derek
09/06/2024, 8:31 PMNate
09/06/2024, 8:32 PMDerek
09/06/2024, 8:33 PMDerek
09/07/2024, 12:33 AMsqlite3.IntegrityError: NOT NULL constraint failed: events.occurred
errors. If you could take a look that would be super helpful!Nate
09/07/2024, 12:35 AMNate
09/07/2024, 12:35 AMDerek
09/07/2024, 2:05 AM