class Google::Cloud::Spanner::Instance::Job

# Job

A resource representing the long-running, asynchronous processing of an instance create or update operation. The job can be refreshed to retrieve the instance object once the operation has been completed.

See {Project#create_instance} and {Instance#update}.

@see cloud.google.com/spanner/reference/rpc/google.longrunning#google.longrunning.Operation

Long-running Operation

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.done? #=> false
job.reload! # API call
job.done? #=> true

if job.error?
  status = job.error
else
  instance = job.instance
end

Attributes

grpc[RW]

@private The `Gapic::Operation` gRPC object.

service[RW]

@private The gRPC Service object.

Public Class Methods

from_grpc(grpc, service) click to toggle source

@private New Instance::Job from a `Gapic::Operation` object.

# File lib/google/cloud/spanner/instance/job.rb, line 223
def self.from_grpc grpc, service
  new.tap do |job|
    job.instance_variable_set :@grpc, grpc
    job.instance_variable_set :@service, service
  end
end
new() click to toggle source

@private Creates a new Instance::Job instance.

# File lib/google/cloud/spanner/instance/job.rb, line 66
def initialize
  @grpc = nil
  @service = nil
end

Public Instance Methods

done?() click to toggle source

Checks if the processing of the instance operation is complete.

@return [boolean] `true` when complete, `false` otherwise.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.done? #=> false
# File lib/google/cloud/spanner/instance/job.rb, line 117
def done?
  @grpc.done?
end
error() click to toggle source

The status if the operation associated with this job produced an error.

@return [Google::Cloud::Spanner::Status, nil] A status object with

the status code and message, or `nil` if no error occurred.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.error? # true

error = job.error
# File lib/google/cloud/spanner/instance/job.rb, line 165
def error
  return nil unless error?
  Google::Cloud::Spanner::Status.from_grpc @grpc.error
end
error?() click to toggle source

Checks if the processing of the instance operation has errored.

@return [boolean] `true` when errored, `false` otherwise.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.error? #=> false
# File lib/google/cloud/spanner/instance/job.rb, line 139
def error?
  @grpc.error?
end
instance() click to toggle source

The instance that is the object of the operation.

@return [Google::Cloud::Spanner::Instance, nil] The instance, or

`nil` if the operation is not complete.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.done? #=> false
job.reload!
job.done? #=> true
instance = job.instance
# File lib/google/cloud/spanner/instance/job.rb, line 93
def instance
  return nil unless done?
  return nil unless @grpc.grpc_op.result == :response
  Instance.from_grpc @grpc.results, service
end
refresh!()
Alias for: reload!
reload!() click to toggle source

Reloads the job with current data from the long-running, asynchronous processing of an instance operation.

@return [Google::Cloud::Spanner::Instance::Job] The same job

instance.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.done? #=> false
job.reload! # API call
job.done? #=> true
# File lib/google/cloud/spanner/instance/job.rb, line 192
def reload!
  @grpc.reload!
  self
end
Also aliased as: refresh!
wait_until_done!() click to toggle source

Reloads the job until the operation is complete. The delay between reloads will incrementally increase.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

job = spanner.create_instance "my-new-instance",
                              name: "My New Instance",
                              config: "regional-us-central1",
                              nodes: 5,
                              labels: { production: :env }

job.done? #=> false
job.wait_until_done!
job.done? #=> true
# File lib/google/cloud/spanner/instance/job.rb, line 217
def wait_until_done!
  @grpc.wait_until_done!
end