Class: Acfs::Runner Private

Inherits:
Object
  • Object
show all
Includes:
Service::Middleware
Defined in:
lib/acfs/runner.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Service::Middleware

#prepare

Constructor Details

#initialize(adapter) ⇒ Runner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Runner.



12
13
14
15
# File 'lib/acfs/runner.rb', line 12

def initialize(adapter)
  @adapter = adapter
  @running = false
end

Instance Attribute Details

#adapterObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/acfs/runner.rb', line 10

def adapter
  @adapter
end

Instance Method Details

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
72
73
# File 'lib/acfs/runner.rb', line 69

def clear
  queue.clear
  adapter.abort
  @running = false
end

#enqueue(operation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enqueue operation to be run later.



41
42
43
44
45
46
47
48
49
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Process an operation. Synchronous operations will be run and parallel operations will be queued.



20
21
22
23
# 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

#queueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List of current queued operations.



35
36
37
# File 'lib/acfs/runner.rb', line 35

def queue
  @queue ||= []
end

#run(operation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run operation right now skipping queue.



27
28
29
30
31
# 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?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return true if queued operations are currently processed.

Returns:

  • (Boolean)


53
54
55
# File 'lib/acfs/runner.rb', line 53

def running?
  @running
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start processing queued operations.



59
60
61
62
63
64
65
66
67
# File 'lib/acfs/runner.rb', line 59

def start
  return if running?

  enqueue_operations
  start_all
rescue StandardError
  queue.clear
  raise
end