sidekiq-grouping 1.0.4 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b21dbcb3c08b354b4b4d1fa16b51296643065f28
4
- data.tar.gz: 3f76b86a71c07ddd1ee2369140b14919ce2146ed
3
+ metadata.gz: df70f6272c6c489626dd612e2c736e5d1fbe2cad
4
+ data.tar.gz: 5a30ac65ae3e7a0b42d2b9633281990b8be84a86
5
5
  SHA512:
6
- metadata.gz: 195affc70d8b81426f784b114de856fb6f266a4ad28578d794c2db8ad5ff4d9b666aa2a9838e4f318834d38bdace4b4660d69df7946e1d8e976f7d7d9cd741c5
7
- data.tar.gz: 90bc4ec34b7155d85f9fe5663f1bc5536d214aafacba64a7564731c2e25c90d1dbc4056a3cf46fc7d99617ff3fc179be6193ff9b202464c38b70b0a18b901352
6
+ metadata.gz: a60255525e80b8911bfb72aec1067d67af644449554fdd04e1d448464bdbdb3fc6186b31ea665d4fa17fb8a836b0d3962d45384edf90d7f2c6ca462f6c4fe84a
7
+ data.tar.gz: 9ca2e704dcffffcacd45178343e7e824e45073a422f1bdcd70cb2f651d7e3bbb870aa3729cd386bfc6ffb2e31b7f95b6e843831833c7a59eb8468e472a386a48
@@ -0,0 +1,17 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ Include:
5
+ - ./Gemfile
6
+
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ Style/StringLiterals:
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/ClassAndModuleChildren:
14
+ EnforcedStyle: compact
15
+
16
+ RSpec/FilePath:
17
+ Enabled: false
@@ -1,24 +1,35 @@
1
- require 'active_support/core_ext/string'
2
- require 'active_support/configurable'
3
- require 'active_support/core_ext/numeric/time'
4
- require 'sidekiq/grouping/version'
1
+ require "active_support/core_ext/string"
2
+ require "active_support/configurable"
3
+ require "active_support/core_ext/numeric/time"
4
+ require "sidekiq/grouping/version"
5
+ require "concurrent"
5
6
 
6
- module Sidekiq
7
- module Grouping
8
- autoload :Config, 'sidekiq/grouping/config'
9
- autoload :Redis, 'sidekiq/grouping/redis'
10
- autoload :Batch, 'sidekiq/grouping/batch'
11
- autoload :Middleware, 'sidekiq/grouping/middleware'
12
- autoload :Logging, 'sidekiq/grouping/logging'
13
- autoload :Actor, 'sidekiq/grouping/actor'
14
- autoload :Supervisor, 'sidekiq/grouping/supervisor'
7
+ module Sidekiq::Grouping
8
+ autoload :Config, "sidekiq/grouping/config"
9
+ autoload :Redis, "sidekiq/grouping/redis"
10
+ autoload :Batch, "sidekiq/grouping/batch"
11
+ autoload :Middleware, "sidekiq/grouping/middleware"
12
+ autoload :Flusher, "sidekiq/grouping/flusher"
13
+ autoload :FlusherObserver, "sidekiq/grouping/flusher_observer"
15
14
 
16
- class << self
17
- attr_writer :logger
15
+ class << self
16
+ attr_writer :logger
18
17
 
19
- def logger
20
- @logger ||= Sidekiq.logger
21
- end
18
+ def logger
19
+ @logger ||= Sidekiq.logger
20
+ end
21
+
22
+ def start!
23
+ interval = Sidekiq::Grouping::Config.poll_interval
24
+ @observer = Sidekiq::Grouping::FlusherObserver.new
25
+ @task = Concurrent::TimerTask.new(
26
+ execution_interval: interval
27
+ ) { Sidekiq::Grouping::Flusher.new.flush }
28
+ @task.add_observer(@observer)
29
+ logger.info(
30
+ "[Sidekiq::Grouping] Started polling batches every #{interval} seconds"
31
+ )
32
+ @task.execute
22
33
  end
23
34
  end
24
35
  end
@@ -35,6 +46,4 @@ Sidekiq.configure_server do |config|
35
46
  end
36
47
  end
37
48
 
38
- if Sidekiq.server?
39
- Sidekiq::Grouping::Supervisor.run!
40
- end
49
+ Sidekiq::Grouping.start! if Sidekiq.server?
@@ -1,7 +1,6 @@
1
1
  module Sidekiq
