Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync upstream #7

Merged
merged 50 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
81e14ae
fix mistype: elasic -> elastic
solutus Oct 7, 2019
7e0a56e
readme: add gem version badge
palkan Jul 15, 2022
7230612
pass args to worker as array in inline mode
egor-lukin Sep 12, 2022
63f9c30
Optimized Lua script for Redis >= 6.2.0
russointroitoa Oct 19, 2022
823b200
Remove trailing spaces
russointroitoa Oct 19, 2022
07121bf
Use sadd? to remove warning message
russointroitoa Oct 21, 2022
83611a2
Fixes sidekiq deprecation
Ross-Hunter Aug 8, 2022
28be96c
Merge pull request #38 from solutus/elasic-mistype-patch-1
gzigzigzeo Nov 29, 2022
66adc7e
Merge pull request #45 from palkan/patch-1
gzigzigzeo Nov 29, 2022
d4f6c4c
Merge pull request #46 from Ross-Hunter/fix/options-deprecation
gzigzigzeo Nov 29, 2022
38562c2
Merge pull request #50 from russointroitoa/improve_lua_script
gzigzigzeo Nov 29, 2022
238c760
Merge pull request #48 from LukinEgor/fix/use-same-worker-interface-f…
gzigzigzeo Dec 1, 2022
77d2336
chore: Configure Rubocop and fix all lint issues
mrexox Dec 1, 2022
0f8da00
ci: Add test github action
mrexox Dec 1, 2022
7336953
ci: Add lint github action
mrexox Dec 2, 2022
19951e8
chore: YAML fix
mrexox Dec 2, 2022
36b224f
ci: Fix redis service ports mapping
mrexox Dec 2, 2022
a3e43eb
fix: Remove occasional fix for interval
mrexox Dec 2, 2022
6af76f7
chore: Add lefthook configuration
mrexox Dec 2, 2022
5cd4d0f
chore: Remove Travis config
mrexox Dec 2, 2022
a0d6475
chore: Appraise setting
mrexox Dec 2, 2022
2eb3b8d
fix: Fix tests
mrexox Dec 2, 2022
f9d8f36
chore: Apply rubocop settings
mrexox Dec 2, 2022
8682687
chore: Bump version upto 1.2.0
mrexox Dec 2, 2022
cc93d30
ci: Remove jruby from matrix
mrexox Dec 2, 2022
08512a0
fix: Use more verbose var name
mrexox Dec 2, 2022
4122dac
chore: Run tests before pushing
mrexox Dec 2, 2022
19cc8a8
Merge pull request #53 from mrexox/chore/lint-and-clean
gzigzigzeo Dec 2, 2022
7ffa30e
feature: Support Sidekiq 7
mrexox Dec 2, 2022
8fbc60f
chore: Fix rubocop issues
mrexox Dec 2, 2022
dc9f160
chore: Bump version
mrexox Dec 2, 2022
12cbb1c
chore: Update lefthook.yml
mrexox Dec 2, 2022
7dfa158
chore: Update lefthook.yml
mrexox Dec 2, 2022
0c68a93
Merge pull request #54 from mrexox/feature/support-sidekiq-upto-7
gzigzigzeo Dec 2, 2022
eccf101
Merge remote-tracking branch 'upstream/master' into sync-upstream
tomzagorski Mar 31, 2023
cf25ac5
fixing rubocop issues in non-spec files
tomzagorski Mar 31, 2023
0ed42f8
fixing rubocop issues in spec files
tomzagorski Mar 31, 2023
b1b0827
fixing specs
tomzagorski Mar 31, 2023
d5fb364
3.0 ruby_version needs to be quoted or else it jumps to 3.2 which app…
tomzagorski Apr 3, 2023
b4891fa
using redis dispatcher for reliable pluck
tomzagorski Apr 3, 2023
ed5dc9e
more redis dispatcher uses
tomzagorski Apr 3, 2023
4367dc3
renaming variable
tomzagorski Apr 3, 2023
f949ed9
build fixes
tomzagorski Apr 4, 2023
92abfb6
adding adapters for redis/redis-client
tomzagorski Apr 4, 2023
efa9643
removing unused methods
tomzagorski Apr 4, 2023
99d7daf
Merge remote-tracking branch 'origin/master' into sync-upstream-2
rex-remind101 Feb 17, 2024
28b9eb5
Merge pull request #9 from ParentSquare/sync-upstream-2
rex-remind101 Feb 20, 2024
c08bd8e
Prevent loading scripts multiple times per process
rex-remind101 Feb 28, 2024
d0add72
Merge pull request #10 from ParentSquare/sync-upstream-3
rex-remind101 Feb 28, 2024
be02a1f
fix rubocop errors
rex-remind101 Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
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:
matrix:
include:
- { ruby_version: 2.7 }
- { ruby_version: '3.0' }
- { ruby_version: 3.1 }
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
.lefthook-local.yml
34 changes: 31 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
---
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/FilePath:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/AnyInstance:
Enabled: false

