Module: Axn::Util::ExecutionContext

Defined in:
lib/axn/util/execution_context.rb

Class Method Summary collapse

Class Method Details

.background?Boolean

Determines if code is currently running within a background job context. Checks all registered async adapters to see if any report running in background.

Examples:

if Axn::Util::ExecutionContext.background?
  # Code is running in Sidekiq or ActiveJob
end

Returns:

  • (Boolean)

    true if running in a background job, false otherwise



17
18
19
20
21
22
23
# File 'lib/axn/util/execution_context.rb', line 17

def background?
  Axn::Async::Adapters.all.values.any? do |adapter|
    adapter.respond_to?(:_running_in_background?) && adapter._running_in_background?
  end
rescue StandardError
  false
end

.console?Boolean

Determines if code is currently running in an interactive console (IRB, Pry, Rails console). Used to skip visual separators in console output since the prompt already provides separation.

Returns:

  • (Boolean)

    true if running in a console, false otherwise



29
30
31
# File 'lib/axn/util/execution_context.rb', line 29

def console?
  defined?(Rails::Console) || defined?(IRB) || defined?(Pry)
end