File: operation_progress.go

package info (click to toggle)
golang-google-api 0.61.0-6
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 209,156 kB
  • sloc: sh: 183; makefile: 22; python: 4
file content (45 lines) | stat: -rw-r--r-- 989 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2018 Google LLC. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"context"
	"log"

	"golang.org/x/oauth2/google"
	compute "google.golang.org/api/compute/v1"
)

const (
	projectID   = "some-project-id"
	zone        = "some-zone"
	operationID = "some-operation-id"
)

func operationProgressMain() {
	ctx := context.Background()

	client, err := google.DefaultClient(ctx, compute.CloudPlatformScope)
	if err != nil {
		log.Fatal(err)
	}
	svc, err := compute.New(client)
	if err != nil {
		log.Fatal(err)
	}

	for {
		resp, err := svc.ZoneOperations.Get(projectID, zone, operationID).Do()
		if err != nil {
			log.Fatal(err)
		}
		// Note: the response Status may differ between APIs. The string values
		// checked here may need to be changed depending on the API.
		if resp.Status != "WORKING" && resp.Status != "QUEUED" {
			break
		}
	}
	log.Println("operation complete")
}