Class: LaunchDarkly::Impl::Migrations::Executor

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

Overview

Utility class for executing migration operations while also tracking our built-in migration measurements.

Since:

  • 5.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, origin, fn, tracker, measure_latency, measure_errors, payload) ⇒ Executor

Returns a new instance of Executor.

Parameters:

Since:

  • 5.5.0



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

#originSymbol (readonly)

Returns:

  • (Symbol)

Since:

  • 5.5.0



243
244
245
# File 'lib/ldclient-rb/impl/migrations/migrator.rb', line 243

def origin
  @origin
end

Instance Method Details

#runLaunchDarkly::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