0
votes

I have two jobs and I want to execute the second one only when the first one has completed. Both are scheduled on cloud scheduler.

I am trying the get API to check the status of the first job but there is no data under the status field. Please note that I have tried to get this data when my first job was running.

  {
  "name": "projects/<project name>/locations/us-central1/jobs/<job name>",
  "description": "Sample",
  "appEngineHttpTarget": {
    "httpMethod": "GET",
    "appEngineRouting": {
      "version": "test-v1",
      "host": "test-v1.test.googleplex.com"
    },
    "relativeUri": "/api/v1/test",
    "headers": {
      "User-Agent": "AppEngine-Google; (+http://code.google.com/appengine)"
    }
  },
  "userUpdateTime": "2020-07-17T11:44:16Z",
  "state": "ENABLED",
  "status": {},
  "scheduleTime": "2020-07-18T11:00:00.834928Z",
  "lastAttemptTime": "2020-07-17T11:44:30.439092Z",
  "retryConfig": {
    "maxRetryDuration": "0s",
    "minBackoffDuration": "5s",
    "maxBackoffDuration": "3600s",
    "maxDoublings": 16
  },
  "schedule": "0 04 * * *",
  "timeZone": "America/Los_Angeles",
  "attemptDeadline": "18000s"
}

Where am I going wrong?

1

1 Answers

0
votes

I was checking the documentation on this, and it looks like to get if a job is running you need to use state, as it will return the state of the job, but I could not find in the documentation a description on when the job is done.

It looks like once the job has finished, it will populate the field status, but status will give you a description of the http status from your job (so it will tell you if it failed or if it succeeded and specific information about the job failure or success)

So, in this case you would need to check if the state is ENABLED (this would tell you that the job is not paused or has other state) and if the status is populated (this would mean that the job finished and at the same time you will know if it succeeded or if it failed).