sidekiq-unique-jobs 5.0.2 → 5.0.11
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq-unique-jobs might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.rubocop.yml +20 -13
- data/.simplecov +1 -1
- data/.travis.yml +30 -20
- data/Appraisals +10 -2
- data/CHANGELOG.md +33 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -12
- data/LICENSE.txt +21 -0
- data/README.md +48 -4
- data/Rakefile +0 -1
- data/bin/bench +1 -1
- data/lib/sidekiq/simulator.rb +4 -10
- data/lib/sidekiq-unique-jobs.rb +16 -6
- data/lib/sidekiq_unique_jobs/cli.rb +14 -12
- data/lib/sidekiq_unique_jobs/client/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/config.rb +2 -0
- data/lib/sidekiq_unique_jobs/constants.rb +20 -17
- data/lib/sidekiq_unique_jobs/core_ext.rb +18 -0
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +4 -5
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_timeout.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +10 -9
- data/lib/sidekiq_unique_jobs/lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/normalizer.rb +3 -1
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +22 -3
- data/lib/sidekiq_unique_jobs/run_lock_failed.rb +2 -0
- data/lib/sidekiq_unique_jobs/script_mock.rb +16 -15
- data/lib/sidekiq_unique_jobs/scripts/acquire_lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/scripts/release_lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/scripts.rb +17 -12
- data/lib/sidekiq_unique_jobs/server/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +4 -14
- data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +2 -0
- data/lib/sidekiq_unique_jobs/testing.rb +4 -2
- data/lib/sidekiq_unique_jobs/timeout_calculator.rb +2 -0
- data/lib/sidekiq_unique_jobs/unique_args.rb +27 -14
- data/lib/sidekiq_unique_jobs/unlockable.rb +6 -6
- data/lib/sidekiq_unique_jobs/util.rb +34 -14
- data/lib/sidekiq_unique_jobs/version.rb +3 -1
- data/redis/acquire_lock.lua +1 -1
- data/sidekiq-unique-jobs.gemspec +27 -23
- metadata +44 -212
- data/LICENSE +0 -13
- data/circle.yml +0 -41
- data/gemfiles/sidekiq_4.0.gemfile +0 -22
- data/gemfiles/sidekiq_4.1.gemfile +0 -22
- data/gemfiles/sidekiq_4.2.gemfile +0 -22
- data/gemfiles/sidekiq_5.0.gemfile +0 -22
- data/gemfiles/sidekiq_develop.gemfile +0 -22
- data/rails_example/.env +0 -12
- data/rails_example/.env.test +0 -12
- data/rails_example/.gitignore +0 -13
- data/rails_example/.rspec +0 -2
- data/rails_example/Gemfile +0 -38
- data/rails_example/Procfile +0 -2
- data/rails_example/README.rdoc +0 -28
- data/rails_example/Rakefile +0 -6
- data/rails_example/app/assets/images/.keep +0 -0
- data/rails_example/app/assets/javascripts/application.js +0 -16
- data/rails_example/app/assets/stylesheets/application.css +0 -15
- data/rails_example/app/channels/appearance_channel.rb +0 -17
- data/rails_example/app/channels/application_cable/channel.rb +0 -4
- data/rails_example/app/channels/application_cable/connection.rb +0 -9
- data/rails_example/app/channels/post_channel.rb +0 -5
- data/rails_example/app/controllers/application_controller.rb +0 -5
- data/rails_example/app/controllers/concerns/.keep +0 -0
- data/rails_example/app/controllers/work_controller.rb +0 -39
- data/rails_example/app/helpers/application_helper.rb +0 -2
- data/rails_example/app/mailers/.keep +0 -0
- data/rails_example/app/models/.keep +0 -0
- data/rails_example/app/models/application_record.rb +0 -3
- data/rails_example/app/models/concerns/.keep +0 -0
- data/rails_example/app/models/guest.rb +0 -18
- data/rails_example/app/models/post.rb +0 -2
- data/rails_example/app/views/layouts/application.html.erb +0 -15
- data/rails_example/app/workers/simple_worker.rb +0 -15
- data/rails_example/app/workers/slow_until_executing_worker.rb +0 -15
- data/rails_example/app/workers/spawn_simple_worker.rb +0 -10
- data/rails_example/app/workers/while_executing_worker.rb +0 -12
- data/rails_example/app/workers/without_args_worker.rb +0 -16
- data/rails_example/app/workers/without_argument_worker.rb +0 -12
- data/rails_example/bin/bundle +0 -3
- data/rails_example/bin/check_or_setup_db +0 -56
- data/rails_example/bin/docker-setup +0 -20
- data/rails_example/bin/rails +0 -4
- data/rails_example/bin/rake +0 -4
- data/rails_example/bin/setup +0 -34
- data/rails_example/bin/update +0 -29
- data/rails_example/cable.ru +0 -6
- data/rails_example/common-services.yml +0 -52
- data/rails_example/config/application.rb +0 -27
- data/rails_example/config/boot.rb +0 -3
- data/rails_example/config/cable.yml +0 -9
- data/rails_example/config/database.docker.yml +0 -12
- data/rails_example/config/database.yml +0 -19
- data/rails_example/config/environment.rb +0 -5
- data/rails_example/config/environments/development.rb +0 -54
- data/rails_example/config/environments/production.rb +0 -86
- data/rails_example/config/environments/test.rb +0 -42
- data/rails_example/config/initializers/application_controller_renderer.rb +0 -6
- data/rails_example/config/initializers/assets.rb +0 -11
- data/rails_example/config/initializers/backtrace_silencers.rb +0 -9
- data/rails_example/config/initializers/cookies_serializer.rb +0 -5
- data/rails_example/config/initializers/filter_parameter_logging.rb +0 -4
- data/rails_example/config/initializers/inflections.rb +0 -16
- data/rails_example/config/initializers/mime_types.rb +0 -4
- data/rails_example/config/initializers/new_framework_defaults.rb +0 -23
- data/rails_example/config/initializers/session_store.rb +0 -3
- data/rails_example/config/initializers/sidekiq.rb +0 -13
- data/rails_example/config/initializers/wrap_parameters.rb +0 -14
- data/rails_example/config/locales/en.yml +0 -23
- data/rails_example/config/puma.rb +0 -38
- data/rails_example/config/routes.rb +0 -8
- data/rails_example/config/secrets.yml +0 -22
- data/rails_example/config/sidekiq.yml +0 -6
- data/rails_example/config/spring.rb +0 -6
- data/rails_example/config.ru +0 -4
- data/rails_example/db/migrate/20160724111322_create_posts.rb +0 -12
- data/rails_example/db/schema.rb +0 -25
- data/rails_example/db/seeds.rb +0 -7
- data/rails_example/dev-entrypoint.sh +0 -55
- data/rails_example/dev.env +0 -12
- data/rails_example/docker/rails.Dockerfile +0 -27
- data/rails_example/docker-compose.yml +0 -71
- data/rails_example/lib/assets/.keep +0 -0
- data/rails_example/lib/tasks/.keep +0 -0
- data/rails_example/log/.keep +0 -0
- data/rails_example/public/404.html +0 -67
- data/rails_example/public/422.html +0 -67
- data/rails_example/public/500.html +0 -66
- data/rails_example/public/favicon.ico +0 -0
- data/rails_example/public/robots.txt +0 -5
- data/rails_example/simple.ru +0 -12
- data/rails_example/spec/controllers/work_controller_mock_spec.rb +0 -91
- data/rails_example/spec/controllers/work_controller_spec.rb +0 -77
- data/rails_example/spec/factories/posts.rb +0 -8
- data/rails_example/spec/models/post_spec.rb +0 -4
- data/rails_example/spec/rails_helper.rb +0 -20
- data/rails_example/spec/spec_helper.rb +0 -20
- data/rails_example/spec/support/sidekiq_meta.rb +0 -12
- data/rails_example/spec/workers/simple_worker_spec.rb +0 -4
- data/rails_example/vendor/assets/javascripts/.keep +0 -0
- data/rails_example/vendor/assets/stylesheets/.keep +0 -0
- data/spec/jobs/another_unique_job.rb +0 -13
- data/spec/jobs/custom_queue_job.rb +0 -5
- data/spec/jobs/custom_queue_job_with_filter_method.rb +0 -7
- data/spec/jobs/custom_queue_job_with_filter_proc.rb +0 -10
- data/spec/jobs/expiring_job.rb +0 -4
- data/spec/jobs/inline_worker.rb +0 -8
- data/spec/jobs/just_a_worker.rb +0 -7
- data/spec/jobs/long_running_job.rb +0 -6
- data/spec/jobs/main_job.rb +0 -7
- data/spec/jobs/my_job.rb +0 -12
- data/spec/jobs/my_unique_job.rb +0 -11
- data/spec/jobs/my_unique_job_with_filter_method.rb +0 -17
- data/spec/jobs/my_unique_job_with_filter_proc.rb +0 -15
- data/spec/jobs/notify_worker.rb +0 -10
- data/spec/jobs/plain_class.rb +0 -3
- data/spec/jobs/simple_worker.rb +0 -11
- data/spec/jobs/spawn_simple_worker.rb +0 -8
- data/spec/jobs/test_class.rb +0 -3
- data/spec/jobs/unique_job_with_conditional_parameter.rb +0 -14
- data/spec/jobs/unique_job_with_filter_method.rb +0 -18
- data/spec/jobs/unique_job_with_nil_unique_args.rb +0 -16
- data/spec/jobs/unique_job_with_no_unique_args_method.rb +0 -12
- data/spec/jobs/unique_job_withthout_unique_args_parameter.rb +0 -14
- data/spec/jobs/unique_on_all_queues_job.rb +0 -13
- data/spec/jobs/until_and_while_executing_job.rb +0 -7
- data/spec/jobs/until_executed_job.rb +0 -17
- data/spec/jobs/until_executing_job.rb +0 -7
- data/spec/jobs/until_global_timeout_job.rb +0 -8
- data/spec/jobs/until_timeout_job.rb +0 -8
- data/spec/jobs/while_executing_job.rb +0 -12
- data/spec/jobs/without_argument_job.rb +0 -9
- data/spec/lib/sidekiq_unique_jobs/cli_spec.rb +0 -183
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +0 -316
- data/spec/lib/sidekiq_unique_jobs/config_spec.rb +0 -84
- data/spec/lib/sidekiq_unique_jobs/core_ext_spec.rb +0 -25
- data/spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +0 -42
- data/spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb +0 -37
- data/spec/lib/sidekiq_unique_jobs/lock/until_timeout_spec.rb +0 -26
- data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +0 -86
- data/spec/lib/sidekiq_unique_jobs/normalizer_spec.rb +0 -21
- data/spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb +0 -113
- data/spec/lib/sidekiq_unique_jobs/queue_lock_timeout_calculator_spec.rb +0 -47
- data/spec/lib/sidekiq_unique_jobs/run_lock_timeout_calculator_spec.rb +0 -36
- data/spec/lib/sidekiq_unique_jobs/script_mock_spec.rb +0 -88
- data/spec/lib/sidekiq_unique_jobs/scripts/acquire_lock_spec.rb +0 -50
- data/spec/lib/sidekiq_unique_jobs/scripts/release_lock_spec.rb +0 -41
- data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +0 -68
- data/spec/lib/sidekiq_unique_jobs/server/middleware_spec.rb +0 -78
- data/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb +0 -164
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +0 -75
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_jobs_spec.rb +0 -41
- data/spec/lib/sidekiq_unique_jobs/timeout_calculator_spec.rb +0 -70
- data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +0 -257
- data/spec/lib/sidekiq_unique_jobs/unlockable_spec.rb +0 -37
- data/spec/lib/sidekiq_unique_jobs/util_spec.rb +0 -81
- data/spec/spec_helper.rb +0 -92
- data/spec/support/matchers/redis_matchers.rb +0 -29
- data/spec/support/ruby_meta.rb +0 -17
- data/spec/support/sidekiq_meta.rb +0 -30
- data/spec/support/unique_macros.rb +0 -71
@@ -1,18 +0,0 @@
|
|
1
|
-
class UniqueJobWithFilterMethod
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :customqueue, retry: 1, backtrace: 10,
|
4
|
-
unique: :while_executing, unique_args: :filtered_args
|
5
|
-
|
6
|
-
sidekiq_retries_exhausted do |msg|
|
7
|
-
logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
8
|
-
end
|
9
|
-
|
10
|
-
def perform(*)
|
11
|
-
# NO-OP
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.filtered_args(args)
|
15
|
-
options = args.extract_options!
|
16
|
-
[args.first, options['type']]
|
17
|
-
end
|
18
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class UniqueJobWithNilUniqueArgs
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :customqueue,
|
4
|
-
retry: true,
|
5
|
-
backtrace: true,
|
6
|
-
unique: :until_executed,
|
7
|
-
unique_args: :unique_args
|
8
|
-
|
9
|
-
def perform(*)
|
10
|
-
# NO-OP
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.unique_args(_args)
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class UniqueJobWithoutUniqueArgsParameter
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :customqueue,
|
4
|
-
retry: true,
|
5
|
-
backtrace: true,
|
6
|
-
unique: :until_executed,
|
7
|
-
unique_args: :unique_args
|
8
|
-
|
9
|
-
def perform(optional = true)
|
10
|
-
# NO-OP
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.unique_args; end
|
14
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class UniqueOnAllQueuesJob
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :working, retry: 1, backtrace: 10,
|
4
|
-
unique: :until_executed, unique_on_all_queues: true
|
5
|
-
|
6
|
-
sidekiq_retries_exhausted do |msg|
|
7
|
-
logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
8
|
-
end
|
9
|
-
|
10
|
-
def perform(*)
|
11
|
-
# NO-OP
|
12
|
-
end
|
13
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class UntilExecutedJob
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :working, retry: 1, backtrace: 10
|
4
|
-
sidekiq_options unique: :until_executed
|
5
|
-
|
6
|
-
sidekiq_retries_exhausted do |msg|
|
7
|
-
logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
8
|
-
end
|
9
|
-
|
10
|
-
def perform(*)
|
11
|
-
# NO-OP
|
12
|
-
end
|
13
|
-
|
14
|
-
def after_unlock
|
15
|
-
# NO OP
|
16
|
-
end
|
17
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class WhileExecutingJob
|
2
|
-
include Sidekiq::Worker
|
3
|
-
sidekiq_options queue: :working, retry: 1, backtrace: 10, unique: :while_executing
|
4
|
-
|
5
|
-
sidekiq_retries_exhausted do |msg|
|
6
|
-
logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def perform(_)
|
10
|
-
# NO OP
|
11
|
-
end
|
12
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'thor/runner'
|
3
|
-
|
4
|
-
RSpec.describe SidekiqUniqueJobs::Cli, ruby_ver: '>= 2.4' do
|
5
|
-
describe '#help' do
|
6
|
-
let(:output) { capture(:stdout) { described_class.start(%w[help]) } }
|
7
|
-
let(:banner) do
|
8
|
-
<<~EOS.freeze
|
9
|
-
Commands:
|
10
|
-
jobs console # drop into a console with easy access to helper methods
|
11
|
-
jobs del PATTERN # deletes unique keys from redis by pattern
|
12
|
-
jobs expire # removes all expired unique keys from the hash in redis
|
13
|
-
jobs help [COMMAND] # Describe available commands or one specific command
|
14
|
-
jobs keys PATTERN # list all unique keys and their expiry time
|
15
|
-
EOS
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'displays help' do
|
19
|
-
expect(output).to include(banner)
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#help del' do
|
23
|
-
let(:output) { capture(:stdout) { described_class.start(%w[help del]) } }
|
24
|
-
let(:banner) do
|
25
|
-
<<~EOS.freeze
|
26
|
-
Usage:
|
27
|
-
jobs del PATTERN
|
28
|
-
|
29
|
-
Options:
|
30
|
-
d, [--dry-run], [--no-dry-run] # set to false to perform deletion
|
31
|
-
c, [--count=N] # The max number of keys to return
|
32
|
-
# Default: 1000
|
33
|
-
|
34
|
-
deletes unique keys from redis by pattern
|
35
|
-
EOS
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'displays help about the `del` command' do
|
39
|
-
expect(output).to eq(banner)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#help expire' do
|
44
|
-
let(:output) { capture(:stdout) { described_class.start(%w[help expire]) } }
|
45
|
-
|
46
|
-
let(:banner) do
|
47
|
-
<<~EOS.freeze
|
48
|
-
Usage:
|
49
|
-
jobs expire
|
50
|
-
|
51
|
-
removes all expired unique keys from the hash in redis
|
52
|
-
EOS
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'displays help about the `expire` command' do
|
56
|
-
expect(output).to eq(banner)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#help keys' do
|
61
|
-
let(:output) { capture(:stdout) { described_class.start(%w[help keys]) } }
|
62
|
-
let(:banner) do
|
63
|
-
<<~EOS.freeze
|
64
|
-
Usage:
|
65
|
-
jobs keys PATTERN
|
66
|
-
|
67
|
-
Options:
|
68
|
-
c, [--count=N] # The max number of keys to return
|
69
|
-
# Default: 1000
|
70
|
-
|
71
|
-
list all unique keys and their expiry time
|
72
|
-
EOS
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'displays help about the `key` command' do
|
76
|
-
expect(output).to eq(banner)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
let(:pattern) { '*' }
|
82
|
-
let(:max_lock_time) { 1 }
|
83
|
-
let(:unique_key) { 'uniquejobs:abcdefab' }
|
84
|
-
let(:jid) { 'abcdefab' }
|
85
|
-
|
86
|
-
describe '.keys' do
|
87
|
-
let(:output) { capture(:stdout) { described_class.start(%w[keys * --count 1000]) } }
|
88
|
-
|
89
|
-
context 'when no keys exist' do
|
90
|
-
let(:expected) { "Found 0 keys matching '#{pattern}':\n" }
|
91
|
-
specify { expect(output).to eq(expected) }
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'when a key exists' do
|
95
|
-
let(:keys) { ['defghayl', jid, 'poilkij'].sort }
|
96
|
-
before do
|
97
|
-
keys.each do |jid|
|
98
|
-
unique_key = "uniquejobs:#{jid}"
|
99
|
-
SidekiqUniqueJobs::Scripts::AcquireLock.execute(nil, unique_key, jid, 20)
|
100
|
-
expect(SidekiqUniqueJobs)
|
101
|
-
.to have_key(unique_key)
|
102
|
-
.for_seconds(20)
|
103
|
-
.with_value(jid)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
after { SidekiqUniqueJobs::Util.del('*', 1000, false) }
|
108
|
-
|
109
|
-
let(:expected) do
|
110
|
-
<<~EOS
|
111
|
-
Found 3 keys matching '#{pattern}':
|
112
|
-
uniquejobs:abcdefab uniquejobs:defghayl uniquejobs:poilkij
|
113
|
-
EOS
|
114
|
-
end
|
115
|
-
specify do
|
116
|
-
expect(output).to eq(expected)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '.del' do
|
122
|
-
let(:expected) do
|
123
|
-
<<~EOS
|
124
|
-
Deleted 1 keys matching '*'
|
125
|
-
EOS
|
126
|
-
end
|
127
|
-
|
128
|
-
before do
|
129
|
-
SidekiqUniqueJobs::Scripts::AcquireLock.execute(nil, unique_key, jid, max_lock_time)
|
130
|
-
expect(SidekiqUniqueJobs)
|
131
|
-
.to have_key(unique_key)
|
132
|
-
.for_seconds(1)
|
133
|
-
.with_value(jid)
|
134
|
-
end
|
135
|
-
|
136
|
-
specify do
|
137
|
-
output = capture(:stdout) { described_class.start(%w[del * --no-dry-run --count 1000]) }
|
138
|
-
expect(output).to eq(expected)
|
139
|
-
expect(SidekiqUniqueJobs).not_to have_key(unique_key)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe '.expire' do
|
144
|
-
before do
|
145
|
-
SidekiqUniqueJobs::Scripts::AcquireLock.execute(nil, unique_key, jid, max_lock_time)
|
146
|
-
expect(SidekiqUniqueJobs)
|
147
|
-
.to have_key(unique_key)
|
148
|
-
.for_seconds(1)
|
149
|
-
.with_value(jid)
|
150
|
-
end
|
151
|
-
let(:expected) do
|
152
|
-
<<~EOS
|
153
|
-
Removed 1 left overs from redis.
|
154
|
-
uniquejobs:abcdefab
|
155
|
-
EOS
|
156
|
-
end
|
157
|
-
|
158
|
-
specify do
|
159
|
-
sleep 1
|
160
|
-
output = capture(:stdout) { described_class.start(%w[expire]) }
|
161
|
-
expect(output).to eq(expected)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '.console' do
|
166
|
-
let(:expected) do
|
167
|
-
<<~EOS
|
168
|
-
Use `keys '*', 1000 to display the first 1000 unique keys matching '*'
|
169
|
-
Use `del '*', 1000, true (default) to see how many keys would be deleted for the pattern '*'
|
170
|
-
Use `del '*', 1000, false to delete the first 1000 keys matching '*'
|
171
|
-
EOS
|
172
|
-
end
|
173
|
-
let(:output) { capture(:stdout) { described_class.start(%w[console]) } }
|
174
|
-
|
175
|
-
specify do
|
176
|
-
expect(Object).to receive(:include).with(SidekiqUniqueJobs::Util).and_return(true)
|
177
|
-
console = double(:console)
|
178
|
-
allow_any_instance_of(SidekiqUniqueJobs::Cli).to receive(:console_class).and_return(console)
|
179
|
-
allow(console).to receive(:start)
|
180
|
-
expect(output).to eq(expected)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
@@ -1,316 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sidekiq/worker'
|
3
|
-
require 'sidekiq-unique-jobs'
|
4
|
-
require 'rspec/wait'
|
5
|
-
|
6
|
-
RSpec.describe SidekiqUniqueJobs::Client::Middleware do
|
7
|
-
def digest_for(item)
|
8
|
-
SidekiqUniqueJobs::UniqueArgs.digest(item)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'with real redis' do
|
12
|
-
describe 'when a job is already scheduled' do
|
13
|
-
it 'processes jobs properly' do
|
14
|
-
Sidekiq::Testing.disable! do
|
15
|
-
jid = NotifyWorker.perform_in(1, 183, 'xxxx')
|
16
|
-
expect(jid).not_to eq(nil)
|
17
|
-
Sidekiq.redis do |c|
|
18
|
-
expect(c.zcard('schedule')).to eq(1)
|
19
|
-
expected = %w[schedule uniquejobs:6e47d668ad22db2a3ba0afd331514ce2 uniquejobs]
|
20
|
-
expect(c.keys).to match_array(expected)
|
21
|
-
end
|
22
|
-
sleep 1
|
23
|
-
Sidekiq::Scheduled::Enq.new.enqueue_jobs
|
24
|
-
|
25
|
-
Sidekiq.redis do |c|
|
26
|
-
wait(10).for { c.llen('queue:notify_worker') }.to eq(1)
|
27
|
-
end
|
28
|
-
|
29
|
-
Sidekiq::Simulator.process_queue(:notify_worker) do
|
30
|
-
Sidekiq.redis do |c|
|
31
|
-
wait(10).for { c.llen('queue:notify_worker') }.to eq(0)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'rejects nested subsequent jobs with the same arguments' do
|
38
|
-
Sidekiq::Testing.disable! do
|
39
|
-
expect(SimpleWorker.perform_async(1)).not_to eq(nil)
|
40
|
-
expect(SimpleWorker.perform_async(1)).to eq(nil)
|
41
|
-
expect(SpawnSimpleWorker.perform_async(1)).not_to eq(nil)
|
42
|
-
|
43
|
-
Sidekiq.redis do |c|
|
44
|
-
expect(c.llen('queue:default')).to eq(1)
|
45
|
-
expect(c.llen('queue:not_default')).to eq(1)
|
46
|
-
end
|
47
|
-
|
48
|
-
Sidekiq::Simulator.process_queue(:not_default) do
|
49
|
-
Sidekiq.redis do |c|
|
50
|
-
expect(c.llen('queue:default')).to eq(1)
|
51
|
-
wait(10).for { c.llen('queue:not_default') }.to eq(0)
|
52
|
-
expect(c.llen('queue:default')).to eq(1)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
Sidekiq.redis do |c|
|
57
|
-
expect(c.llen('queue:default')).to eq(1)
|
58
|
-
end
|
59
|
-
|
60
|
-
Sidekiq::Simulator.process_queue(:default) do
|
61
|
-
Sidekiq.redis do |c|
|
62
|
-
expect(c.llen('queue:not_default')).to eq(0)
|
63
|
-
wait(10).for { c.llen('queue:default') }.to eq(0)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'rejects new scheduled jobs with the same argument' do
|
70
|
-
MyUniqueJob.perform_in(3600, 1)
|
71
|
-
expect(MyUniqueJob.perform_in(3600, 1)).to eq(nil)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'will run a job in real time with the same arguments' do
|
75
|
-
WhileExecutingJob.perform_in(3600, 1)
|
76
|
-
expect(WhileExecutingJob.perform_async(1)).not_to eq(nil)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'schedules new jobs when arguments differ' do
|
80
|
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].each do |x|
|
81
|
-
MainJob.perform_in(x, x)
|
82
|
-
end
|
83
|
-
|
84
|
-
Sidekiq.redis do |c|
|
85
|
-
count = c.zcount('schedule', -1, Time.now.to_f + 2 * 60)
|
86
|
-
expect(count).to eq(20)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'schedules allows jobs to be scheduled ' do
|
91
|
-
class ShitClass
|
92
|
-
def do_it(_arg)
|
93
|
-
# whatever
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].each do |x|
|
98
|
-
ShitClass.delay_for(x, unique: :while_executing).do_it(1)
|
99
|
-
end
|
100
|
-
|
101
|
-
Sidekiq.redis do |c|
|
102
|
-
count = c.zcount('schedule', -1, Time.now.to_f + 2 * 60)
|
103
|
-
expect(count).to eq(20)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'does not push duplicate messages when configured for unique only' do
|
109
|
-
10.times { MyUniqueJob.perform_async(1, 2) }
|
110
|
-
Sidekiq.redis do |c|
|
111
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'does not push duplicate messages when unique_args are filtered with a proc' do
|
116
|
-
10.times { MyUniqueJobWithFilterProc.perform_async(1) }
|
117
|
-
Sidekiq.redis { |c| expect(c.llen('queue:customqueue')).to eq(1) }
|
118
|
-
|
119
|
-
Sidekiq.redis(&:flushdb)
|
120
|
-
Sidekiq.redis { |c| expect(c.llen('queue:customqueue')).to eq(0) }
|
121
|
-
|
122
|
-
10.times do
|
123
|
-
Sidekiq::Client.push(
|
124
|
-
'class' => MyUniqueJobWithFilterProc,
|
125
|
-
'queue' => 'customqueue',
|
126
|
-
'args' => [1, type: 'value', some: 'not used'],
|
127
|
-
)
|
128
|
-
end
|
129
|
-
Sidekiq.redis { |c| expect(c.llen('queue:customqueue')).to eq(1) }
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'does not push duplicate messages when unique_args are filtered with a method' do
|
133
|
-
10.times { MyUniqueJobWithFilterMethod.perform_async(1) }
|
134
|
-
Sidekiq.redis do |c|
|
135
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
136
|
-
end
|
137
|
-
Sidekiq.redis(&:flushdb)
|
138
|
-
Sidekiq.redis { |c| expect(c.llen('queue:customqueue')).to eq(0) }
|
139
|
-
10.times do
|
140
|
-
Sidekiq::Client.push(
|
141
|
-
'class' => MyUniqueJobWithFilterMethod,
|
142
|
-
'queue' => 'customqueue',
|
143
|
-
'args' => [1, type: 'value', some: 'not used'],
|
144
|
-
)
|
145
|
-
end
|
146
|
-
Sidekiq.redis { |c| expect(c.llen('queue:customqueue')).to eq(1) }
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'does push duplicate messages to different queues' do
|
150
|
-
Sidekiq::Client.push('class' => MyUniqueJob, 'queue' => 'customqueue', 'args' => [1, 2])
|
151
|
-
Sidekiq::Client.push('class' => MyUniqueJob, 'queue' => 'customqueue2', 'args' => [1, 2])
|
152
|
-
Sidekiq.redis do |c|
|
153
|
-
expect(c.llen('queue:customqueue')).to eq 1
|
154
|
-
expect(c.llen('queue:customqueue2')).to eq 1
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'does not queue duplicates when when calling delay' do
|
159
|
-
10.times { PlainClass.delay(unique: :until_executed, queue: 'customqueue').run(1) }
|
160
|
-
Sidekiq.redis do |c|
|
161
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'does not schedule duplicates when calling perform_in' do
|
166
|
-
10.times { MyUniqueJob.perform_in(60, [1, 2]) }
|
167
|
-
Sidekiq.redis do |c|
|
168
|
-
expect(c.zcount('schedule', -1, Time.now.to_f + 2 * 60))
|
169
|
-
.to eq(1)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'enqueues previously scheduled job' do
|
174
|
-
jid = WhileExecutingJob.perform_in(60 * 60, 1, 2)
|
175
|
-
item = { 'class' => WhileExecutingJob, 'queue' => 'customqueue', 'args' => [1, 2], 'jid' => jid }
|
176
|
-
|
177
|
-
# time passes and the job is pulled off the schedule:
|
178
|
-
Sidekiq::Client.push(item)
|
179
|
-
|
180
|
-
Sidekiq.redis do |c|
|
181
|
-
expect(c.llen('queue:customqueue')).to eq 1
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'sets an expiration when provided by sidekiq options' do
|
186
|
-
item = { 'class' => ExpiringJob, 'queue' => 'customqueue', 'args' => [1, 2] }
|
187
|
-
Sidekiq::Client.push(item)
|
188
|
-
|
189
|
-
Sidekiq.redis do |c|
|
190
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
191
|
-
expect(c.ttl(digest_for(item)))
|
192
|
-
.to eq(ExpiringJob.get_sidekiq_options['unique_expiration'])
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'does push duplicate messages when not configured for unique only' do
|
197
|
-
10.times do
|
198
|
-
Sidekiq::Client.push('class' => CustomQueueJob, 'queue' => 'customqueue', 'args' => [1, 2])
|
199
|
-
end
|
200
|
-
|
201
|
-
Sidekiq.redis do |c|
|
202
|
-
expect(c.llen('queue:customqueue')).to eq(10)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe 'when unique_args is defined' do
|
207
|
-
it 'does not push duplicate messages based on args filter method' do
|
208
|
-
expect(CustomQueueJobWithFilterMethod).to respond_to(:args_filter)
|
209
|
-
expect(CustomQueueJobWithFilterMethod.get_sidekiq_options['unique_args']).to eq :args_filter
|
210
|
-
|
211
|
-
(0..10).each do |i|
|
212
|
-
Sidekiq::Client.push(
|
213
|
-
'class' => CustomQueueJobWithFilterMethod,
|
214
|
-
'queue' => 'customqueue',
|
215
|
-
'args' => [1, i],
|
216
|
-
)
|
217
|
-
end
|
218
|
-
|
219
|
-
Sidekiq.redis do |c|
|
220
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'does not push duplicate messages based on args filter proc' do
|
225
|
-
expect(CustomQueueJobWithFilterProc.get_sidekiq_options['unique_args']).to be_a(Proc)
|
226
|
-
|
227
|
-
100.times do
|
228
|
-
Sidekiq::Client.push(
|
229
|
-
'class' => CustomQueueJobWithFilterProc,
|
230
|
-
'queue' => 'customqueue',
|
231
|
-
'args' => [1, { random: rand, name: 'foobar' }],
|
232
|
-
)
|
233
|
-
end
|
234
|
-
|
235
|
-
Sidekiq.redis do |c|
|
236
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe 'when unique_on_all_queues is set' do
|
241
|
-
it 'does not push duplicate messages on different queues' do
|
242
|
-
item = { 'class' => UniqueOnAllQueuesJob, 'args' => [1, 2] }
|
243
|
-
Sidekiq::Client.push(item.merge('queue' => 'customqueue'))
|
244
|
-
Sidekiq::Client.push(item.merge('queue' => 'customqueue2'))
|
245
|
-
Sidekiq.redis do |c|
|
246
|
-
expect(c.llen('queue:customqueue')).to eq(1)
|
247
|
-
expect(c.llen('queue:customqueue2')).to eq(0)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
# TODO: If anyone know of a better way to check that the expiration for scheduled
|
254
|
-
# jobs are set around the same time as the scheduled job itself feel free to improve.
|
255
|
-
it 'expires the digest when a scheduled job is scheduled at' do
|
256
|
-
expected_expires_at =
|
257
|
-
(Time.at(Time.now.to_i + 15 * 60) - Time.now.utc) +
|
258
|
-
SidekiqUniqueJobs.config.default_queue_lock_expiration
|
259
|
-
jid = MyUniqueJob.perform_in(expected_expires_at, 'mike')
|
260
|
-
item = { 'class' => MyUniqueJob,
|
261
|
-
'queue' => 'customqueue',
|
262
|
-
'args' => ['mike'],
|
263
|
-
'at' => expected_expires_at }
|
264
|
-
digest = digest_for(item.merge('jid' => jid))
|
265
|
-
Sidekiq.redis do |c|
|
266
|
-
expect(c.ttl(digest)).to eq(9_899)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'logs duplicate payload when config turned on' do
|
271
|
-
expect(Sidekiq.logger).to receive(:warn).with(/^payload is not unique/)
|
272
|
-
UntilExecutedJob.sidekiq_options log_duplicate_payload: true
|
273
|
-
2.times do
|
274
|
-
Sidekiq::Client.push('class' => UntilExecutedJob, 'queue' => 'customqueue', 'args' => [1, 2])
|
275
|
-
end
|
276
|
-
Sidekiq.redis do |c|
|
277
|
-
expect(c.llen('queue:customqueue')).to eq 1
|
278
|
-
end
|
279
|
-
UntilExecutedJob.sidekiq_options log_duplicate_payload: true
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'does not log duplicate payload when config turned off' do
|
283
|
-
expect(SidekiqUniqueJobs.logger).to_not receive(:warn).with(/^payload is not unique/)
|
284
|
-
|
285
|
-
UntilExecutedJob.sidekiq_options log_duplicate_payload: false
|
286
|
-
|
287
|
-
2.times do
|
288
|
-
Sidekiq::Client.push('class' => UntilExecutedJob, 'queue' => 'customqueue', 'args' => [1, 2])
|
289
|
-
end
|
290
|
-
Sidekiq.redis do |c|
|
291
|
-
expect(c.llen('queue:customqueue')).to eq 1
|
292
|
-
end
|
293
|
-
UntilExecutedJob.sidekiq_options log_duplicate_payload: true
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
describe '#call' do
|
298
|
-
let(:worker_class) { SimpleWorker }
|
299
|
-
let(:item) do
|
300
|
-
{ 'class' => SimpleWorker,
|
301
|
-
'queue' => 'default',
|
302
|
-
'args' => [1] }
|
303
|
-
end
|
304
|
-
let(:queue) { 'default' }
|
305
|
-
context 'when ordinary_or_locked?' do
|
306
|
-
before do
|
307
|
-
allow(subject).to receive(:disabled_or_successfully_locked?).and_return(false)
|
308
|
-
end
|
309
|
-
|
310
|
-
it 'returns nil' do
|
311
|
-
expect(subject.call(worker_class, item, queue))
|
312
|
-
.to eq(nil)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|