I can’t find a way to attach an hook to an asset m...
# ask-community
I can’t find a way to attach an hook to an asset materialisation. I’ve created the job for the asset with
and then I inject the job in a
which I use in the repository. I’ve also found this but maybe there’s a workaround
hi @Riccardo Tesselli! do you mind sharing a bit more about what you'd like the hook to do? we do have a concept of an
, which will kick off some arbitrary code (or even another job) whenever an asset materialization event occurs for a given key.
I would like to have a failure hook which is triggered when the asset materialisation fails
right now, there's not built-in support for asset failure hooks, there is a concept of op failure hooks: https://docs.dagster.io/concepts/ops-jobs-graphs/op-hooks#op-hooks. so if you had a hook defined, you could do something like this:
Copy code
def do_asset_computation(input):

my_asset = AssetsDefinition.from_op(
    keys_by_input_name={"input": AssetKey("input")},
    keys_by_output_name={"result": AssetKey("some_asset")},
which is pretty roundabout but should work.
an alternative solution might just be to do something like
Copy code
def my_asset():
    result = None
        # ... do stuff
        result = "something"
        # things went as expected
        if result is not None:
            return result
            # ... do some error-related stuff
also, if you will only ever execute the asset via the specific job you've defined, you could just set up a run_status_sensor to alert if that job fails
@owen thanks!!!