class Google::Cloud::Spanner::Database::Job
# Job
A resource representing the long-running, asynchronous processing of a database create or update operation. The job can be refreshed to retrieve the database object once the operation has been completed.
See {Project#create_database} and {Database#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_database "my-instance", "my-new-database" job.done? #=> false job.reload! # API call job.done? #=> true if job.error? status = job.error else database = job.database end
Attributes
@private The `Gapic::Operation` gRPC object.
@private The gRPC Service
object.
Public Class Methods
@private New Database::Job
from a `Gapic::Operation` object.
# File lib/google/cloud/spanner/database/job.rb, line 205 def self.from_grpc grpc, service new.tap do |job| job.instance_variable_set :@grpc, grpc job.instance_variable_set :@service, service end end
@private Creates a new Database::Job
instance.
# File lib/google/cloud/spanner/database/job.rb, line 64 def initialize @grpc = nil @service = nil end
Public Instance Methods
The database that is the object of the operation.
@return [Google::Cloud::Spanner::Database, nil] The database, or
`nil` if the operation is not complete.
@example
require "google/cloud/spanner" spanner = Google::Cloud::Spanner.new job = spanner.create_database "my-instance", "my-new-database" job.done? #=> false job.reload! job.done? #=> true database = job.database
# File lib/google/cloud/spanner/database/job.rb, line 88 def database return nil unless done? return nil unless @grpc.grpc_op.result == :response return nil unless @grpc.results.instance_of? \ Admin::Database::V1::Database Database.from_grpc @grpc.results, service end
Checks if the processing of the database operation is complete.
@return [boolean] `true` when complete, `false` otherwise.
@example
require "google/cloud/spanner" spanner = Google::Cloud::Spanner.new job = spanner.create_database "my-instance", "my-new-database" job.done? #=> false
# File lib/google/cloud/spanner/database/job.rb, line 111 def done? @grpc.done? end
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_database "my-instance", "my-new-database" job.error? # true error = job.error
# File lib/google/cloud/spanner/database/job.rb, line 153 def error return nil unless error? Google::Cloud::Spanner::Status.from_grpc @grpc.error end
Checks if the processing of the database operation has errored.
@return [boolean] `true` when errored, `false` otherwise.
@example
require "google/cloud/spanner" spanner = Google::Cloud::Spanner.new job = spanner.create_database "my-instance", "my-new-database" job.error? #=> false
# File lib/google/cloud/spanner/database/job.rb, line 130 def error? @grpc.error? end
Reloads the job with current data from the long-running, asynchronous processing of a database operation.
@return [Google::Cloud::Spanner::Database::Job] The same job
instance.
@example
require "google/cloud/spanner" spanner = Google::Cloud::Spanner.new job = spanner.create_database "my-instance", "my-new-database" job.done? #=> false job.reload! # API call job.done? #=> true
# File lib/google/cloud/spanner/database/job.rb, line 177 def reload! @grpc.reload! self end
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_database "my-instance", "my-new-database" job.done? #=> false job.wait_until_done! job.done? #=> true
# File lib/google/cloud/spanner/database/job.rb, line 199 def wait_until_done! @grpc.wait_until_done! end