Constructor
new Operation(scope, name)
Parameters:
| Name | Type | Description |
|---|---|---|
scope |
Compute | Zone | Region |
The scope of the operation: a |
name |
string |
Operation name. |
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
//-
// Reference a global operation.
//-
const operation = compute.operation('operation-id');
//-
// Reference a region operation.
//-
const region = compute.region('us-central1');
const operation = region.operation('operation-id');
//-
// Reference a zone operation.
//-
const zone = compute.zone('us-central1-a');
const operation = zone.operation('operation-id');
//-
// All operations are event emitters. The status of each operation is polled
// continuously, starting only after you register a "complete" listener.
//-
operation.on('complete', function(metadata) {
// The operation is complete.
});
//-
// You can register a listener to monitor when the operation begins running.
//-
operation.on('running', function(metadata) {
// The operation is running.
});
//-
// Be sure to register an error handler as well to catch any issues which
// impeded the operation.
//-
operation.on('error', function(err) {
// An error occurred during the operation.
});
//-
// To force the Operation object to stop polling for updates, simply remove
// any "complete" listeners you've registered.
//
// The easiest way to do this is with `removeAllListeners()`.
//-
operation.removeAllListeners();
Members
id
name
Methods
delete(callbackopt)
Delete the operation.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const operation = compute.operation('operation-id');
operation.delete(function(err, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
operation.delete().then(function(data) {
var apiResponse = data[0];
});
exists(callback)
Check if the operation exists.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const operation = compute.operation('operation-id');
operation.exists(function(err, exists) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
operation.exists().then(function(data) {
var exists = data[0];
});
get()
Get an operation if it exists.
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const operation = compute.operation('operation-id');
operation.get(function(err, operation, apiResponse) {
// `operation` is an Operation object.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
operation.get().then(function(data) {
var operation = data[0];
var apiResponse = data[1];
});
getMetadata(callbackopt)
Get the operation's metadata. For a detailed description of metadata see Operation resource.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
- See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
operation.getMetadata(function(err, metadata, apiResponse) {
// `metadata.error`: Contains errors if the operation failed.
// `metadata.warnings`: Contains warnings.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
operation.getMetadata().then(function(data) {
const metadata = data[0];
const apiResponse = data[1];
});