Class: Flor::Spooler

Inherits:
Object
  • Object
show all
Defined in:
lib/flor/unit/spooler.rb

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ Spooler

NB: logger configuration entries start with “spo_”



9
10
11
12
13
14
# File 'lib/flor/unit/spooler.rb', line 9

def initialize(unit)

  @unit = unit

  @dir = determine_spool_dir
end

Instance Method Details

#shutdownObject



16
17
18
19
# File 'lib/flor/unit/spooler.rb', line 16

def shutdown

  @dir = nil
end

#spoolObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/flor/unit/spooler.rb', line 21

def spool

  return -1 unless @dir

  Dir[File.join(@dir, '*.json')]
    .inject(0) do |count, path|

      begin
        File.open(path, 'rb') do |f|
          lock(path, f) or next
          accept(path, f) or next
          unlock(path, f)
        end
        count += 1
      rescue => err
        reject(path, err)
      end

      count
    end
end