Hey, is there a case where I should better use @jo...
# ask-community
m
Hey, is there a case where I should better use @job instead of @graph ?
y
Hi @Maverick Humbert dagster machinery always executes a job.
@job
is a convenient way to define a job. let’s say you have this piece of code:
Copy 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:
Copy code
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:
Copy code
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()
m
oh thanks for the example and details !