Metrics/MethodLength:
Max: 15

Metrics/ClassLength:
Max: 150

Layout/LineLength:
Max: 80

Layout/FirstArgumentIndentation:
EnforcedStyle: consistent

Layout/FirstMethodArgumentLineBreak:
Enabled: true

Layout/MultilineMethodArgumentLineBreaks:
Enabled: true
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

14 changes: 13 additions & 1 deletion 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'
gem 'sidekiq', github: 'mperham/sidekiq', branch: 'main'
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 Down Expand Up @@ -25,7 +27,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: "../"
2 changes: 1 addition & 1 deletion gemfiles/sidekiq_master.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

gem "sidekiq", github: "mperham/sidekiq"
gem "sidekiq", github: "mperham/sidekiq", branch: "main"

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
68 changes: 38 additions & 30 deletions lib/sidekiq/grouping.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
# 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 :ReliableBatch, "sidekiq/grouping/reliable_batch"
autoload :Middleware, "sidekiq/grouping/middleware"
autoload :Flusher, "sidekiq/grouping/flusher"
autoload :FlusherObserver, "sidekiq/grouping/flusher_observer"
autoload :Supervisor, "sidekiq/grouping/supervisor"

class << self
attr_writer :logger

def logger
@logger ||= Sidekiq.logger
end
module Sidekiq
module Grouping
autoload :Config, "sidekiq/grouping/config"
autoload :Redis, "sidekiq/grouping/redis"
autoload :Batch, "sidekiq/grouping/batch"
autoload :ReliableBatch, "sidekiq/grouping/reliable_batch"
autoload :Supervisor, "sidekiq/grouping/supervisor"
autoload :Middleware, "sidekiq/grouping/middleware"
autoload :Flusher, "sidekiq/grouping/flusher"
autoload :FlusherObserver, "sidekiq/grouping/flusher_observer"

def force_flush_for_test!
Sidekiq::Grouping::Flusher.new.force_flush_for_test!
end
class << self
attr_writer :logger

def logger
@logger ||= Sidekiq.logger
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) do
Sidekiq::Grouping::Flusher.new.flush
Sidekiq::Grouping::Supervisor.new.requeue_expired if Sidekiq::Grouping::Config.reliable
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
if Sidekiq::Grouping::Config.reliable
Sidekiq::Grouping::Supervisor.new.requeue_expired
end
end
@task.add_observer(@observer)
logger.info(
"[Sidekiq::Grouping] Started polling batches every " \
"#{interval} seconds"
)
@task.execute
end
@task.add_observer(@observer)
logger.info(
"[Sidekiq::Grouping] Started polling batches every #{interval} seconds"
)
@task.execute
end
end
end
Expand Down
38 changes: 38 additions & 0 deletions lib/sidekiq/grouping/adapters/base_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require_relative "../redis_dispatcher"
require_relative "../redis_scripts"

module Sidekiq
module Grouping
module Adapters
class BaseAdapter
private

def requeue_script(unique)
if unique
RedisScripts.script_hash(:unique_requeue)
else
RedisScripts.script_hash(:requeue)
end
end

def unique_messages_key(name)
ns("#{name}:unique_messages")
end

def pending_jobs(name)
ns("#{name}:pending_jobs")
end

def this_job_name(name)
ns("#{name}:#{SecureRandom.hex}")
end

def ns(key = nil)
"batching:#{key}"
end
end
end
end
end
Loading
Loading