Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud run job trigger when another job completes

I have a cloud run job(not cloud run service). I want to execute next cloud run job when first job completes . what are the suggested ways to trigger job 2 when cloud run job 1 completes ? 

1 2 2,568
2 REPLIES 2

Hello @gcloudLearning,

There are two ways on how you can execute cloud run jobs, through Workflows or by schedule.

Cloud Rub Jobs do not listen for or serve HTTP requests. To execute Cloud Run jobs from a workflow, use Cloud Run Admin API Connector. By using googleapis.run.v1.namespaces.jobs.run, It waits until the operation is complete, fails, or times out.

For an example, check Executing a Cloud Run Job using Workflows. You can also check out this Stack Overflow post as it also talks about the same solution. 

Another way you can trigger a cloud run job is by using a schedule. But in using Cloud Scheduler Job you have to input the frequency of the job rather than executing once a job finishes. You can specify the scheduler to run every minute, every hour, or every a certain day of the week.

If the above options don't work, you can contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!

@Marramirez  Thank you for the response. I tried to execute as per google documentation ,My case is when a file is created in storage  , it should trigger cloud run job.

I created below workflow-

# This is a sample workflow to test or replace with your source code.
#
# This workflow passes the region where the workflow is deployed
# to the Wikipedia API and returns a list of related Wikipedia articles.
# A region is retrieved from the GOOGLE_CLOUD_LOCATION system variable
# unless you input your own search term; for example, {"searchTerm": "asia"}.
main:
    params: [event]
    steps:
        - init:
            assign:
                - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
                - event_bucket: ${event.data.bucket}
                - event_object: ${event.data.name}
                - target_bucket: ${"project1"}
                - target_object: file.csv
                - job_name: job1
                - job_location: us-central1
        - check_input_object:
            switch:
                - condition: ${(event_bucket == target_bucket) and (event_object == target_object)}
                  next: run_job
                - condition: true
                  next: end
        - run_job:
            call: googleapis.run.v1.namespaces.jobs.run
            args:
                name: ${"namespaces/" + project_id + "/jobs/" + job_name}
                location: ${job_location}
            result: job_execution
        - finish:
            return: ${job_execution}
 
I am trying to execute it , it's giving below error -
KeyError: key not found: data
 
I have given required permission to service account also.  but this line is giving error
-
                - event_bucket: ${event.data.bucket}
I have given right bucket name while creating event, can you please suggest.