ocular 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d45b8d9465be93f0f27f5819c758ebac6452a39
4
- data.tar.gz: 65ad1e3578826f806d62da568436412fe57b9fd9
3
+ metadata.gz: f6b417bff05762b7e15a5dcc2dad418b5e31b224
4
+ data.tar.gz: fc7391ab1ac121832c29627712830a1447bca5e8
5
5
  SHA512:
6
- metadata.gz: 121bd72c23beabb03efa9c31515677bcc26a1f865b27eb689f4f7d4f1b0d9a8de9f5a6aae2885b5d99468a174a4d51e0b43b1bf2be1a8c5945d1cc74da526216
7
- data.tar.gz: b944c036054b6c237fc6a3a8e76ae31acb2090f5cf1a64b99b301dbc8411405ed706c23cbe03a2716a787328188142f68cc3b21a36487afd1abe29f8f3b604fd
6
+ metadata.gz: 7b2d2092d6d8391456907c4323cd636bc73746840865c91fbbf5caff9ef6c12f04f1674993065d7fd0a1490e7f64d2a37812b6e71e230b352df4749c56881b78
7
+ data.tar.gz: 26d6329a5b56c07807e8125f6c3a9874c76721d71bd04d1bd64e5408a75262a87e75be2824c34ab06a76b39a904458b04538c57742fcc769e2cf8b14e88be84a
data/bin/ocular CHANGED
@@ -4,7 +4,7 @@ require 'ocular'
4
4
  require 'optparse'
5
5
  require 'ostruct'
6
6
  require 'pp'
7
-
7
+ require 'logger'
8
8
 
9
9
  class OptparseExample
10
10
 
@@ -590,7 +590,7 @@ class Ocular
590
590
 
591
591
  @thread = Thread.new do
592
592
  events_hander = @settings[:silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
593
- server = ::Puma::Server.new(self, events_hander)
593
+ server = ::Puma::Server.new(self, events_hander)
594
594
 
595
595
  server.add_tcp_listener @settings[:host], @settings[:port]
596
596
  server.min_threads = 0
@@ -1,5 +1,7 @@
1
1
  require "kafka"
2
2
  require "socket"
3
+ require "logger"
4
+ require "thread"
3
5
 
4
6
  class Ocular
5
7
  module Logging
@@ -14,16 +16,22 @@ class Ocular
14
16
  if kafka != nil
15
17
  @kafka = kafka
16
18
  else
17
- pp settings
19
+ #logger = Logger.new(STDOUT)
20
+ #logger.level = Logger::DEBUG
21
+ #settings[:client][:logger] = logger
18
22
  @kafka = Kafka.new(settings[:client])
19
23
  end
20
24
  @settings = settings
21
25
 
22
26
  @producer = @kafka.producer
27
+
28
+ @semaphore = Mutex.new
23
29
  end
24
30
 
25
31
  def reconnect()
26
32
  @kafka = Kafka.new(@settings[:client])
33
+ @producer = @kafka.producer
34
+ @semaphore = Mutex.new
27
35
  end
28
36
 
29
37
  def debug(message = nil, &block)
@@ -47,6 +55,10 @@ class Ocular
47
55
  add(Severity::FATAL, message, @run_id, &block)
48
56
  end
49
57
 
58
+ def deliver_messages
59
+ @producer.deliver_messages
60
+ end
61
+
50
62
  def add(severity, message = nil, run_id = nil, &block)
51
63
  severity ||= Severity::UNKNOWN
52
64
  if severity < @level
@@ -62,8 +74,10 @@ class Ocular
62
74
  end
63
75
 
64
76
  begin
65
- @producer.produce(@formatter.format_message(severity, Time.now, run_id, message), topic: @settings[:topic], partition_key: run_id)
66
- @producer.deliver_messages
77
+ @semaphore.synchronize do
78
+ @producer.produce(@formatter.format_message(severity, Time.now, run_id, message), topic: @settings[:topic], partition_key: run_id)
79
+ deliver_messages()
80
+ end
67
81
  rescue StandardError => e
68
82
  STDERR.puts "Error on producing kafka message: #{e}"
69
83
  STDERR.puts "Message was #{message}, stacktrace: #{e.backtrace.join("\n")}"
@@ -72,8 +86,10 @@ class Ocular
72
86
 
73
87
  def log_event(property, value, run_id = nil)
74
88
  begin
75
- @producer.produce(@formatter.format_event(property, value, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
76
- @producer.deliver_messages
89
+ @semaphore.synchronize do
90
+ @producer.produce(@formatter.format_event(property, value, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
91
+ deliver_messages()
92
+ end
77
93
  rescue StandardError => e
78
94
  STDERR.puts "Error on producing kafka log_event: #{e}"
79
95
  STDERR.puts "#{property} => #{value}, stacktrace: #{e.backtrace.join("\n")}"
@@ -82,8 +98,10 @@ class Ocular
82
98
 
83
99
  def log_cause(type, environment, run_id = nil)
84
100
  begin
85
- @producer.produce(@formatter.format_cause(type, environment, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
86
- @producer.deliver_messages
101
+ @semaphore.synchronize do
102
+ @producer.produce(@formatter.format_cause(type, environment, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
103
+ deliver_messages()
104
+ end
87
105
  rescue StandardError => e
88
106
  STDERR.puts "Error on producing kafka log_cause: #{e}"
89
107
  STDERR.puts "type: #{type}, stacktrace: #{e.backtrace.join("\n")}"
@@ -93,8 +111,10 @@ class Ocular
93
111
 
94
112
  def log_timing(key, value, run_id = nil)
95
113
  begin
96
- @producer.produce(@formatter.format_event("timing:" + key, value, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
97
- @producer.deliver_messages
114
+ @semaphore.synchronize do
115
+ @producer.produce(@formatter.format_event("timing:" + key, value, Time.now, run_id), topic: @settings[:topic], partition_key: run_id)
116
+ deliver_messages()
117
+ end
98
118
  rescue StandardError => e
99
119
  STDERR.puts "Error on producing kafka log_timing: #{e}"
100
120
  STDERR.puts "Timing: #{key} => #{value}, stacktrace: #{e.backtrace.join("\n")}"
@@ -1,3 +1,3 @@
1
1
  class Ocular
2
- Version = "0.2.5"
2
+ Version = "0.2.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juho Mäkinen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rye
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.3.2
131
+ version: 0.3.15
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.3.2
138
+ version: 0.3.15
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: mysql2
141
141
  requirement: !ruby/object:Gem::Requirement