sidekiq-unique-jobs 5.0.2 → 5.0.4
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 +4 -4
- data/.rubocop.yml +4 -1
- data/Appraisals +1 -1
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +21 -0
- data/bin/bench +1 -1
- data/lib/sidekiq-unique-jobs.rb +3 -1
- data/lib/sidekiq/simulator.rb +4 -10
- data/lib/sidekiq_unique_jobs/cli.rb +2 -0
- 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 +19 -17
- data/lib/sidekiq_unique_jobs/core_ext.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +3 -1
- 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 +2 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/normalizer.rb +2 -0
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +2 -0
- data/lib/sidekiq_unique_jobs/run_lock_failed.rb +2 -0
- data/lib/sidekiq_unique_jobs/script_mock.rb +2 -0
- data/lib/sidekiq_unique_jobs/scripts.rb +15 -10
- 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/server/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +2 -0
- data/lib/sidekiq_unique_jobs/testing.rb +2 -0
- data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +2 -0
- data/lib/sidekiq_unique_jobs/timeout_calculator.rb +2 -0
- data/lib/sidekiq_unique_jobs/unique_args.rb +3 -1
- data/lib/sidekiq_unique_jobs/unlockable.rb +2 -0
- data/lib/sidekiq_unique_jobs/util.rb +5 -3
- data/lib/sidekiq_unique_jobs/version.rb +3 -1
- data/sidekiq-unique-jobs.gemspec +27 -23
- metadata +44 -200
- 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.ru +0 -4
- 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/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-compose.yml +0 -71
- data/rails_example/docker/rails.Dockerfile +0 -27
- 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,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'sidekiq/api'
|
3
|
-
require 'sidekiq/worker'
|
4
|
-
require 'sidekiq_unique_jobs/server/middleware'
|
5
|
-
require 'sidekiq_unique_jobs/client/middleware'
|
6
|
-
require 'sidekiq_unique_jobs/sidekiq_unique_ext'
|
7
|
-
|
8
|
-
RSpec.describe 'Sidekiq::Api' do
|
9
|
-
let(:item) do
|
10
|
-
{ 'class' => JustAWorker,
|
11
|
-
'queue' => 'testqueue',
|
12
|
-
'args' => [foo: 'bar'] }
|
13
|
-
end
|
14
|
-
|
15
|
-
def unique_key
|
16
|
-
SidekiqUniqueJobs::UniqueArgs.digest(
|
17
|
-
'class' => JustAWorker,
|
18
|
-
'queue' => 'testqueue',
|
19
|
-
'args' => [foo: 'bar'],
|
20
|
-
'at' => (Date.today + 1).to_time.to_i,
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def schedule_job
|
25
|
-
JustAWorker.perform_in(60 * 60 * 3, foo: 'bar')
|
26
|
-
end
|
27
|
-
|
28
|
-
def perform_async
|
29
|
-
JustAWorker.perform_async(foo: 'bar')
|
30
|
-
end
|
31
|
-
|
32
|
-
describe Sidekiq::SortedEntry::UniqueExtension do
|
33
|
-
it 'deletes uniqueness lock on delete' do
|
34
|
-
expect(schedule_job).to be_truthy
|
35
|
-
|
36
|
-
Sidekiq::ScheduledSet.new.each(&:delete)
|
37
|
-
Sidekiq.redis do |c|
|
38
|
-
expect(c.exists(unique_key)).to be_falsy
|
39
|
-
end
|
40
|
-
|
41
|
-
expect(schedule_job).to be_truthy
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe Sidekiq::Job::UniqueExtension do
|
46
|
-
it 'deletes uniqueness lock on delete' do
|
47
|
-
jid = perform_async
|
48
|
-
Sidekiq::Queue.new('testqueue').find_job(jid).delete
|
49
|
-
Sidekiq.redis do |c|
|
50
|
-
expect(c.exists(unique_key)).to be_falsy
|
51
|
-
end
|
52
|
-
expect(true).to be_truthy
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe Sidekiq::Queue::UniqueExtension do
|
57
|
-
it 'deletes uniqueness locks on clear' do
|
58
|
-
perform_async
|
59
|
-
Sidekiq::Queue.new('testqueue').clear
|
60
|
-
Sidekiq.redis do |c|
|
61
|
-
expect(c.exists(unique_key)).to be_falsy
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe Sidekiq::JobSet::UniqueExtension do
|
67
|
-
it 'deletes uniqueness locks on clear' do
|
68
|
-
schedule_job
|
69
|
-
Sidekiq::JobSet.new('schedule').clear
|
70
|
-
Sidekiq.redis do |c|
|
71
|
-
expect(c.exists(unique_key)).to be_falsy
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
RSpec.describe SidekiqUniqueJobs do
|
3
|
-
describe '.configure_middleware' do
|
4
|
-
it 'configures both client and server middleware' do
|
5
|
-
expect(described_class).to receive(:configure_server_middleware)
|
6
|
-
expect(described_class).to receive(:configure_client_middleware)
|
7
|
-
|
8
|
-
described_class.configure_middleware
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '.configure_server_middleware' do
|
13
|
-
let(:server_config) { class_double(Sidekiq) }
|
14
|
-
let(:server_middleware) { double(Sidekiq::Middleware::Chain) }
|
15
|
-
let(:client_middleware) { double(Sidekiq::Middleware::Chain) }
|
16
|
-
|
17
|
-
it 'adds client and server middleware when required' do
|
18
|
-
expect(Sidekiq).to receive(:configure_server).and_yield(server_config)
|
19
|
-
|
20
|
-
expect(server_config).to receive(:client_middleware).and_yield(client_middleware)
|
21
|
-
expect(client_middleware).to receive(:add).with(SidekiqUniqueJobs::Client::Middleware)
|
22
|
-
|
23
|
-
expect(server_config).to receive(:server_middleware).and_yield(server_middleware)
|
24
|
-
expect(server_middleware).to receive(:add).with(SidekiqUniqueJobs::Server::Middleware)
|
25
|
-
described_class.configure_server_middleware
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '.configure_client_middleware' do
|
30
|
-
let(:client_config) { class_double(Sidekiq) }
|
31
|
-
let(:client_middleware) { double(Sidekiq::Middleware::Chain) }
|
32
|
-
|
33
|
-
it 'adds client middleware when required' do
|
34
|
-
expect(Sidekiq).to receive(:configure_client).and_yield(client_config)
|
35
|
-
expect(client_config).to receive(:client_middleware).and_yield(client_middleware)
|
36
|
-
expect(client_middleware).to receive(:add).with(SidekiqUniqueJobs::Client::Middleware)
|
37
|
-
|
38
|
-
described_class.configure_client_middleware
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::TimeoutCalculator do
|
4
|
-
shared_context 'undefined worker class' do
|
5
|
-
subject { described_class.new('class' => 'test') }
|
6
|
-
end
|
7
|
-
|
8
|
-
shared_context 'item not scheduled' do
|
9
|
-
subject { described_class.new('class' => 'MyUniqueJob') }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'public api' do
|
13
|
-
subject { described_class.new(nil) }
|
14
|
-
it { is_expected.to respond_to(:time_until_scheduled) }
|
15
|
-
it { is_expected.to respond_to(:worker_class_queue_lock_expiration) }
|
16
|
-
it { is_expected.to respond_to(:worker_class_run_lock_expiration) }
|
17
|
-
it { is_expected.to respond_to(:worker_class) }
|
18
|
-
it { is_expected.to respond_to(:seconds) }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '.for_item' do
|
22
|
-
it 'initializes a new calculator' do
|
23
|
-
expect(described_class).to receive(:new).with('WAT')
|
24
|
-
described_class.for_item('WAT')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#time_until_scheduled' do
|
29
|
-
it_behaves_like 'item not scheduled' do
|
30
|
-
its(:time_until_scheduled) { is_expected.to eq(0) }
|
31
|
-
end
|
32
|
-
|
33
|
-
subject { described_class.new('class' => 'MyUniqueJob', 'at' => schedule_time) }
|
34
|
-
let(:schedule_time) { Time.now.utc.to_i + 24 * 60 * 60 }
|
35
|
-
let(:now_in_utc) { Time.now.utc.to_i }
|
36
|
-
|
37
|
-
its(:time_until_scheduled) do
|
38
|
-
Timecop.travel(Time.at(now_in_utc)) do
|
39
|
-
is_expected.to be_within(1).of(schedule_time - now_in_utc)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#worker_class_queue_lock_expiration' do
|
45
|
-
it_behaves_like 'undefined worker class' do
|
46
|
-
its(:worker_class_queue_lock_expiration) { is_expected.to eq(nil) }
|
47
|
-
end
|
48
|
-
|
49
|
-
subject { described_class.new('class' => 'MyUniqueJob') }
|
50
|
-
its(:worker_class_queue_lock_expiration) { is_expected.to eq(7_200) }
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#worker_class_run_lock_expiration' do
|
54
|
-
it_behaves_like 'undefined worker class' do
|
55
|
-
its(:worker_class_run_lock_expiration) { is_expected.to eq(nil) }
|
56
|
-
end
|
57
|
-
|
58
|
-
subject { described_class.new('class' => 'LongRunningJob') }
|
59
|
-
its(:worker_class_run_lock_expiration) { is_expected.to eq(7_200) }
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#worker_class' do
|
63
|
-
it_behaves_like 'undefined worker class' do
|
64
|
-
its(:worker_class) { is_expected.to eq('test') }
|
65
|
-
end
|
66
|
-
|
67
|
-
subject { described_class.new('class' => 'MyJob') }
|
68
|
-
its(:worker_class) { is_expected.to eq(MyJob) }
|
69
|
-
end
|
70
|
-
end
|
@@ -1,257 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::UniqueArgs do
|
4
|
-
let(:item) { { 'class' => 'UntilExecutedJob', 'queue' => 'myqueue', 'args' => [[1, 2]] } }
|
5
|
-
subject { described_class.new(item) }
|
6
|
-
describe '#unique_digest' do
|
7
|
-
context 'when args are empty' do
|
8
|
-
let(:item) { { 'class' => 'WithoutArgumentJob', 'args' => [] } }
|
9
|
-
let(:another_subject) { described_class.new(item) }
|
10
|
-
|
11
|
-
context 'with the same unique args' do
|
12
|
-
it 'equals to unique_digest for that item' do
|
13
|
-
expect(subject.unique_digest).to eq(another_subject.unique_digest)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
shared_examples 'unique digest' do
|
19
|
-
subject { described_class.new(item_options) }
|
20
|
-
context 'given another item' do
|
21
|
-
let(:another_subject) { described_class.new(another_item) }
|
22
|
-
|
23
|
-
context 'with the same unique args' do
|
24
|
-
let(:another_item) { item_options.merge('args' => [1, 2, 'type' => 'it']) }
|
25
|
-
it 'equals to unique_digest for that item' do
|
26
|
-
expect(subject.unique_digest).to eq(another_subject.unique_digest)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with different unique args' do
|
31
|
-
let(:another_item) { item_options.merge('args' => [1, 3, 'type' => 'that']) }
|
32
|
-
it 'differs from unique_digest for that item' do
|
33
|
-
expect(subject.unique_digest).not_to eq(another_subject.unique_digest)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when unique_args is a proc' do
|
40
|
-
let(:item_options) do
|
41
|
-
{
|
42
|
-
'class' => 'MyUniqueJobWithFilterProc',
|
43
|
-
'queue' => 'customqueue',
|
44
|
-
'args' => [1, 2, 'type' => 'it'],
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
it_behaves_like 'unique digest'
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when unique_args is a symbol' do
|
52
|
-
let(:item_options) do
|
53
|
-
{
|
54
|
-
'class' => 'MyUniqueJobWithFilterMethod',
|
55
|
-
'queue' => 'customqueue',
|
56
|
-
'args' => [1, 2, 'type' => 'it'],
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
it_behaves_like 'unique digest'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#unique_args_enabled?' do
|
65
|
-
with_default_worker_options(unique: :until_executed, unique_args: ->(args) { args[1]['test'] }) do
|
66
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args) do
|
67
|
-
its(:unique_args_enabled?) { is_expected.to eq(:unique_args) }
|
68
|
-
end
|
69
|
-
|
70
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: false) do
|
71
|
-
its(:unique_args_enabled?) { is_expected.to be_a(Proc) }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
with_default_worker_options(unique: false, unique_args: nil) do
|
76
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args) do
|
77
|
-
its(:unique_args_enabled?) { is_expected.to eq(:unique_args) }
|
78
|
-
end
|
79
|
-
|
80
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: false) do
|
81
|
-
its(:unique_args_enabled?) { is_expected.to be_falsy }
|
82
|
-
end
|
83
|
-
|
84
|
-
its(:unique_args_enabled?) { is_expected.to be_falsy }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#unique_on_all_queues?' do
|
89
|
-
with_global_config(unique_args_enabled: true) do
|
90
|
-
its(:unique_on_all_queues?) { is_expected.to eq(nil) }
|
91
|
-
|
92
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: true) do
|
93
|
-
its(:unique_on_all_queues?) { is_expected.to eq(true) }
|
94
|
-
end
|
95
|
-
|
96
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: false) do
|
97
|
-
its(:unique_on_all_queues?) { is_expected.to be_falsy }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
with_global_config(unique_args_enabled: false) do
|
102
|
-
its(:unique_on_all_queues?) { is_expected.to eq(nil) }
|
103
|
-
|
104
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: false) do
|
105
|
-
its(:unique_on_all_queues?) { is_expected.to eq(false) }
|
106
|
-
end
|
107
|
-
|
108
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: true) do
|
109
|
-
its(:unique_on_all_queues?) { is_expected.to eq(true) }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#filter_by_proc' do
|
115
|
-
let(:filter) { ->(args) { args[1]['test'] } }
|
116
|
-
let(:args) { [1, 'test' => 'it'] }
|
117
|
-
let(:unique_args) { described_class.new(item) }
|
118
|
-
|
119
|
-
subject { unique_args.filter_by_proc(args) }
|
120
|
-
|
121
|
-
context 'without any default worker options configured' do
|
122
|
-
before do
|
123
|
-
allow(unique_args).to receive(:unique_args_method).and_return(filter)
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'returns the value of theoptions hash ' do
|
127
|
-
expect(subject).to eq('it')
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'when #unique_args_method is nil' do
|
132
|
-
before do
|
133
|
-
allow(unique_args).to receive(:unique_args_method).and_return(nil)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'returns the value of theoptions hash ' do
|
137
|
-
expect(SidekiqUniqueJobs.logger).to receive(:warn) do |&block|
|
138
|
-
expect(block.call).to eq('filter_by_proc : unique_args_method is nil. Returning ([1, {"test"=>"it"}])')
|
139
|
-
end
|
140
|
-
expect(subject).to eq(args)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
with_default_worker_options(unique: :until_executed, unique_args: ->(args) { args[1]['test'] }) do
|
145
|
-
it 'returns the value of the provided options' do
|
146
|
-
expect(subject).to eq('it')
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#filter_by_symbol' do
|
152
|
-
let(:unique_args) { described_class.new(item) }
|
153
|
-
|
154
|
-
context 'when filter is a working symbol' do
|
155
|
-
let(:item) do
|
156
|
-
{ 'class' => 'UniqueJobWithFilterMethod',
|
157
|
-
'queue' => 'myqueue',
|
158
|
-
'args' => [[1, 2]] }
|
159
|
-
end
|
160
|
-
|
161
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
162
|
-
subject { unique_args.filter_by_symbol(args) }
|
163
|
-
|
164
|
-
it 'returns the value of the provided class method' do
|
165
|
-
expected = %w[name test]
|
166
|
-
expect(unique_args.logger).to receive(:debug) do |&block|
|
167
|
-
expect(block.call).to eq("filter_by_symbol : filtered_args(#{args}) => #{expected}")
|
168
|
-
end
|
169
|
-
expect(subject).to eq(expected)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'when worker takes conditional parameters' do
|
174
|
-
let(:item) do
|
175
|
-
{ 'class' => 'UniqueJobWithoutUniqueArgsParameter',
|
176
|
-
'queue' => 'myqueue',
|
177
|
-
'args' => [1] }
|
178
|
-
end
|
179
|
-
let(:args) { [1] }
|
180
|
-
|
181
|
-
subject { unique_args.filter_by_symbol(args) }
|
182
|
-
|
183
|
-
it 'returns the value of the provided class method' do
|
184
|
-
expect(subject).to eq(args)
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when provided nil' do
|
188
|
-
let(:args) { [] }
|
189
|
-
it 'returns the value of the provided class method' do
|
190
|
-
expect(subject).to eq(args)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context "when workers unique_args method doesn't take parameters" do
|
196
|
-
let(:item) do
|
197
|
-
{ 'class' => 'UniqueJobWithoutUniqueArgsParameter',
|
198
|
-
'queue' => 'myqueue',
|
199
|
-
'args' => [[1, 2]] }
|
200
|
-
end
|
201
|
-
|
202
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
203
|
-
subject { unique_args.filter_by_symbol(args) }
|
204
|
-
|
205
|
-
it 'returns the value of the provided class method' do
|
206
|
-
expect(unique_args.logger)
|
207
|
-
.to receive(:fatal)
|
208
|
-
.with('filter_by_symbol : UniqueJobWithoutUniqueArgsParameter\'s unique_args needs at least one argument')
|
209
|
-
expect(unique_args.logger).to receive(:fatal).with a_kind_of(ArgumentError)
|
210
|
-
|
211
|
-
expect(subject).to eq(args)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'when @worker_class does not respond_to unique_args_method' do
|
216
|
-
let(:item) do
|
217
|
-
{ 'class' => 'UniqueJobWithNoUniqueArgsMethod',
|
218
|
-
'queue' => 'myqueue',
|
219
|
-
'args' => [[1, 2]] }
|
220
|
-
end
|
221
|
-
|
222
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
223
|
-
subject { unique_args.filter_by_symbol(args) }
|
224
|
-
|
225
|
-
it 'returns the value of the provided class method' do
|
226
|
-
expect(unique_args.logger).to receive(:warn) do |&block|
|
227
|
-
expect(block.call)
|
228
|
-
.to eq(
|
229
|
-
"filter_by_symbol : UniqueJobWithNoUniqueArgsMethod does not respond to filtered_args). " \
|
230
|
-
"Returning (#{args})",
|
231
|
-
)
|
232
|
-
end
|
233
|
-
|
234
|
-
expect(subject).to eq(args)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context 'when workers unique_args method returns nil' do
|
239
|
-
let(:item) do
|
240
|
-
{ 'class' => 'UniqueJobWithNilUniqueArgs',
|
241
|
-
'queue' => 'myqueue',
|
242
|
-
'args' => [[1, 2]] }
|
243
|
-
end
|
244
|
-
|
245
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
246
|
-
subject { unique_args.filter_by_symbol(args) }
|
247
|
-
|
248
|
-
it 'returns the value of the provided class method' do
|
249
|
-
expect(unique_args.logger).to receive(:debug) do |&block|
|
250
|
-
expect(block.call).to eq("filter_by_symbol : unique_args(#{args}) => ")
|
251
|
-
end
|
252
|
-
|
253
|
-
expect(subject).to eq(nil)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Unlockable do
|
4
|
-
def item_with_digest
|
5
|
-
SidekiqUniqueJobs::UniqueArgs.digest(item)
|
6
|
-
item
|
7
|
-
end
|
8
|
-
let(:item) do
|
9
|
-
{ 'class' => MyUniqueJob,
|
10
|
-
'queue' => 'customqueue',
|
11
|
-
'args' => [1, 2] }
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:unique_digest) { item_with_digest[SidekiqUniqueJobs::UNIQUE_DIGEST_KEY] }
|
15
|
-
describe '.unlock_by_key' do
|
16
|
-
before do
|
17
|
-
end
|
18
|
-
|
19
|
-
specify do
|
20
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(0)
|
21
|
-
jid = Sidekiq::Client.push(item_with_digest)
|
22
|
-
|
23
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(1)
|
24
|
-
expect(SidekiqUniqueJobs::Util.keys).to match_array([unique_digest])
|
25
|
-
expect(SidekiqUniqueJobs::Util.unique_key(jid)).to eq(unique_digest)
|
26
|
-
|
27
|
-
described_class.unlock_by_key(
|
28
|
-
unique_digest,
|
29
|
-
jid,
|
30
|
-
)
|
31
|
-
|
32
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(0)
|
33
|
-
expect(SidekiqUniqueJobs::Util.keys).not_to match_array([unique_digest])
|
34
|
-
expect(SidekiqUniqueJobs::Util.unique_key(jid)).to eq(nil)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|