Class: LaunchDarkly::Impl::Migrations::Executor
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Migrations::Executor
- Defined in:
- lib/ldclient-rb/impl/migrations/migrator.rb
Overview
Utility class for executing migration operations while also tracking our built-in migration measurements.
Instance Attribute Summary collapse
- #origin ⇒ Symbol readonly
Instance Method Summary collapse
-
#initialize(logger, origin, fn, tracker, measure_latency, measure_errors, payload) ⇒ Executor
constructor
A new instance of Executor.
-
#run ⇒ LaunchDarkly::Migrations::OperationResult
Execute the configured operation and track any available measurements.
Constructor Details
#initialize(logger, origin, fn, tracker, measure_latency, measure_errors, payload) ⇒ Executor
Returns a new instance of Executor.
253 254 255 256 257 258 259 260 261 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 253 def initialize(logger, origin, fn, tracker, measure_latency, measure_errors, payload) @logger = logger @origin = origin @fn = fn @tracker = tracker @measure_latency = measure_latency @measure_errors = measure_errors @payload = payload end |
Instance Attribute Details
#origin ⇒ Symbol (readonly)
243 244 245 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 243 def origin @origin end |
Instance Method Details
#run ⇒ LaunchDarkly::Migrations::OperationResult
Execute the configured operation and track any available measurements.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 268 def run() start = Time.now begin result = @fn.call(@payload) rescue => e LaunchDarkly::Util.log_exception(@logger, "Unexpected error running method for '#{origin}' origin", e) result = LaunchDarkly::Result.fail("'#{origin}' operation raised an exception", e) end @tracker.latency(@origin, (Time.now - start) * 1_000) if @measure_latency @tracker.error(@origin) if @measure_errors && !result.success? @tracker.invoked(@origin) LaunchDarkly::Migrations::OperationResult.new(@origin, result) end |