Class: LaunchDarkly::Migrations::MigratorBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/migrations.rb

Overview

The migration builder is used to configure and construct an instance of a Interfaces::Migrations::Migrator. This migrator can be used to perform LaunchDarkly assisted technology migrations through the use of migration-based feature flags.

Constant Summary collapse

EXECUTION_SERIAL =
:serial
EXECUTION_RANDOM =
:random
EXECUTION_PARALLEL =
:parallel

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ MigratorBuilder

Returns a new instance of MigratorBuilder.

Parameters:



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ldclient-rb/migrations.rb', line 117

def initialize(client)
  @client = client

  # Default settings as required by the spec
  @read_execution_order = EXECUTION_PARALLEL
  @measure_latency = true
  @measure_errors = true

  @read_config = nil # @type [LaunchDarkly::Impl::Migrations::MigrationConfig, nil]
  @write_config = nil # @type [LaunchDarkly::Impl::Migrations::MigrationConfig, nil]
end

Instance Method Details

#buildLaunchDarkly::Interfaces::Migrations::Migrator, string

Build constructs a Interfaces::Migrations::Migrator instance to support migration-based reads and writes. A string describing any failure conditions will be returned if the build fails.



220
221
222
223
224
225
226
# File 'lib/ldclient-rb/migrations.rb', line 220

def build
  return "client not provided" if @client.nil?
  return "read configuration not provided" if @read_config.nil?
  return "write configuration not provided" if @write_config.nil?

  LaunchDarkly::Impl::Migrations::Migrator.new(@client, @read_execution_order, @read_config, @write_config, @measure_latency, @measure_errors)
end

#read(old_read, new_read, comparison = nil) ⇒ Object

Read can be used to configure the migration-read behavior of the resulting Interfaces::Migrations::Migrator instance.

Users are required to provide two different read methods -- one to read from the old migration origin, and one to read from the new origin. Additionally, customers can opt-in to consistency tracking by providing a comparison function.

Depending on the migration stage, one or both of these read methods may be called.

The read methods should accept a single nullable parameter. This parameter is a payload passed through the Interfaces::Migrations::Migrator#read method. This method should return a Result instance.

The consistency method should accept 2 parameters of any type. These parameters are the results of executing the read operation against the old and new origins. If both operations were successful, the consistency method will be invoked. This method should return true if the two parameters are equal, or false otherwise.

Parameters:

  • old_read (#call)
  • new_read (#call)
  • comparison (#call, nil) (defaults to: nil)


183
184
185
186
187
188
189
# File 'lib/ldclient-rb/migrations.rb', line 183

def read(old_read, new_read, comparison = nil)
  return unless old_read.respond_to?(:call) && old_read.arity == 1
  return unless new_read.respond_to?(:call) && new_read.arity == 1
  return unless comparison.nil? || (comparison.respond_to?(:call) && comparison.arity == 2)

  @read_config = LaunchDarkly::Impl::Migrations::MigrationConfig.new(old_read, new_read, comparison)
end

#read_execution_order(order) ⇒ Object

The read execution order influences the parallelism and execution order for read operations involving multiple origins.

Parameters:

  • order (Symbol)


135
136
137
138
139
# File 'lib/ldclient-rb/migrations.rb', line 135

def read_execution_order(order)
  return unless VALID_EXECUTION_ORDERS.include? order

  @read_execution_order = order
end

#track_errors(enabled) ⇒ Object

Enable or disable error tracking for migration operations. This error information can be sent upstream to LaunchDarkly to enhance migration visibility.

Parameters:

  • enabled (Boolean)


157
158
159
# File 'lib/ldclient-rb/migrations.rb', line 157

def track_errors(enabled)
  @measure_errors = !!enabled
end

#track_latency(enabled) ⇒ Object

Enable or disable latency tracking for migration operations. This latency information can be sent upstream to LaunchDarkly to enhance migration visibility.

Parameters:

  • enabled (Boolean)


147
148
149
# File 'lib/ldclient-rb/migrations.rb', line 147

def track_latency(enabled)
  @measure_latency = !!enabled
end

#write(old_write, new_write) ⇒ Object

Write can be used to configure the migration-write behavior of the resulting Interfaces::Migrations::Migrator instance.

Users are required to provide two different write methods -- one to write to the old migration origin, and one to write to the new origin.

Depending on the migration stage, one or both of these write methods may be called.

The write methods should accept a single nullable parameter. This parameter is a payload passed through the Interfaces::Migrations::Migrator#write method. This method should return a Result instance.

Parameters:

  • old_write (#call)
  • new_write (#call)


207
208
209
210
211
212
# File 'lib/ldclient-rb/migrations.rb', line 207

def write(old_write, new_write)
  return unless old_write.respond_to?(:call) && old_write.arity == 1
  return unless new_write.respond_to?(:call) && new_write.arity == 1

  @write_config = LaunchDarkly::Impl::Migrations::MigrationConfig.new(old_write, new_write, nil)
end