checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA256:
3
- metadata.gz: 8013e20dadb47994367e66c8bdbed92b6a0abf8d571d3bc6b7071d511dfe82b5
4
- data.tar.gz: c6a9d958fb78125df046ad404093b3f41cde5fe5401a2dfc9a2cef79dc572779
3
+ metadata.gz: 7a9131278d68746096c17ea16bd644f4dd043afcae8d20904e960a0d6d7cb7bc
4
+ data.tar.gz: b5894f6abb499eb92aaac11ab7c7b1acd62f7da1ac1f42681a8693b6fbc64572
5
5
SHA512:
6
- metadata.gz: 81e265582b9f338f7e2ef4c1ba206130b6759544a0b0ecc009ebb3b5154c6389458f7aa61b94bbac9e3b7f1d0febde08d45551ac06bf5d4289cdec398ae5e188
7
- data.tar.gz: 631c33cbbbc9ecfb9f6f72ebe29b74ac040ed0c99f500a62e4e38ac1b7e1f37bd79edaf424ee2d78144f31d5f8efece27f4401b8245d8091b6e82a0fab7faf4f
6
+ metadata.gz: cd25ecc4856efaa674bf4855cdf417ce66c173d8d520ca94d63c9ea9d343d4e0947db93b5e2300c63b84ee985bf8877ba74c6eb1affc5b23afbe6a5b7e04c853
7
+ data.tar.gz: 5ec609ea9aaec81c856ea477956ec3df8f73a99b7885d622d4a501bc97482aa5dd528235a411741ac5b0092ec7b162caf8bc7df38834d3768af63a177712f466
data/lib/sidekiq/haron/client_middleware.rb CHANGED
@@ -1,10 +1,14 @@
1
- class Sidekiq::Haron::ClientMiddleware
1
+ module Sidekiq
2
+ module Haron
3
+ class ClientMiddleware
4
+
5
+ def call(worker_class, msg, queue, redis_pool=nil)
6
+ if msg['retry_count'].blank? # don't store on retry
7
+ Sidekiq::Haron.transmitter.save(worker_class, msg, queue, redis_pool)
8
+ end
9
+ yield
10
+ end
2
11
3
- def call(worker_class, msg, queue, redis_pool=nil)
4
- if msg['retry_count'].blank? # don't store on retry
5
- Sidekiq::Haron.transmitter.save(worker_class, msg, queue, redis_pool)
6
12
end
7
- yield
8
13
end
9
-
10
14
end
data/lib/sidekiq/haron/exception_logger.rb CHANGED
@@ -1,15 +1,19 @@
1
1
require 'sidekiq/exception_handler'
2
- class Sidekiq::Haron::ExceptionLogger < Sidekiq::ExceptionHandler::Logger
2
+ module Sidekiq
3
+ module Haron
4
+ class ExceptionLogger < Sidekiq::ExceptionHandler::Logger
3
5
4
- def self.install
5
- Sidekiq.error_handlers.delete_if{|eh| eh.is_a? Sidekiq::ExceptionHandler::Logger }
6
- Sidekiq.error_handlers.unshift Sidekiq::Haron::ExceptionLogger.new
7
- end
6
+ def self.install
7
+ Sidekiq.error_handlers.delete_if{|eh| eh.is_a? Sidekiq::ExceptionHandler::Logger }
8
+ Sidekiq.error_handlers.unshift Sidekiq::Haron::ExceptionLogger.new
9
+ end
8
10
9
- def call(ex, ctxHash)
10
- jid = ctxHash.present? && ctxHash[:job]['jid']
11
- Sidekiq::Haron.transmitter.load(jid) if jid.present?
12
- Sidekiq::Haron.transmitter.tagged{ super(ex, ctxHash) }
13
- end
11
+ def call(ex, ctxHash)
12
+ jid = ctxHash.present? && ctxHash[:job]['jid']
13
+ Sidekiq::Haron.transmitter.load(jid) if jid.present?
14
+ Sidekiq::Haron.transmitter.tagged{ super(ex, ctxHash) }
15
+ end
14
16
17
+ end
18
+ end
15
19
end
data/lib/sidekiq/haron/formatter.rb CHANGED
@@ -1,12 +1,16 @@
1
- class Sidekiq::Haron::Formatter < Sidekiq::Logging::Pretty
1
+ module Sidekiq
2
+ module Haron
3
+ class Formatter < Sidekiq::Logging::Pretty
2
4
3
- def call(severity, time, program_name, message)
4
- result = "#{context} #{severity.to_s[0]}: #{message}\n"
5
- if ENV['RAILS_LOG_TO_STDOUT'].present?
6
- result
7
- else
8
- "#{time.utc.iso8601(3)} #{result}"
5
+ def call(severity, time, program_name, message)
6
+ result = "#{context} #{severity.to_s[0]}: #{message}\n"
7
+ if ENV['RAILS_LOG_TO_STDOUT'].present?
8
+ result
9
+ else
10
+ "#{time.utc.iso8601(3)} #{result}"
11
+ end
12
+ end
13
+
9
14
end
10
15
end
11
-
12
16
end
data/lib/sidekiq/haron/job_logger.rb CHANGED
@@ -1,12 +1,16 @@
1
1
require 'sidekiq/job_logger'
2
- class Sidekiq::Haron::JobLogger < Sidekiq::JobLogger
2
+ module Sidekiq
3
+ module Haron
4
+ class JobLogger < Sidekiq::JobLogger
3
5
4
- def call(item, queue)
5
- Sidekiq::Haron.transmitter.load(item['jid'])
6
- Sidekiq::Haron.transmitter.tagged do
7
- Sidekiq.logger.info("with args #{item['args'].inspect}")
8
- super
6
+ def call(item, queue)
7
+ Sidekiq::Haron.transmitter.load(item['jid'])
8
+ Sidekiq::Haron.transmitter.tagged do
9
+ Sidekiq.logger.info("with args #{item['args'].inspect}")
10
+ super
11
+ end
12
+ end
13
+
9
14
end
10
15
end
11
-
12
16
end
data/lib/sidekiq/haron/server_middleware.rb CHANGED
@@ -1,8 +1,12 @@
1
- class Sidekiq::Haron::ServerMiddleware
1
+ module Sidekiq
2
+ module Haron
3
+ class ServerMiddleware
2
4
3
- def call(worker, msg, queue)
4
- Sidekiq::Haron.transmitter.load(msg['jid'])
5
- yield
6
- end
5
+ def call(worker, msg, queue)
6
+ Sidekiq::Haron.transmitter.load(msg['jid'])
7
+ yield
8
+ end
7
9
10
+ end
11
+ end
8
12
end
data/lib/sidekiq/haron/storage.rb CHANGED
@@ -1,38 +1,43 @@
1
- module Sidekiq::Haron::Storage
2
- DEFAULT_EXPIRY = 30 * 24 * 60 * 60 # 30 days
1
+ module Sidekiq
2
+ module Haron
3
+ module Storage
3
4
4
- protected
5
+ DEFAULT_EXPIRY = 30 * 24 * 60 * 60 # 30 days
5
6
6
- def store_for_id(id, data, redis_pool=nil)
7
+ protected
7
- redis_connection(redis_pool) do |conn|
8
- conn.multi do
9
- conn.hmset key(id), *(data.to_a.flatten(1))
10
- conn.expire key(id), DEFAULT_EXPIRY
11
- end[0]
12
- end
13
- end
14
8
15
- def read_for_id(id)
16
- Sidekiq.redis do |conn|
17
- conn.hgetall(key(id))
18
- end
19
- end
9
+ def store_for_id(id, data, redis_pool=nil)
10
+ redis_connection(redis_pool) do |conn|
11
+ conn.multi do
12
+ conn.hmset key(id), *(data.to_a.flatten(1))
13
+ conn.expire key(id), DEFAULT_EXPIRY
14
+ end[0]
15
+ end
16
+ end
20
17
21
- private
18
+ def read_for_id(id)
19
+ Sidekiq.redis do |conn|
20
+ conn.hgetall(key(id))
21
+ end
22
+ end
23
+
24
+ private
22
25
23
- def redis_connection(redis_pool=nil)
24
- if redis_pool
25
- redis_pool.with do |conn|
26
- yield conn
26
+ def redis_connection(redis_pool=nil)
27
+ if redis_pool
28
+ redis_pool.with do |conn|
29
+ yield conn
30
+ end
31
+ else
32
+ Sidekiq.redis do |conn|
33
+ yield conn
34
+ end
35
+ end
27
36
end
28
- else
29
- Sidekiq.redis do |conn|
30
- yield conn
37
+
38
+ def key(id)
39
+ "sidekiq:haron:#{id}"
31
40
end
32
41
end
33
42
end
34
-
35
- def key(id)
36
- "sidekiq:haron:#{id}"
37
- end
38
43
end
data/lib/sidekiq/haron/transmitter.rb CHANGED
@@ -1,39 +1,43 @@
1
- class Sidekiq::Haron::Transmitter
2
- include Sidekiq::Haron::Storage
1
+ module Sidekiq
2
+ module Haron
3
+ class Transmitter
4
+ include Sidekiq::Haron::Storage
5
+
6
+ def save worker_class, msg, queue, redis_pool
7
+ data = saved_data(worker_class, msg, queue)
8
+ store_for_id msg['jid'], data, redis_pool
9
+ end
3
10
4
- def save worker_class, msg, queue, redis_pool
5
- data = saved_data(worker_class, msg, queue)
6
- store_for_id msg['jid'], data, redis_pool
7
- end
11
+ def load jid
12
+ load_data read_for_id(jid)
13
+ rescue => e
14
+ Sidekiq.logger.error "loading data error - #{e.to_s}"
15
+ {}
16
+ end
8
17
9
- def load jid
10
- load_data read_for_id(jid)
11
- rescue => e
12
- Sidekiq.logger.error "loading data error - #{e.to_s}"
13
- {}
14
- end
18
+ def tagged
19
+ Rails.logger.tagged(tags) do
20
+ Sidekiq.logger.tagged(tags) do
21
+ yield
22
+ end
23
+ end
15
24
16
- def tagged
17
- Rails.logger.tagged(tags) do
18
- Sidekiq.logger.tagged(tags) do
19
- yield
20
25
end
21
- end
22
26
23
- end
27
+ def tags
28
+ []
29
+ end
24
30
25
- def tags
31
+ private
26
- []
27
- end
28
32
29
- private
33
+ def saved_data
34
+ raise NotImplemented
35
+ end
30
36
31
- def saved_data
32
- raise NotImplemented
33
- end
37
+ def load_data
38
+ raise NotImplemented
39
+ end
34
40
35
- def load_data
41
+ end
36
- raise NotImplemented
37
42
end
38
-
39
43
end
data/lib/sidekiq/haron/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
module Sidekiq
2
2
module Haron
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
end
5
5
end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
--- !ruby/object:Gem::Specification
2
2
name: sidekiq-haron
3
3
version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
platform: ruby
6
6
authors:
7
7
- Serg F