1

What is the simplest way to wait for a job to complete on a google compute engine? Running with a bash shell, from windows, with gcloud setup.

Let's say I boot an instance

gcloud compute instances create gci --image-family gci-stable --image-project google-containers \
--scopes 773889352370-compute@developer.gserviceaccount.com="https://www.googleapis.com/auth/cloud-platform" \
--boot-disk-size "40" \
--metadata-from-file startup-script=SubmitJson.sh $MONTH

Such that I have a startup script that runs a small job (analyzes some images on Google CloudML). I want to wait for the job to complete before continuing.

I could poll its status

gcloud compute instances describe gci

which returns a long set of specs

C:\Program Files (x86)\Google\Cloud SDK>gcloud compute instances describe gci
canIpForward: false
cpuPlatform: Intel Sandy Bridge
creationTimestamp: '2017-02-19T20:42:38.878-08:00'
disks:
- autoDelete: true
  boot: true
  deviceName: persistent-disk-0
  index: 0
  interface: SCSI
  kind: compute#attachedDisk
  licenses:
  - https://www.googleapis.com/compute/v1/projects/google-containers/global/licenses/gci-public
  mode: READ_WRITE
  source: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/zones/us-central1-a/disks/gci
  type: PERSISTENT
id: '4161667477774257489'
kind: compute#instance
machineType: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/zones/us-central1-a/machineTypes/n1-standard-1
metadata:
  fingerprint: zaIRTnxUhBE=
  kind: compute#metadata
name: gci
networkInterfaces:
- accessConfigs:
  - kind: compute#accessConfig
    name: external-nat
    natIP: 104.197.244.99
    type: ONE_TO_ONE_NAT
  kind: compute#networkInterface
  name: nic0
  network: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/global/networks/default
  networkIP: 10.128.0.2
  subnetwork: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/regions/us-central1/subnetworks/default
scheduling:
  automaticRestart: true
  onHostMaintenance: MIGRATE
  preemptible: false
selfLink: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/zones/us-central1-a/instances/gci
serviceAccounts:
- email: 773889352370-compute@developer.gserviceaccount.com
  scopes:
  - https://www.googleapis.com/auth/cloud-platform
status: RUNNING
tags:
  fingerprint: 42WmSpB8rSM=
zone: https://www.googleapis.com/compute/v1/projects/api-project-773889352370/zones/us-central1-a

I can do this in a loop, every X seconds, waiting for status to become TERMINATED, but this seems really inefficient. AWS had a wait until feature for ec2. I expected to see a similar function, but can't find it. Synchronous running.

Related question, but note i'm not interested in the kubernetes cluster resource: Wait for job/pod completion in Kubernetes or Google Container Engine

Community
  • 1
  • 1
bw4sz
  • 2,237
  • 2
  • 29
  • 53
  • Doesn't answer your question but `gcloud compute instances describe gci --format 'value(status)'` is an easy way to grab out just the information that you want. – Zachary Newman Feb 21 '17 at 20:39

0 Answers0