Maverick Humbert
05/09/2022, 12:07 AMyuhan
05/09/2022, 5:23 PM@job
is a convenient way to define a job.
let’s say you have this piece of code:
from dagster import graph, op
@op
def interact_with_server(context):
...
@graph
def do_stuff():
interact_with_server()
you can execute the do_stuff
graph directly -- because there’s no extra configuration needed in this graph, dagster machinery would wrap this graph to a job and then execute the job.
when you want to use features like resource and reuse the graph, you’d do:
from dagster import graph, op
@op(required_resource_keys={"server"})
def interact_with_server(context):
context.resources.server.ping_server()
@graph
def do_stuff():
interact_with_server()
prod_job = do_stuff.to_job(resource_defs={"server": prod_server}, name="do_stuff_prod")
local_job = do_stuff.to_job(
resource_defs={"server": local_server}, name="do_stuff_local"
)
but if you don’t want to reuse the graph you can simply do:
from dagster import job, op
@op(required_resource_keys={"server"})
def interact_with_server(context):
context.resources.server.ping_server()
@job(resource_defs={"server": prod_server}) # here
def do_stuff():
interact_with_server()
Maverick Humbert
05/13/2022, 8:39 AM