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(op)
click to toggle source
Enqueue operation to be run later.
# File lib/acfs/runner.rb, line 41 def enqueue(op) ::ActiveSupport::Notifications.instrument 'acfs.runner.enqueue', operation: op do if running? op_request(op) {|req| adapter.queue req } else queue << op end end end
process(op)
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(op) ::ActiveSupport::Notifications.instrument 'acfs.operation.before_process', operation: op op.synchronous? ? run(op) : enqueue(op) end
queue()
click to toggle source
List of current queued operations.
# File lib/acfs/runner.rb, line 35 def queue @queue ||= [] end
run(op)
click to toggle source
Run operation right now skipping queue.
# File lib/acfs/runner.rb, line 27 def run(op) ::ActiveSupport::Notifications.instrument 'acfs.runner.sync_run', operation: op do op_request(op) {|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 (op = queue.shift) op_request(op) {|req| adapter.queue req } end end
op_request(op) { |req| ... }
click to toggle source
# File lib/acfs/runner.rb, line 90 def op_request(op) return if Acfs::Stub.enabled? && Acfs::Stub.stubbed(op) req = op.service.prepare op.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