Giacomo Colombo
03/07/2024, 8:11 AMScout
03/07/2024, 8:11 AMbuild_resources
function to manually build and configure the resource within the sensor evaluation function. Here's a step-by-step guide based on the documentation: 1. Define your resource with the desired configuration options. This resource will be used to initialize the sensor context with the specific configuration you want. 2. In your sensor definition, use the build_resources
function within a context manager to create an instance of the resource with the desired configuration. 3. Access the configured resource from the context provided by the build_resources
function and use it as needed within your sensor evaluation logic. Here's an example from the documentation that illustrates how to manually build a resource within a sensor: python from dagster import sensor, SensorEvaluationContext, build_resources # Define your resource here my_resource = ... @sensor(jobs=[my_job]) def my_sensor(_): # Initialize the resources using build_resources with build_resources(resources={"my_resource_key": my_resource}) as resources: # Access the configured resource my_configured_resource = resources.my_resource_key # Use the resource in your sensor logic ...
In this example, my_resource
is the resource you want to configure, and my_resource_key
is the key that you will use to access the resource within the sensor evaluation function. The build_resources
function is used to create an instance of the resource with the specified configuration, which is then accessed and used within the sensor logic. Remember that using build_resources
in this way is a manual approach to resource configuration within a sensor, and it's important to ensure that the resource is properly configured to meet the needs of your sensor logic.