https://dagster.io/ logo
#ask-community
Title
# ask-community
l

Linton Ye

02/25/2024, 5:00 PM
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

Chris Roth

02/26/2024, 3:02 AM
Try creating a DBResource that inherits from Resource. Then pass in a second argument to the method of that type.
l

Linton Ye

02/26/2024, 6:10 PM
Thanks. That works. Interesting that it doesn’t seem to be documented anywhere
👍 1
4 Views