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

Igor

09/04/2022, 6:12 PM
What is the correct way to run a Job when another one in the same repository is completed? first satus = SUCCESS and run jobs second
Copy code
@job
def first():
    pass

@job
def second():
    pass

@repository
def repository():
    return [first, second]
dagster bot responded by community 1
🤖 1
t

Tamas Foldi

09/05/2022, 5:21 AM
I think you should use a sensor to start the second job. AFAIK ops can have dependencies but jobs not, that's why you need a sensor
i

Igor

09/05/2022, 11:00 AM
@Tamas Foldi
Copy code
@run_status_sensor(
    run_status=DagsterRunStatus.SUCCESS,
    request_job=first,
)
def sensor_job_second(context):
???
How to run job?
s

Stephen Bailey

09/05/2022, 5:56 PM
Copy code
@run_status_sensor(
    run_status=DagsterRunStatus.SUCCESS,
    request_job=first,
)
def sensor_job_second(context):
    config = {} 
    yield RunRequest(run_config=config)
you can also set a
run_key
if you want to make sure that the
first
job does not spin up
second
more often than some period. for example, if you wanted at most one run per day, you could set
run_key=datetime.datetime.now().strfmt("%Y-%m-%d)
i

Igor

09/06/2022, 12:05 PM
@Stephen Bailey This is weird, I just want to run a job
s

Stephen Bailey

09/06/2022, 12:34 PM
yeah, it took me a second to grok because i thought it should be
my_job.execute()
or something like that. but a sensor doesn't say "run this job", it says, "hey dagster, put this job on the queue", or you may have it say, "hey dagster, for each of these N records, put a job on the queue", which is why it's the
yield RunRequest
syntax. having a sensor do any serious compute or direct scheduling is definitely an anti-pattern.
🌈 1
D 1
i

Igor

09/06/2022, 4:34 PM
@Stephen Bailey I still don't understand how to transfer another job to scheduling in the config((
Copy code
config = job_second
s

Stephen Bailey

09/06/2022, 4:49 PM
the
@sensor(job=job_second)
is the place where you define which job you are going to create when the sensor trips. the `config` is the settings you want for that particular, for example in the docs linked above:
Copy code
yield RunRequest(
                run_key=filename,
                run_config={
                    "ops": {"process_file": {"config": {"filename": filename}}}
                },
            )
i

Igor

09/06/2022, 5:30 PM
Copy code
@asset_sensor(asset_key=AssetKey('first_done'), job=second)
def sensor_second(context, asset_event):
    return RunRequest(run_key=None)
And put the key =
first_done
in first job
98 Views