Class: Google::Cloud::Spanner::Instance::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/spanner/instance/job.rb

Overview

# 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 #update.

Examples:

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

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJob

Returns a new instance of Job.



65
66
67
68
# File 'lib/google/cloud/spanner/instance/job.rb', line 65

def initialize
  @grpc = nil
  @service = nil
end

Instance Attribute Details

#grpcObject



57
58
59
# File 'lib/google/cloud/spanner/instance/job.rb', line 57

def grpc
  @grpc
end

#serviceObject



61
62
63
# File 'lib/google/cloud/spanner/instance/job.rb', line 61

def service
  @service
end

Class Method Details

.from_grpc(grpc, service) ⇒ Object



222
223
224
225
226
227
# File 'lib/google/cloud/spanner/instance/job.rb', line 222

def self.from_grpc grpc, service
  new.tap do |job|
    job.instance_variable_set :@grpc, grpc
    job.instance_variable_set :@service, service
  end
end

Instance Method Details

#done?boolean

Checks if the processing of the instance operation is complete.

Examples:

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

Returns:

  • (boolean)

    ‘true` when complete, `false` otherwise.



116
117
118
# File 'lib/google/cloud/spanner/instance/job.rb', line 116

def done?
  @grpc.done?
end

#errorGoogle::Cloud::Spanner::Status?

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

Examples:

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

Returns:



164
165
166
167
# File 'lib/google/cloud/spanner/instance/job.rb', line 164

def error
  return nil unless error?
  Google::Cloud::Spanner::Status.from_grpc @grpc.error
end

#error?boolean

Checks if the processing of the instance operation has errored.

Examples:

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

Returns:

  • (boolean)

    ‘true` when errored, `false` otherwise.



138
139
140
# File 'lib/google/cloud/spanner/instance/job.rb', line 138

def error?
  @grpc.error?
end

#instanceGoogle::Cloud::Spanner::Instance?

The instance that is the object of the operation.

Examples:

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

Returns:



92
93
94
95
96
# File 'lib/google/cloud/spanner/instance/job.rb', line 92

def instance
  return nil unless done?
  return nil unless @grpc.grpc_op.result == :response
  Instance.from_grpc @grpc.results, service
end

#reload!Google::Cloud::Spanner::Instance::Job Also known as: refresh!

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

Examples:

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

Returns:



191
192
193
194
# File 'lib/google/cloud/spanner/instance/job.rb', line 191

def reload!
  @grpc.reload!
  self
end

#wait_until_done!Object

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

Examples:

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


216
217
218
# File 'lib/google/cloud/spanner/instance/job.rb', line 216

def wait_until_done!
  @grpc.wait_until_done!
end