is there a way to use `required_resource_keys` whe...
# ask-community
c
is there a way to use
required_resource_keys
where you can define two options and one must be provided to the job? If you name both, then both are required. If you omit it, then you can use any. But is there a way to ensure that at least one resource is used for an op?
🤖 1
does the
Selector
config type work in this context? I basically want to use that but for resource keys
o
hm I'm not 100% sure I follow, so let me know if I'm off base here. It sounds like you want something like
Copy code
@op(required_resource_keys={"resource_a", "resource_b"})
def my_op(context):
    ...
but with the option to have either resource_a or resource_b be omitted (but it's ok if both are supplied). Right now, there's no built-in way of doing this validation step. Personally, I'd recommend just creating a combined resource. This might look something like
Copy code
@resource(config_schema={"resource_a": resource_a.config_schema, "resource_b": resource_b.config_schema})
def resource_ab(context):
    a_config = context.resource_config.get("resource_a")
    b_config = context.resource_config.get("resource_b")
    assert a_config or b_config
    my_resource_a = # instantiate resource a w/ a_config
    my_resource_b = # instantiate resource b w/ b_config
    ABResource = namedtuple("ABResource", "a b")
    return ABResource(my_a_resource, my_b_resource)
    

...
@op(required_resource_keys={"resource_ab"})
def my_op(context):
    ...
(haven't tested the above code so might be some typos and such)
c
Interesting. Yeah I need to think this through some more. My job has a final step where the data is loaded to either an sftp or a Google sheet depending on the config. I was trying to combine the load into one Op to simplify the graph, but that seems to come at the cost of resource reusabllity
o
I see -- could you potentially just have a single "loader" required_resource_key, which could be supplied by either an sftp or gsheet loader resource?
c
Yup! Just figured that out this morning. I was overthinking it
Then for sftp jobs, I provide my sftp resource, and for sheets jobs, gsheets resource
1