flor 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,109 @@
1
+
2
+ module Flor
3
+
4
+ class Spooler
5
+
6
+ # NB: logger configuration entries start with "spo_"
7
+
8
+ def initialize(unit)
9
+
10
+ @unit = unit
11
+
12
+ @dir = determine_spool_dir
13
+ end
14
+
15
+ def shutdown
16
+
17
+ @dir = nil
18
+ end
19
+
20
+ def spool
21
+
22
+ return -1 unless @dir
23
+
24
+ Dir[File.join(@dir, '*.json')]
25
+ .inject(0) do |count, path|
26
+
27
+ begin
28
+ File.open(path, 'rb') do |f|
29
+ lock(path, f) or next
30
+ accept(path, f) or next
31
+ unlock(path, f)
32
+ end
33
+ count += 1
34
+ rescue => err
35
+ reject(path, err)
36
+ end
37
+
38
+ count
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ def determine_spool_dir
45
+
46
+ d = @unit.conf['spo_dir'] || 'var/spool'
47
+ d = File.join(@unit.conf['root'], d) if d
48
+ d = nil unless File.directory?(d)
49
+
50
+ d
51
+ end
52
+
53
+ def lock(path, file)
54
+
55
+ file.flock(File::LOCK_EX | File::LOCK_NB) == 0
56
+ end
57
+
58
+ def unlock(path, file)
59
+
60
+ # nothing more to do
61
+ end
62
+
63
+ def accept(path, file)
64
+
65
+ json = file.read
66
+
67
+ return false if json == ''
68
+
69
+ @unit.storage.put_message(JSON.parse(json))
70
+
71
+ con = File.join(@dir, 'consumed')
72
+
73
+ File.delete(path)
74
+
75
+ return true unless File.directory?(con)
76
+
77
+ fn = File.join(con, "#{File.basename(path, '.json')}.#{Flor.tamp}.json")
78
+
79
+ File.open(fn, 'wb') { |f| f.write(json) }
80
+
81
+ true
82
+ end
83
+
84
+ def reject(path, err)
85
+
86
+ rej = File.join(@dir, 'rejected')
87
+
88
+ FileUtils.mkdir_p(rej)
89
+
90
+ eh = err.hash.abs
91
+ ts = Flor.tamp
92
+
93
+ jfn = File.join(
94
+ rej, "#{File.basename(path, '.json')}__#{eh}_#{ts}.json")
95
+ tfn = File.join(
96
+ rej, "#{File.basename(path, '.json')}__#{eh}_#{ts}.txt")
97
+
98
+ FileUtils.mv(path, jfn)
99
+
100
+ File.open(tfn, 'wb') do |tf|
101
+ tf.puts(err.inspect)
102
+ tf.puts(err.class.to_s)
103
+ tf.puts(err.to_s)
104
+ tf.puts(err.backtrace)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
@@ -254,7 +254,7 @@ module Flor
254
254
 
255
255
  synchronize do
256
256
 
257
- @db[:flor_messages].count(status: 'created') > 0
257
+ @db[:flor_messages].where(status: 'created').count > 0
258
258
  end
259
259
 
260
260
  rescue => err
@@ -3,8 +3,6 @@ module Flor
3
3
 
4
4
  class Waiter
5
5
 
6
- DEFAULT_TIMEOUT = 4 # seconds
7
-
8
6
  def initialize(exid, opts)
9
7
 
10
8
  serie, timeout, repeat = expand_args(opts)
@@ -12,7 +10,7 @@ module Flor
12
10
  @exid = exid
13
11
  @original_serie = repeat ? Flor.dup(serie) : nil
14
12
  @serie = serie
15
- @timeout = timeout == true ? DEFAULT_TIMEOUT : timeout
13
+ @timeout = timeout
16
14
 
17
15
  @queue = []
18
16
  @mutex = Mutex.new
@@ -91,7 +89,7 @@ module Flor
91
89
 
92
90
  owait = opts[:wait]
93
91
  orepeat = opts[:repeat] || false
94
- otimeout = opts[:timeout] || DEFAULT_TIMEOUT
92
+ otimeout = opts[:timeout]
95
93
 
96
94
  case owait
97
95
  when true
@@ -3,9 +3,17 @@ module Flor
3
3
 
4
4
  class WaitList
5
5
 
6
+ # NB: tasker configuration entries start with "wtl_"
7
+ #
8
+ # `wtl_default_timeout`:
9
+ # when #launch ing or #wait ing, set the default timeout, in seconds
10
+
11
+ DEFAULT_TIMEOUT = Flor.env_i('FLOR_DEFAULT_TIMEOUT')
12
+
6
13
  def initialize(unit)
7
14
 
8
15
  @unit = unit
16
+ @unit.hooker.add('wlist', self)
9
17
 
10
18
  @mutex = Mutex.new
11
19
  @waiters = []
@@ -49,6 +57,11 @@ module Flor
49
57
  [ exid, opts ]
50
58
  end
51
59
 
60
+ opts[:timeout] =
61
+ nil if opts[:timeout] == true
62
+ opts[:timeout] ||=
63
+ (DEFAULT_TIMEOUT || @unit.conf['wtl_default_timeout'] || 5)
64
+
52
65
  @mutex.synchronize do
53
66
 
54
67
  (@waiters << Waiter.new(exid, opts)).last
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-02 00:00:00.000000000 Z
12
+ date: 2017-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: munemo
@@ -162,6 +162,7 @@ files:
162
162
  - lib/flor/pcore/sequence.rb
163
163
  - lib/flor/pcore/set.rb
164
164
  - lib/flor/pcore/stall.rb
165
+ - lib/flor/pcore/twig.rb
165
166
  - lib/flor/pcore/until.rb
166
167
  - lib/flor/pcore/val.rb
167
168
  - lib/flor/punit/cancel.rb
@@ -181,7 +182,9 @@ files:
181
182
  - lib/flor/tools/shell.rb
182
183
  - lib/flor/unit/executor.rb
183
184
  - lib/flor/unit/ganger.rb
185
+ - lib/flor/unit/hook.rb
184
186
  - lib/flor/unit/hooker.rb
187
+ - lib/flor/unit/hooks.rb
185
188
  - lib/flor/unit/journal.rb
186
189
  - lib/flor/unit/loader.rb
187
190
  - lib/flor/unit/logger.rb
@@ -191,7 +194,9 @@ files:
191
194
  - lib/flor/unit/models/trace.rb
192
195
  - lib/flor/unit/models/trap.rb
193
196
  - lib/flor/unit/models.rb
197
+ - lib/flor/unit/runner.rb
194
198
  - lib/flor/unit/scheduler.rb
199
+ - lib/flor/unit/spooler.rb
195
200
  - lib/flor/unit/storage.rb
196
201
  - lib/flor/unit/taskers.rb
197
202
  - lib/flor/unit/waiter.rb
@@ -199,6 +204,7 @@ files:
199
204
  - lib/flor/unit.rb
200
205
  - lib/flor.rb
201
206
  - flor.gemspec
207
+ - fail.txt
202
208
  - LICENSE.txt
203
209
  - CHANGELOG.md
204
210
  - README.md