2
2
  module Grouping
3
3
  class Batch
4
-
5
4
  def initialize(worker_class, queue, redis_pool = nil)
6
5
  @worker_class = worker_class
7
6
  @queue = queue
@@ -1,19 +1,15 @@
1
- module Sidekiq
2
- module Grouping
3
- module Config
4
- include ActiveSupport::Configurable
1
+ module Sidekiq::Grouping::Config
2
+ include ActiveSupport::Configurable
5
3
 
6
- # Queue size overflow check polling interval
7
- config_accessor :poll_interval
8
- self.config.poll_interval = 3
4
+ # Queue size overflow check polling interval
5
+ config_accessor :poll_interval
6
+ config.poll_interval = 3
9
7
 
10
- # Maximum batch size
11
- config_accessor :max_batch_size
12
- self.config.max_batch_size = 1000
8
+ # Maximum batch size
9
+ config_accessor :max_batch_size
10
+ config.max_batch_size = 1000
13
11
 
14
- # Batch queue flush lock timeout
15
- config_accessor :lock_ttl
16
- self.config.lock_ttl = 1
17
- end
18
- end
12
+ # Batch queue flush lock timeout
13
+ config_accessor :lock_ttl
14
+ config.lock_ttl = 1
19
15
  end
@@ -0,0 +1,20 @@
1
+ class Sidekiq::Grouping::Flusher
2
+ def flush
3
+ batches = Sidekiq::Grouping::Batch.all.map do |batch|
4
+ batch if batch.could_flush?
5
+ end
6
+ batches.compact!
7
+ flush_concrete(batches)
8
+ end
9
+
10
+ private
11
+
12
+ def flush_concrete(batches)
13
+ return if batches.empty?
14
+ names = batches.map { |batch| "#{batch.worker_class} in #{batch.queue}" }
15
+ Sidekiq::Grouping.logger.info(
16
+ "[Sidekiq::Grouping] Trying to flush batched queues: #{names.join(',')}"
17
+ )
18
+ batches.each(&:flush)
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ class Sidekiq::Grouping::FlusherObserver
2
+ def update(time, _result, ex)
3
+ if ex.is_a?(Concurrent::TimeoutError)
4
+ Sidekiq::Grouping.logger.error(
5
+ "[Sidekiq::Grouping] (#{time}) Execution timed out\n"
6
+ )
7
+ elsif ex.present?
8
+ Sidekiq::Grouping.logger.error(
9
+ "[Sidekiq::Grouping] Execution failed with error #{ex}\n"
10
+ )
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Grouping
3
- VERSION = '1.0.4'
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
@@ -1,14 +1,15 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'sidekiq/grouping/version'
3
+ require "sidekiq/grouping/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "sidekiq-grouping"
8
7
  spec.version = Sidekiq::Grouping::VERSION
9
8
  spec.authors = ["Victor Sokolov"]
10
9
  spec.email = ["gzigzigzeo@gmail.com"]
11
- spec.summary = %q{Allows identical sidekiq jobs to be processed with a single background call}
10
+ spec.summary = %q(
11
+ Allows identical sidekiq jobs to be processed with a single background call
12
+ )
12
13
  spec.homepage = "http://github.com/gzigzigzeo/sidekiq-grouping"
13
14
  spec.license = "MIT"
14
15
 
@@ -26,5 +27,5 @@ Gem::Specification.new do |spec|
26
27
  spec.add_development_dependency "timecop"
27
28
 
28
29
  spec.add_dependency "sidekiq"
29
- spec.add_dependency "celluloid"
30
+ spec.add_dependency "concurrent-ruby"
30
31
  end
@@ -1,22 +1,21 @@
1
1
  $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
2
2
 
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- require 'timecop'
6
- require 'simplecov'
7
- require 'celluloid/autostart'
8
- require 'sidekiq'
9
- require 'rspec-sidekiq'
10
- require 'support/test_workers'
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+ require "timecop"
6
+ require "simplecov"
7
+ require "sidekiq"
8
+ require "rspec-sidekiq"
9
+ require "support/test_workers"
11
10
 
12
11
  SimpleCov.start do
13
- add_filter 'spec'
12
+ add_filter "spec"
14
13
  end
15
14
 
