Joey
07/31/2023, 8:49 PMresources
in RunConfig
is supposed to work, detail in 🧵Joey
07/31/2023, 8:49 PMfrom dagster import ConfigurableResource, RunConfig, job, op
class DummyResource(ConfigurableResource):
foo: str = "foo"
@op
def greet_dummy(dummy: DummyResource) -> None:
print(f"Hi {dummy.foo}?")
@job
def greet_dummy_job() -> None:
greet_dummy()
# this does not work
op_result = greet_dummy_job.execute_in_process(run_config=RunConfig(resources={"dummy": DummyResource()}))
# this works
op_result = greet_dummy_job.execute_in_process(run_config=RunConfig(), resources={"dummy": DummyResource()})
Joey
07/31/2023, 8:50 PMRunConfig
but the job doesn't appear to be able to find the config properlyJoey
07/31/2023, 8:50 PMdagster-1.4.2
Auster Cid
07/31/2023, 8:54 PM@op(required_resource_keys={'dummy'})
def greet_dummy(context) -> None:
dummy = context.resources.dummy
print(f"Hi {dummy.foo}?")
Auster Cid
07/31/2023, 8:55 PMJoey
07/31/2023, 8:57 PMUsing Ops and jobs
Joey
07/31/2023, 9:03 PMRunConfig
(used to be a single dict and resources used to be defined via schema and @resource
decorator)
instance = DagsterInstance.get()
execute_job(
reconstructable(reconstructable_dummy_job),
instance=instance,
run_config=RunConfig(
resources={"dummy": DummyResource()}, execution={"config": {"multiprocess": {"max_concurrent": 2}}}
),
)
Auster Cid
07/31/2023, 9:06 PMowen
07/31/2023, 11:47 PMresources
parameter for the RunConfig
object refers to configuration for your resources, not fully-instantiated resources themselves. Instead, you'd want to pass in that resources={"dummy": DummyResource()}
into the execute_job
/ execute_in_process
command directly, i.e. ...execute_in_process(..., run_config=RunConfig(execution={...}), resources={...})
Joey
08/01/2023, 12:51 PMowen
08/01/2023, 6:02 PM@job(resources=...)
. The reason for the arg on the RunConfig object is to configure those resources that have already been bound to the job. You can imagine having some resource that reads from a certain API, and then configuring it with specific credentials via the RunConfig