Charlie Bini
06/01/2022, 8:33 PMrequired_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?Charlie Bini
06/01/2022, 8:34 PMSelector
config type work in this context? I basically want to use that but for resource keysowen
06/01/2022, 9:23 PM@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
@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)Charlie Bini
06/01/2022, 11:48 PMowen
06/02/2022, 4:27 PMCharlie Bini
06/02/2022, 4:28 PMCharlie Bini
06/02/2022, 4:29 PM