omf_common 6.1.3.pre.1 → 6.1.3.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/lib/omf_common/comm/amqp/amqp_communicator.rb +7 -10
- data/lib/omf_common/comm/xmpp/communicator.rb +15 -2
- data/lib/omf_common.rb +97 -9
- data/omf_common.gemspec +0 -1
- metadata +2 -18
data/Gemfile
CHANGED
@@ -127,17 +127,14 @@ module OmfCommon
|
|
127
127
|
begin
|
128
128
|
last_reported_timestamp = nil
|
129
129
|
@session = ::AMQP.connect(@url, @opts) do |connection|
|
130
|
-
connection.
|
131
|
-
|
130
|
+
connection.on_tcp_connection_loss do |conn, settings|
|
131
|
+
now = Time.now
|
132
|
+
if last_reported_timestamp == nil || (now - last_reported_timestamp) > 60
|
133
|
+
warn "Lost connectivity. Trying to reconnect..."
|
134
|
+
last_reported_timestamp = now
|
135
|
+
end
|
136
|
+
_reconnect(conn)
|
132
137
|
end
|
133
|
-
#connection.on_tcp_connection_loss do |conn, settings|
|
134
|
-
# now = Time.now
|
135
|
-
# if last_reported_timestamp == nil || (now - last_reported_timestamp) > 60
|
136
|
-
# warn "Lost connectivity. Trying to reconnect..."
|
137
|
-
# last_reported_timestamp = now
|
138
|
-
# end
|
139
|
-
# _reconnect(conn)
|
140
|
-
#end
|
141
138
|
@channel = ::AMQP::Channel.new(connection)
|
142
139
|
@channel.auto_recovery = true
|
143
140
|
|
@@ -3,8 +3,21 @@
|
|
3
3
|
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
4
|
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
5
|
|
6
|
-
|
7
|
-
require 'blather
|
6
|
+
begin
|
7
|
+
require 'blather'
|
8
|
+
require 'blather/client/dsl'
|
9
|
+
rescue LoadError => e
|
10
|
+
error <<-ERR
|
11
|
+
#{e.message}
|
12
|
+
|
13
|
+
# Looks like you are trying to use XMPP as your communication protocol but you have not installed XMPP library 'blather'
|
14
|
+
#
|
15
|
+
# To correct this, install blather. E.g.
|
16
|
+
#
|
17
|
+
# gem install blather
|
18
|
+
ERR
|
19
|
+
exit(1)
|
20
|
+
end
|
8
21
|
|
9
22
|
require 'omf_common/comm/xmpp/xmpp_mp'
|
10
23
|
require 'omf_common/comm/xmpp/topic'
|
data/lib/omf_common.rb
CHANGED
@@ -17,6 +17,8 @@ require 'omf_common/auth'
|
|
17
17
|
require 'omf_common/core_ext/string'
|
18
18
|
require 'omf_common/eventloop'
|
19
19
|
|
20
|
+
require 'oml4r/logging/oml4r_appender'
|
21
|
+
|
20
22
|
include OmfCommon::DefaultLogging
|
21
23
|
|
22
24
|
# Set the default encoding to UTF8
|
@@ -132,15 +134,54 @@ module OmfCommon
|
|
132
134
|
}
|
133
135
|
}
|
134
136
|
|
137
|
+
# Initialise the OMF runtime.
|
138
|
+
#
|
139
|
+
# The options here can be customised via EC or RC's configuration files.
|
140
|
+
#
|
141
|
+
# Given the following example EC configuration file (YAML format):
|
142
|
+
#
|
143
|
+
# environment: development
|
144
|
+
# communication:
|
145
|
+
# url: amqp://localhost
|
146
|
+
#
|
147
|
+
# OMF runtime will be configured as:
|
148
|
+
#
|
149
|
+
# OmfCommon.init(:development, { communication: { url: "amqp://localhost" }})
|
150
|
+
#
|
151
|
+
#
|
152
|
+
# @example Use AMQP for communication in :development mode
|
153
|
+
#
|
154
|
+
# OmfCommon.init(:development, { communication: { url: "amqp://localhost" }})
|
155
|
+
#
|
156
|
+
# @example Change Logging configuration
|
135
157
|
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
158
|
+
# options = {
|
159
|
+
# communication: { url: "amqp://localhost" },
|
160
|
+
# logging: {
|
161
|
+
# level: { default: 'debug' },
|
162
|
+
# appenders: {
|
163
|
+
# stdout: {
|
164
|
+
# level: :info,
|
165
|
+
# date_pattern: '%H:%M:%S',
|
166
|
+
# pattern: '%d %5l %c{2}: %m\n'
|
167
|
+
# },
|
168
|
+
# rolling_file: {
|
169
|
+
# level: :debug,
|
170
|
+
# log_dir: '/var/tmp',
|
171
|
+
# size: 1024*1024*50, # max 50mb of each log file
|
172
|
+
# keep: 5, # keep a 5 logs in total
|
173
|
+
# date_pattern: '%F %T %z',
|
174
|
+
# pattern: '[%d] %-5l %c: %m\n'
|
175
|
+
# },
|
176
|
+
# }
|
177
|
+
# }
|
178
|
+
# }
|
143
179
|
#
|
180
|
+
# OmfCommon.init(:development, options)
|
181
|
+
#
|
182
|
+
# @see _init_logging
|
183
|
+
#
|
184
|
+
# @param [Symbol] op_mode
|
144
185
|
# @param [Hash] opts
|
145
186
|
#
|
146
187
|
def self.init(op_mode, opts = {}, &block)
|
@@ -245,8 +286,49 @@ module OmfCommon
|
|
245
286
|
yh
|
246
287
|
end
|
247
288
|
|
248
|
-
# DO NOT CALL DIRECTLY
|
289
|
+
# DO NOT CALL THIS METHOD DIRECTLY
|
290
|
+
#
|
291
|
+
# By providing logging section via init method, you could custom how logging messages could be written.
|
292
|
+
#
|
293
|
+
# @example Change default logging level to :default, but :info under OmfEc namespace
|
294
|
+
#
|
295
|
+
# {
|
296
|
+
# logging: {
|
297
|
+
# level: { default: 'debug', 'OmfEc' => 'info' }
|
298
|
+
# }
|
299
|
+
# }
|
249
300
|
#
|
301
|
+
# @example Write logging message to STDOUT, OML, and ROLLING_FILE
|
302
|
+
# {
|
303
|
+
# logging: {
|
304
|
+
# level: { default: 'debug' }, # root logger set to level :debug
|
305
|
+
# appenders: {
|
306
|
+
# stdout: {
|
307
|
+
# level: :info,
|
308
|
+
# date_pattern: '%H:%M:%S', # show hours, mintues, seconds
|
309
|
+
# pattern: '%d %5l %c{2}: %m\n' # show date time, logging level, namespace/class
|
310
|
+
# },
|
311
|
+
# rolling_file: {
|
312
|
+
# level: :debug,
|
313
|
+
# log_dir: '/var/tmp', # files go to /var/tmp
|
314
|
+
# log_file: 'bob', # name of file
|
315
|
+
# size: 1024*1024*50, # max 50mb of each log file
|
316
|
+
# keep: 5, # keep a 5 logs in total
|
317
|
+
# date_pattern: '%F %T %z', # shows date, time, timezone
|
318
|
+
# pattern: '[%d] %-5l %c: %m\n'
|
319
|
+
# },
|
320
|
+
# oml4r: {
|
321
|
+
# appName: 'bob', # OML appName
|
322
|
+
# domain: 'bob_2345', # OML domain (database name)
|
323
|
+
# collect: 'tcp:localhost:3003' # OML server
|
324
|
+
# }
|
325
|
+
# }
|
326
|
+
# }
|
327
|
+
# }
|
328
|
+
#
|
329
|
+
# @note OmfCommon now ONLY provides support for STDOUT, OML, FILE, and ROLLING_FILE.
|
330
|
+
#
|
331
|
+
# @param [Hash] opts
|
250
332
|
def self._init_logging(opts = {})
|
251
333
|
logger = Logging.logger.root
|
252
334
|
|
@@ -275,7 +357,11 @@ module OmfCommon
|
|
275
357
|
date_method: topts.delete(:date_method)
|
276
358
|
}
|
277
359
|
|
278
|
-
|
360
|
+
if pattern_opts[:pattern]
|
361
|
+
appender_opts = topts.merge(layout: Logging.layouts.pattern(pattern_opts))
|
362
|
+
else
|
363
|
+
appender_opts = topts
|
364
|
+
end
|
279
365
|
|
280
366
|
case type.to_sym
|
281
367
|
when :stdout
|
@@ -286,6 +372,8 @@ module OmfCommon
|
|
286
372
|
file_name = topts.delete(:log_file) || "#{File.basename($0, File.extname($0))}.log"
|
287
373
|
path = File.join(dir_name, file_name)
|
288
374
|
logger.add_appenders(Logging.appenders.send(type, path, appender_opts))
|
375
|
+
when :oml4r
|
376
|
+
logger.add_appenders(Logging.appenders.oml4r('oml4r', appender_opts))
|
289
377
|
else
|
290
378
|
raise "Unknown logging appender type '#{type}'"
|
291
379
|
end
|
data/omf_common.gemspec
CHANGED
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency "mocha"
|
29
29
|
|
30
30
|
s.add_runtime_dependency "eventmachine"
|
31
|
-
s.add_runtime_dependency "blather"
|
32
31
|
s.add_runtime_dependency "logging"
|
33
32
|
s.add_runtime_dependency "hashie"
|
34
33
|
s.add_runtime_dependency "oml4r", "~> 2.10.1"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.3.pre.
|
4
|
+
version: 6.1.3.pre.2
|
5
5
|
prerelease: 6
|
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: 2014-07-
|
12
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -107,22 +107,6 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: blather
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
110
|
- !ruby/object:Gem::Dependency
|
127
111
|
name: logging
|
128
112
|
requirement: !ruby/object:Gem::Requirement
|