class Google::Cloud::Spanner::Backup::Restore::Job

# Job

A resource representing the long-running, asynchronous processing of a backup restore. The job can be refreshed to retrieve the restored database object once the operation has been completed.

See {Backup#restore}

@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

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

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

if job.error?
  status = job.error
else
  database = job.database
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 Restore::Job from a `Gapic::Operation` object.

# File lib/google/cloud/spanner/backup/restore/job.rb, line 235
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 Restore::Job instance.

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

Public Instance Methods

database() click to toggle source

The database is the object of the operation.

@return [Database, nil] The database instance, or

`nil` if the operation is not complete.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

job.done? #=> false
job.reload!
job.done? #=> true
database = job.database
# File lib/google/cloud/spanner/backup/restore/job.rb, line 90
def database
  return nil unless done?
  return nil unless @grpc.grpc_op.result == :response
  Database.from_grpc @grpc.results, service
end
done?() click to toggle source

Checks if the processing of the restore operation is complete.

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

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

job.done? #=> false
# File lib/google/cloud/spanner/backup/restore/job.rb, line 112
def done?
  @grpc.done?
end
end_time() click to toggle source

The operation end time.

@return [Time, nil]

# File lib/google/cloud/spanner/backup/restore/job.rb, line 228
def end_time
  return nil unless @grpc.metadata.progress.end_time
  Convert.timestamp_to_time @grpc.metadata.progress.end_time
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

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

job.error? # true

error = job.error
# File lib/google/cloud/spanner/backup/restore/job.rb, line 156
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 restore operation has errored.

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

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

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

The operation progress in percentage.

@return [Integer]

# File lib/google/cloud/spanner/backup/restore/job.rb, line 211
def progress_percent
  @grpc.metadata.progress.progress_percent
end
refresh!()
Alias for: reload!
reload!() click to toggle source

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

@return [Backup::Job] The same job instance.

@example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

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

The operation start time.

@return [Time, nil]

# File lib/google/cloud/spanner/backup/restore/job.rb, line 219
def start_time
  return nil unless @grpc.metadata.progress.start_time
  Convert.timestamp_to_time @grpc.metadata.progress.start_time
end
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

instance = spanner.instance "my-instance"
backup = instance.backup "my-backup"
job = backup.restore "my-restored-database"

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