class Acfs::Runner
@api private
Attributes
adapter[R]
Public Class Methods
new(adapter)
click to toggle source
# File lib/acfs/runner.rb, line 12 def initialize(adapter) @adapter = adapter @running = false end
Public Instance Methods
clear()
click to toggle source
# File lib/acfs/runner.rb, line 69 def clear queue.clear adapter.abort @running = false end
enqueue(operation)
click to toggle source
Enqueue operation to be run later.
# File lib/acfs/runner.rb, line 41 def enqueue(operation) ::ActiveSupport::Notifications.instrument('acfs.runner.enqueue', operation: operation) do if running? operation_request(operation) {|req| adapter.queue req } else queue << operation end end end
process(operation)
click to toggle source
Process an operation. Synchronous operations will be run and parallel operations will be queued.
# File lib/acfs/runner.rb, line 20 def process(operation) ::ActiveSupport::Notifications.instrument('acfs.operation.before_process', operation: operation) operation.synchronous? ? run(operation) : enqueue(operation) end
queue()
click to toggle source
List of current queued operations.
# File lib/acfs/runner.rb, line 35 def queue @queue ||= [] end
run(operation)
click to toggle source
Run operation right now skipping queue.
# File lib/acfs/runner.rb, line 27 def run(operation) ::ActiveSupport::Notifications.instrument('acfs.runner.sync_run', operation: operation) do operation_request(operation) {|req| adapter.run req } end end
running?()
click to toggle source
Return true if queued operations are currently processed.
# File lib/acfs/runner.rb, line 53 def running? @running end
start()
click to toggle source
Start processing queued operations.
# File lib/acfs/runner.rb, line 59 def start return if running? enqueue_operations start_all rescue StandardError queue.clear raise end
Private Instance Methods
enqueue_operations()
click to toggle source
# File lib/acfs/runner.rb, line 84 def enqueue_operations while (operation = queue.shift) operation_request(operation) {|req| adapter.queue req } end end
operation_request(operation) { |req| ... }
click to toggle source
# File lib/acfs/runner.rb, line 90 def operation_request(operation) return if Acfs::Stub.enabled? && Acfs::Stub.stubbed(operation) req = operation.service.prepare(operation.request) return unless req.is_a? Acfs::Request req = prepare req return unless req.is_a? Acfs::Request yield req end
start_all()
click to toggle source
# File lib/acfs/runner.rb, line 77 def start_all @running = true adapter.start ensure @running = false end