Skip to content

Commit

Permalink
Merge latest master from gzigzigzeo/sidekiq-grouping (#6)
Browse files Browse the repository at this point in the history
* fix mistype: elasic -> elastic

* fix require active_support

* fix deprecation warnings about redis multi

* Version bump

* readme: add gem version badge

* pass args to worker as array in inline mode

* Optimized Lua script for Redis >= 6.2.0

* Remove trailing spaces

* Use sadd? to remove warning message

* Fixes sidekiq deprecation

* chore: Configure Rubocop and fix all lint issues

Signed-off-by: Valentin Kiselev <[email protected]>

* ci: Add test github action

Signed-off-by: Valentin Kiselev <[email protected]>

* ci: Add lint github action

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: YAML fix

* ci: Fix redis service ports mapping

Signed-off-by: Valentin Kiselev <[email protected]>

* fix: Remove occasional fix for interval

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Add lefthook configuration

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Remove Travis config

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Appraise setting

Signed-off-by: Valentin Kiselev <[email protected]>

* fix: Fix tests

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Apply rubocop settings

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Bump version upto 1.2.0

Signed-off-by: Valentin Kiselev <[email protected]>

* ci: Remove jruby from matrix

Signed-off-by: Valentin Kiselev <[email protected]>

* fix: Use more verbose var name

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Run tests before pushing

Signed-off-by: Valentin Kiselev <[email protected]>

* feature: Support Sidekiq 7

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Fix rubocop issues

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Bump version

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Update lefthook.yml

Signed-off-by: Valentin Kiselev <[email protected]>

* chore: Update lefthook.yml

Signed-off-by: Valentin Kiselev <[email protected]>

* Fix rubocop

* Add Ruby 3.3

* Set fail-fast: false

* Move fail-fast inside strategy

---------

Signed-off-by: Valentin Kiselev <[email protected]>
Co-authored-by: Staskov Sergey <[email protected]>
Co-authored-by: Grey Moore <[email protected]>
Co-authored-by: Victor Sokolov <[email protected]>
Co-authored-by: Vladimir Dementyev <[email protected]>
Co-authored-by: Egor Lukin <[email protected]>
Co-authored-by: russointroitoa <[email protected]>
Co-authored-by: Ross-Hunter <[email protected]>
Co-authored-by: Valentin Kiselev <[email protected]>
  • Loading branch information
9 people authored Jan 7, 2025
1 parent cd446d5 commit 3e27904
Show file tree
Hide file tree
Showing 28 changed files with 784 additions and 334 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Lint
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Ruby ${{ matrix.ruby_version }}
uses: ruby/setup-ruby@v1
with:
bundler: 2
ruby-version: 2.7

- uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ matrix.ruby-version }}-${{ hashFiles('./*.gemspec') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Run Rubocop
run: bundle exec rubocop
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
rspec:
name: Rspec
runs-on: ubuntu-latest
services:
redis:
image: redis:6
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
include:
- { ruby_version: 2.7 }
- { ruby_version: 3.0 }
- { ruby_version: 3.1 }
- { ruby_version: 3.3 }
steps:
- uses: actions/checkout@v3

- name: Set up Ruby ${{ matrix.ruby_version }}
uses: ruby/setup-ruby@v1
with:
bundler: 2
ruby-version: ${{ matrix.ruby_version }}

# Appraisal doesn't support vendored install
# See: https://github.com/thoughtbot/appraisal/issues/173
# https://github.com/thoughtbot/appraisal/pull/174
- name: Bundle install
run: |
bundle install --jobs 4 --retry 3
bundle exec appraisal install
- name: Run tests
run: bundle exec appraisal rspec
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ spec/reports
test/tmp
test/version_tmp
tmp
.lefthook-local.yml
.idea
77 changes: 74 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,88 @@
---
require: rubocop-rspec

AllCops:
TargetRubyVersion: 2.7.0
SuggestExtensions: false
NewCops: enable
Include:
- ./Gemfile
- ./Rakefile
- '*.gemspec'
- '**/*.rb'

Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/ClassAndModuleChildren:
EnforcedStyle: compact
RSpec/ExampleLength:
Enabled: false

RSpec/AnyInstance:
Enabled: false

RSpec/SpecFilePathFormat:
Enabled: false

RSpec/NamedSubject:
Enabled: false

RSpec/ContextWording:
Enabled: false

RSpec/RepeatedExampleGroupDescription:
Enabled: false

RSpec/NestedGroups:
Enabled: false

RSpec/FilePath:
RSpec/MultipleExpectations:
Enabled: false

RSpec/ExampleWording:
Enabled: false

Metrics/MethodLength:
Max: 15
Exclude:
- 'lib/sidekiq/grouping/flusher.rb'
- 'lib/sidekiq/grouping/middleware.rb'
- 'lib/sidekiq/grouping/batch.rb'

Metrics/ClassLength:
Max: 150

Metrics/AbcSize:
Exclude:
- 'lib/sidekiq/grouping/flusher.rb'
- 'lib/sidekiq/grouping/middleware.rb'
- 'spec/modules/batch_spec.rb'

Metrics/CyclomaticComplexity:
Exclude:
- 'lib/sidekiq/grouping/flusher.rb'
- 'lib/sidekiq/grouping/middleware.rb'

Metrics/PerceivedComplexity:
Exclude:
- 'lib/sidekiq/grouping/middleware.rb'

Layout/LineLength:
Max: 90
Exclude:
- 'lib/sidekiq/grouping/flusher.rb'
- 'lib/sidekiq/grouping/web.rb'

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent

Layout/FirstMethodArgumentLineBreak:
Enabled: true

Layout/MultilineMethodArgumentLineBreaks:
Enabled: true

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ appraise 'sidekiq-5.0' do
gem 'sidekiq', '~> 5.0.0'
end

appraise 'sidekiq-6.0' do
gem 'sidekiq', '~> 6.0.0'
end

appraise 'sidekiq-6.5' do
gem 'sidekiq', '~> 6.5.0'
end

appraise 'sidekiq-7.0' do
gem 'sidekiq', '~> 7.0.0'
end

appraise 'sidekiq-master' do
gem 'sidekiq', github: 'mperham/sidekiq'
end
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Gem Version](https://badge.fury.io/rb/sidekiq-grouping.svg)](https://rubygems.org/gems/sidekiq-grouping)

# Sidekiq::Grouping

<a href="https://evilmartians.com/?utm_source=sidekiq-grouping-gem">
Expand All @@ -23,7 +25,7 @@ class ElasticBulkIndexWorker
include Sidekiq::Worker

sidekiq_options(
queue: :elasic_bulks,
queue: :elastic_bulks,
batch_flush_size: 30, # Jobs will be combined when queue size exceeds 30
batch_flush_interval: 60, # Jobs will be combined every 60 seconds
retry: 5
Expand Down
8 changes: 8 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sidekiq/grouping"

require "pry"
Pry.start
7 changes: 7 additions & 0 deletions gemfiles/sidekiq_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sidekiq", "~> 6.0.0"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/sidekiq_6.5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sidekiq", "~> 6.5.0"

gemspec path: "../"
7 changes: 7 additions & 0 deletions gemfiles/sidekiq_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sidekiq", "~> 7.0.0"

gemspec path: "../"
20 changes: 20 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Git hooks configuration
#
# See: github.com/evilmartians/lefthook

pre-commit:
parallel: true
commands:
appraisal:
glob: "{Appraisals,*.gemfile}"
run: echo {staged_files} > /dev/null; bundle exec appraisal install && git add gemfiles/*.gemfile
rubocop:
glob: "{*.rb,*.gemspec,Gemfile,Rakefile}"
run: bundle exec rubocop -A {staged_files} && git add {staged_files}

pre-push:
commands:
rspec:
glob: "*.rb"
run: echo {push_files} > /dev/null; bundle exec appraisal rspec
59 changes: 33 additions & 26 deletions lib/sidekiq/grouping.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/string"
require "active_support/configurable"
require "active_support/core_ext/numeric/time"
require "sidekiq"
require "sidekiq/grouping/version"
require "concurrent"

module Sidekiq::Grouping
autoload :Config, "sidekiq/grouping/config"
autoload :Redis, "sidekiq/grouping/redis"
autoload :Batch, "sidekiq/grouping/batch"
autoload :Middleware, "sidekiq/grouping/middleware"
autoload :Flusher, "sidekiq/grouping/flusher"
autoload :FlusherObserver, "sidekiq/grouping/flusher_observer"
module Sidekiq
module Grouping
autoload :Config, "sidekiq/grouping/config"
autoload :Redis, "sidekiq/grouping/redis"
autoload :Batch, "sidekiq/grouping/batch"
autoload :Middleware, "sidekiq/grouping/middleware"
autoload :Flusher, "sidekiq/grouping/flusher"
autoload :FlusherObserver, "sidekiq/grouping/flusher_observer"

class << self
attr_writer :logger
class << self
attr_writer :logger

def logger
@logger ||= Sidekiq.logger
end
def logger
@logger ||= Sidekiq.logger
end

def force_flush_for_test!
Sidekiq::Grouping::Flusher.new.force_flush_for_test!
end
def force_flush_for_test!
Sidekiq::Grouping::Flusher.new.force_flush_for_test!
end

def start!
interval = Sidekiq::Grouping::Config.poll_interval
@observer = Sidekiq::Grouping::FlusherObserver.new
@task = Concurrent::TimerTask.new(
execution_interval: interval
) { Sidekiq::Grouping::Flusher.new.flush }
@task.add_observer(@observer)
logger.info(
"[Sidekiq::Grouping] Started polling batches every #{interval} seconds"
)
@task.execute
def start!
interval = Sidekiq::Grouping::Config.poll_interval
@observer = Sidekiq::Grouping::FlusherObserver.new
@task = Concurrent::TimerTask.new(execution_interval: interval) do
Sidekiq::Grouping::Flusher.new.flush
end
@task.add_observer(@observer)
logger.info(
"[Sidekiq::Grouping] Started polling batches every " \
"#{interval} seconds"
)
@task.execute
end
end
end
end
Expand Down
Loading

0 comments on commit 3e27904

Please sign in to comment.