https://dagster.io/ logo
#ask-community
Title
# ask-community
c

Chris Hansen

08/07/2022, 10:54 PM
when would i use @graph to chain ops versus @job? it seems like they accomplish the same thing?
dagster bot responded by community 1
s

Stephen Bailey

08/07/2022, 11:27 PM
a graph is one step lower than a job -- you can think of as a graph as a "super-op", while a job is a sort of "instantiated graph". For example, we have several graphs that take in some configuration and do an ETL process. Each table is created via a job that instantiates this one graph under different settings
c

Chris Hansen

08/07/2022, 11:28 PM
so the graph might be able to take parameters while the job wouldn't?
s

Stephen Bailey

08/07/2022, 11:29 PM
job can still take some config, but a graph isn't invokable -- it is just a definition
here's an example
Copy code
@op(config_schema={"website": str})
def make_request(context):
    response = requests.get(context.op_config["website"]
    return response.json()

@op
def print_result(response_json):
    print(json.dumps(response_json)

@graph
def my_cool_graph():
    response = make_request()
    print_result(response)

instantiated = my_cool_graph.to_job(name="my_cool_job", config={"ops": {"make_request": {"config": {"website": "<http://www.google.com|www.google.com>"}}}})
i like using graphs because then you can basically just loop through a list of settings and generate a set of jobs or assets dynamically from, .e.g. a YAML file with config
c

Chris Hansen

08/07/2022, 11:33 PM
i see!
so i don't need a graph to have a job?
s

Stephen Bailey

08/07/2022, 11:34 PM
no, but if you define a job, you will also get a graph under the hood
c

Chris Hansen

08/07/2022, 11:36 PM
ah i see, thank you!
c

claire

08/08/2022, 3:03 PM
Yep—Stephen provided a good use case. Another reason is that you want to switch resources depending on environment, in which case you'd create a graph and then bind the graph to resources depending on the executing environment.
3 Views