eventhub-processor 0.2.3 → 0.3.0
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.
- checksums.yaml +5 -13
- data/lib/eventhub/argument_parser.rb +2 -0
- data/lib/eventhub/base_exception.rb +2 -0
- data/lib/eventhub/configuration.rb +25 -26
- data/lib/eventhub/constant.rb +13 -13
- data/lib/eventhub/heartbeat.rb +77 -0
- data/lib/eventhub/helper.rb +49 -55
- data/lib/eventhub/message.rb +138 -128
- data/lib/eventhub/message_processor.rb +31 -0
- data/lib/eventhub/multi_logger.rb +89 -89
- data/lib/eventhub/no_deadletter_exception.rb +2 -0
- data/lib/eventhub/pidfile.rb +21 -0
- data/lib/eventhub/processor.rb +268 -307
- data/lib/eventhub/statistics.rb +47 -0
- data/lib/eventhub/test.rb +10 -0
- data/lib/eventhub/version.rb +1 -1
- data/lib/eventhub-processor.rb +36 -29
- metadata +47 -26
@@ -1,89 +1,89 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
# format adaptation
|
4
|
-
class Logger
|
5
|
-
class Formatter
|
6
|
-
def call(severity, time, progname, msg)
|
7
|
-
time_in_string = "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%04d" % (time.usec/100)}"
|
8
|
-
[time_in_string,Process.pid,severity,msg].join("\t") + "\n"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
module EventHub
|
16
|
-
|
17
|
-
class MultiLogger
|
18
|
-
|
19
|
-
MAX_EXCEPTIONS_FILES = 500
|
20
|
-
|
21
|
-
attr_accessor :folder, :devices
|
22
|
-
|
23
|
-
def initialize(folder=nil)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_device(device)
|
35
|
-
@devices << device
|
36
|
-
end
|
37
|
-
|
38
|
-
def save_detailed_error(feedback,message=nil)
|
39
|
-
time = Time.now
|
40
|
-
stamp = "#{time.strftime("%Y%m%d_%H%M%S")}_#{"%03d" % (time.usec/1000)}"
|
41
|
-
filename = "#{stamp}.log"
|
42
|
-
|
43
|
-
FileUtils.makedirs(@folder_exceptions)
|
44
|
-
|
45
|
-
# check max exception log files
|
46
|
-
exception_files = Dir.glob(@folder_exceptions + '/*.log')
|
47
|
-
if exception_files.size > MAX_EXCEPTIONS_FILES
|
48
|
-
exception_files.reverse[MAX_EXCEPTIONS_FILES..-1].each do |file|
|
49
|
-
begin
|
50
|
-
File.delete(file)
|
51
|
-
File.delete(File.dirname(file) + '/' + File.basename(file,".*") + '.msg.raw')
|
52
|
-
rescue
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
File.open("#{@folder_exceptions}/#{filename}","w") do |output|
|
58
|
-
output.write("#{feedback}\n\n")
|
59
|
-
output.write("Exception: #{feedback.class.to_s}\n\n")
|
60
|
-
output.write("Call Stack:\n")
|
61
|
-
feedback.backtrace.each do |line|
|
62
|
-
output.write("#{line}\n")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# save message if provided
|
67
|
-
if message
|
68
|
-
File.open("#{@folder_exceptions}/#{stamp}.msg.raw","wb") do |output|
|
69
|
-
output.write(message)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
return stamp
|
74
|
-
end
|
75
|
-
|
76
|
-
%w(log debug info warn error).each do |m|
|
77
|
-
define_method(m) do |*args|
|
78
|
-
@devices.map { |d| d.send(m, *args) }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# format adaptation
|
4
|
+
class Logger
|
5
|
+
class Formatter
|
6
|
+
def call(severity, time, progname, msg)
|
7
|
+
time_in_string = "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%04d" % (time.usec/100)}"
|
8
|
+
[time_in_string,Process.pid,severity,msg].join("\t") + "\n"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
module EventHub
|
16
|
+
|
17
|
+
class MultiLogger
|
18
|
+
|
19
|
+
MAX_EXCEPTIONS_FILES = 500
|
20
|
+
|
21
|
+
attr_accessor :folder, :devices
|
22
|
+
|
23
|
+
def initialize(folder = nil)
|
24
|
+
@folder_base = folder || Dir.pwd
|
25
|
+
@folder_base.chomp!('/')
|
26
|
+
@folder = [@folder_base,'logs'].join('/')
|
27
|
+
@folder_exceptions = [@folder_base,'exceptions'].join('/')
|
28
|
+
|
29
|
+
@devices = []
|
30
|
+
|
31
|
+
FileUtils.makedirs(@folder)
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_device(device)
|
35
|
+
@devices << device
|
36
|
+
end
|
37
|
+
|
38
|
+
def save_detailed_error(feedback,message=nil)
|
39
|
+
time = Time.now
|
40
|
+
stamp = "#{time.strftime("%Y%m%d_%H%M%S")}_#{"%03d" % (time.usec/1000)}"
|
41
|
+
filename = "#{stamp}.log"
|
42
|
+
|
43
|
+
FileUtils.makedirs(@folder_exceptions)
|
44
|
+
|
45
|
+
# check max exception log files
|
46
|
+
exception_files = Dir.glob(@folder_exceptions + '/*.log')
|
47
|
+
if exception_files.size > MAX_EXCEPTIONS_FILES
|
48
|
+
exception_files.reverse[MAX_EXCEPTIONS_FILES..-1].each do |file|
|
49
|
+
begin
|
50
|
+
File.delete(file)
|
51
|
+
File.delete(File.dirname(file) + '/' + File.basename(file,".*") + '.msg.raw')
|
52
|
+
rescue
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
File.open("#{@folder_exceptions}/#{filename}","w") do |output|
|
58
|
+
output.write("#{feedback}\n\n")
|
59
|
+
output.write("Exception: #{feedback.class.to_s}\n\n")
|
60
|
+
output.write("Call Stack:\n")
|
61
|
+
feedback.backtrace.each do |line|
|
62
|
+
output.write("#{line}\n")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# save message if provided
|
67
|
+
if message
|
68
|
+
File.open("#{@folder_exceptions}/#{stamp}.msg.raw","wb") do |output|
|
69
|
+
output.write(message)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
return stamp
|
74
|
+
end
|
75
|
+
|
76
|
+
%w(log debug info warn error).each do |m|
|
77
|
+
define_method(m) do |*args|
|
78
|
+
@devices.map { |d| d.send(m, *args) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class EventHub::Pidfile
|
2
|
+
attr_reader :file
|
3
|
+
def initialize(file)
|
4
|
+
@file = file
|
5
|
+
end
|
6
|
+
|
7
|
+
# write the pid to the file specified in the initializer
|
8
|
+
def write(pid)
|
9
|
+
FileUtils.makedirs(File.dirname(file))
|
10
|
+
IO.write(file, pid.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Try to delete file, ignore all errors
|
14
|
+
def delete
|
15
|
+
begin
|
16
|
+
File.delete(file)
|
17
|
+
rescue
|
18
|
+
# ignore
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|