Hi, has anyone tried to use resources in a sensor?...
# ask-community
l
Hi, has anyone tried to use resources in a sensor? I tried to access it via
context.resources
but got an error that the resource is unknown. Here’s the sensor:
Copy code
@run_status_sensor(
    run_status=DagsterRunStatus.CANCELED,
)
def cancelled_run_status_sensor(context: RunStatusSensorContext):
    run_id = context.dagster_run.run_id
    update_run_stats(
        run_id, {"runStatus": "cancelled"}, context.resources.db.get_engine()
    )
    return SkipReason("Skipping sensor")
Here’s the error:
Copy code
dagster._core.errors.DagsterUserCodeProcessError: dagster._core.errors.DagsterUnknownResourceError: Unknown resource `db`. Specify `db` as a required resource on the compute / config function that accessed it.
c
Try creating a DBResource that inherits from Resource. Then pass in a second argument to the method of that type.
l
Thanks. That works. Interesting that it doesn’t seem to be documented anywhere
👍 1