entp-astrotrain 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/astrotrain.gemspec +1 -1
- data/lib/astrotrain/worker.rb +17 -13
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/astrotrain.gemspec
CHANGED
data/lib/astrotrain/worker.rb
CHANGED
@@ -3,8 +3,8 @@ module Astrotrain
|
|
3
3
|
class Worker
|
4
4
|
attr_accessor :logger, :sleep_duration, :name
|
5
5
|
|
6
|
-
def self.start(options = {})
|
7
|
-
new(options).run
|
6
|
+
def self.start(options = {}, &block)
|
7
|
+
new(options).run(&block)
|
8
8
|
end
|
9
9
|
|
10
10
|
def initialize(options = {})
|
@@ -14,17 +14,21 @@ module Astrotrain
|
|
14
14
|
@logger = options.key?(:logger) ? options[:logger] : STDOUT
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
# override this to perform other tasks in the astrotrain job loop
|
18
|
+
def run(&block)
|
19
|
+
block ||= lambda { |w| w.process_emails }
|
20
|
+
setup(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_emails
|
24
|
+
files = 0
|
25
|
+
Dir.foreach(Message.queue_path) do |f|
|
26
|
+
next if f =~ /^\.{1,2}$/
|
27
|
+
files += 1
|
28
|
+
file = File.join(Message.queue_path, f)
|
29
|
+
Message.receive_file(file)
|
27
30
|
end
|
31
|
+
files
|
28
32
|
end
|
29
33
|
|
30
34
|
def say(s)
|
@@ -42,7 +46,7 @@ module Astrotrain
|
|
42
46
|
|
43
47
|
loop do
|
44
48
|
count = nil
|
45
|
-
realtime = Benchmark.realtime { count = yield }
|
49
|
+
realtime = Benchmark.realtime { count = yield(self) }
|
46
50
|
|
47
51
|
break if $exit
|
48
52
|
|