Class: LaunchDarkly::Impl::Migrations::Migrator Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Migrations::Migrator
- Defined in:
- lib/ldclient-rb/impl/migrations/migrator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An implementation of the [LaunchDarkly::Interfaces::Migrations::Migrator] interface, capable of supporting feature-flag backed technology migrations.
Instance Method Summary collapse
-
#initialize(client, read_execution_order, read_config, write_config, measure_latency, measure_errors) ⇒ Migrator
constructor
private
A new instance of Migrator.
-
#read(key, context, default_stage, payload = nil) ⇒ LaunchDarkly::Migrations::OperationResult
private
Perform the configured read operations against the appropriate old and/or new origins.
-
#write(key, context, default_stage, payload = nil) ⇒ LaunchDarkly::Migrations::WriteResult
private
Perform the configured write operations against the appropriate old and/or new origins.
Constructor Details
#initialize(client, read_execution_order, read_config, write_config, measure_latency, measure_errors) ⇒ Migrator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Migrator.
68 69 70 71 72 73 74 75 76 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 68 def initialize(client, read_execution_order, read_config, write_config, measure_latency, measure_errors) @client = client @read_execution_order = read_execution_order @read_config = read_config @write_config = write_config @measure_latency = measure_latency @measure_errors = measure_errors @sampler = LaunchDarkly::Impl::Sampler.new(Random.new) end |
Instance Method Details
#read(key, context, default_stage, payload = nil) ⇒ LaunchDarkly::Migrations::OperationResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform the configured read operations against the appropriate old and/or new origins.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 88 def read(key, context, default_stage, payload = nil) stage, tracker = @client.migration_variation(key, context, default_stage) tracker.operation(LaunchDarkly::Migrations::OP_READ) old = Executor.new(@client.logger, LaunchDarkly::Migrations::ORIGIN_OLD, @read_config.old, tracker, @measure_latency, @measure_errors, payload) new = Executor.new(@client.logger, LaunchDarkly::Migrations::ORIGIN_NEW, @read_config.new, tracker, @measure_latency, @measure_errors, payload) case stage when LaunchDarkly::Migrations::STAGE_OFF result = old.run when LaunchDarkly::Migrations::STAGE_DUALWRITE result = old.run when LaunchDarkly::Migrations::STAGE_SHADOW result = read_both(old, new, @read_config.comparison, @read_execution_order, tracker) when LaunchDarkly::Migrations::STAGE_LIVE result = read_both(new, old, @read_config.comparison, @read_execution_order, tracker) when LaunchDarkly::Migrations::STAGE_RAMPDOWN result = new.run when LaunchDarkly::Migrations::STAGE_COMPLETE result = new.run else result = LaunchDarkly::Migrations::OperationResult.new( LaunchDarkly::Migrations::ORIGIN_OLD, LaunchDarkly::Result.fail("invalid stage #{stage}; cannot execute read") ) end @client.track_migration_op(tracker) result end |
#write(key, context, default_stage, payload = nil) ⇒ LaunchDarkly::Migrations::WriteResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform the configured write operations against the appropriate old and/or new origins.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 130 def write(key, context, default_stage, payload = nil) stage, tracker = @client.migration_variation(key, context, default_stage) tracker.operation(LaunchDarkly::Migrations::OP_WRITE) old = Executor.new(@client.logger, LaunchDarkly::Migrations::ORIGIN_OLD, @write_config.old, tracker, @measure_latency, @measure_errors, payload) new = Executor.new(@client.logger, LaunchDarkly::Migrations::ORIGIN_NEW, @write_config.new, tracker, @measure_latency, @measure_errors, payload) case stage when LaunchDarkly::Migrations::STAGE_OFF result = old.run() write_result = LaunchDarkly::Migrations::WriteResult.new(result) when LaunchDarkly::Migrations::STAGE_DUALWRITE , = write_both(old, new, tracker) write_result = LaunchDarkly::Migrations::WriteResult.new(, ) when LaunchDarkly::Migrations::STAGE_SHADOW , = write_both(old, new, tracker) write_result = LaunchDarkly::Migrations::WriteResult.new(, ) when LaunchDarkly::Migrations::STAGE_LIVE , = write_both(new, old, tracker) write_result = LaunchDarkly::Migrations::WriteResult.new(, ) when LaunchDarkly::Migrations::STAGE_RAMPDOWN , = write_both(new, old, tracker) write_result = LaunchDarkly::Migrations::WriteResult.new(, ) when LaunchDarkly::Migrations::STAGE_COMPLETE result = new.run() write_result = LaunchDarkly::Migrations::WriteResult.new(result) else result = LaunchDarkly::Migrations::OperationResult.fail( LaunchDarkly::Migrations::ORIGIN_OLD, LaunchDarkly::Result.fail("invalid stage #{stage}; cannot execute write") ) write_result = LaunchDarkly::Migrations::WriteResult.new(result) end @client.track_migration_op(tracker) write_result end |