16
- require 'sidekiq/grouping'
15
+ require "sidekiq/grouping"
17
16
 
18
17
  Sidekiq::Grouping.logger = nil
19
- Sidekiq.redis = { namespace: ENV['namespace'] }
18
+ Sidekiq.redis = { namespace: ENV["namespace"] }
20
19
  Sidekiq.logger = nil
21
20
 
22
21
  RSpec::Sidekiq.configure do |config|
@@ -31,7 +30,7 @@ RSpec.configure do |config|
31
30
 
32
31
  config.before :each do
33
32
  Sidekiq.redis do |conn|
34
- keys = conn.keys '*batching*'
33
+ keys = conn.keys "*batching*"
35
34
  keys.each { |key| conn.del key }
36
35
  end
37
36
  end
@@ -41,4 +40,4 @@ RSpec.configure do |config|
41
40
  end
42
41
  end
43
42
 
44
- $: << File.join(File.dirname(__FILE__), '..', 'lib')
43
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-grouping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Sokolov
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: celluloid
126
+ name: concurrent-ruby
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -144,19 +144,19 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".rubocop.yml"
147
148
  - ".travis.yml"
148
149
  - Gemfile
149
150
  - LICENSE.txt
150
151
  - README.md
151
152
  - Rakefile
152
153
  - lib/sidekiq/grouping.rb
153
- - lib/sidekiq/grouping/actor.rb
154
154
  - lib/sidekiq/grouping/batch.rb
155
155
  - lib/sidekiq/grouping/config.rb
156
- - lib/sidekiq/grouping/logging.rb
156
+ - lib/sidekiq/grouping/flusher.rb
157
+ - lib/sidekiq/grouping/flusher_observer.rb
157
158
  - lib/sidekiq/grouping/middleware.rb
158
159
  - lib/sidekiq/grouping/redis.rb
159
- - lib/sidekiq/grouping/supervisor.rb
160
160
  - lib/sidekiq/grouping/version.rb
161
161
  - lib/sidekiq/grouping/views/index.erb
162
162
  - lib/sidekiq/grouping/web.rb
@@ -1,47 +0,0 @@
1
- module Sidekiq
2
- module Grouping
3
- class Actor
4
- include Sidekiq::Grouping::Logging
5
- include ::Celluloid
6
-
7
- def initialize
8
- link_to_sidekiq_manager
9
- end
10
-
11
- private
12
-
13
- def start_polling
14
- interval = Sidekiq::Grouping::Config.poll_interval
15
- info "Start polling of queue batches every #{interval} seconds"
16
- every(interval) { flush_batches }
17
- end
18
-
19
- def flush_batches
20
- batches = []
21
-
22
- Sidekiq::Grouping::Batch.all.map do |batch|
23
- if batch.could_flush?
24
- batches << batch
25
- end
26
- end
27
-
28
- flush(batches)
29
- end
30
-
31
- def link_to_sidekiq_manager
32
- start_polling
33
- rescue
34
- info "Can't link #{self.class.name}. Sidekiq::Manager not running. Retrying in 5 seconds ..."
35
- after(5) { link_to_sidekiq_manager }
36
- end
37
-
38
- def flush(batches)
39
- if batches.any?
40
- names = batches.map { |batch| "#{batch.worker_class} in #{batch.queue}" }
41
- info "Trying to flush batched queues: #{names.join(',')}"
42
- batches.each { |batch| batch.flush }
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,13 +0,0 @@
1
- module Sidekiq
2
- module Grouping
3
- module Logging
4
- %w(fatal error warn info debug).each do |level|
5
- level = level.to_sym
6
-
7
- define_method(level) do |msg|
8
- Sidekiq::Grouping.logger.public_send(level, "[Sidekiq::Grouping] #{msg}")
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- require 'celluloid/current' unless defined?(Celluloid)
2
-
3
- module Sidekiq
4
- module Grouping
5
- module Supervisor
6
- class << self
7
- include Sidekiq::Grouping::Logging
8
-
9
- if Celluloid::VERSION >= '0.17'
10
- def run!
11
- info 'Sidekiq::Grouping starts supervision'
12
- Sidekiq::Grouping::Actor.supervise as: :sidekiq_grouping
13
- end
14
- else
15
- def run!
16
- info 'Sidekiq::Grouping starts supervision'
17
- Sidekiq::Grouping::Actor.supervise_as(:sidekiq_grouping)
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end