What is the correct way to run a Job when another ...
# ask-community
i
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
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
@Tamas Foldi
Copy code
@run_status_sensor(
    run_status=DagsterRunStatus.SUCCESS,
    request_job=first,
)
def sensor_job_second(context):
???
How to run job?
s
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
@Stephen Bailey This is weird, I just want to run a job
s
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
@Stephen Bailey I still don't understand how to transfer another job to scheduling in the config((
Copy code
config = job_second
s
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
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
219 Views