sidekiq-unique-jobs 6.0.0.rc6 → 6.0.0.rc7
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/.codeclimate.yml +6 -7
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.reek.yml +17 -48
- data/.rubocop.yml +3 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +2 -0
- data/README.md +65 -23
- data/assets/unique_digests_1.png +0 -0
- data/assets/unique_digests_2.png +0 -0
- data/examples/another_unique_job.rb +4 -2
- data/examples/custom_queue_job_with_filter_method.rb +1 -1
- data/examples/custom_queue_job_with_filter_proc.rb +1 -1
- data/examples/expiring_job.rb +1 -1
- data/examples/inline_worker.rb +1 -1
- data/examples/just_a_worker.rb +1 -1
- data/examples/long_running_job.rb +4 -2
- data/examples/main_job.rb +3 -2
- data/examples/my_unique_job.rb +4 -5
- data/examples/my_unique_job_with_filter_method.rb +3 -3
- data/examples/my_unique_job_with_filter_proc.rb +3 -3
- data/examples/notify_worker.rb +2 -2
- data/examples/simple_worker.rb +2 -2
- data/examples/unique_across_workers_job.rb +1 -1
- data/examples/unique_job_on_conflict_raise.rb +14 -0
- data/examples/unique_job_on_conflict_reject.rb +14 -0
- data/examples/unique_job_on_conflict_reschedule.rb +14 -0
- data/examples/unique_job_with_conditional_parameter.rb +3 -3
- data/examples/unique_job_with_filter_method.rb +5 -2
- data/examples/unique_job_with_nil_unique_args.rb +3 -3
- data/examples/unique_job_with_no_unique_args_method.rb +3 -3
- data/examples/unique_job_withthout_unique_args_parameter.rb +3 -3
- data/examples/unique_on_all_queues_job.rb +1 -1
- data/examples/until_and_while_executing_job.rb +4 -1
- data/examples/until_executed_2_job.rb +5 -5
- data/examples/until_executed_job.rb +5 -5
- data/examples/until_executing_job.rb +1 -1
- data/examples/until_expired_job.rb +1 -1
- data/examples/until_global_expired_job.rb +1 -1
- data/examples/while_executing_job.rb +2 -2
- data/examples/while_executing_reject_job.rb +2 -2
- data/examples/without_argument_job.rb +1 -1
- data/lib/sidekiq_unique_jobs.rb +30 -0
- data/lib/sidekiq_unique_jobs/client/middleware.rb +12 -1
- data/lib/sidekiq_unique_jobs/connection.rb +5 -1
- data/lib/sidekiq_unique_jobs/constants.rb +3 -0
- data/lib/sidekiq_unique_jobs/digests.rb +111 -0
- data/lib/sidekiq_unique_jobs/exceptions.rb +15 -16
- data/lib/sidekiq_unique_jobs/lock/base_lock.rb +44 -3
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +13 -3
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +8 -1
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +8 -1
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +14 -2
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +19 -5
- data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +16 -63
- data/lib/sidekiq_unique_jobs/locksmith.rb +36 -13
- data/lib/sidekiq_unique_jobs/logging.rb +24 -1
- data/lib/sidekiq_unique_jobs/normalizer.rb +6 -0
- data/lib/sidekiq_unique_jobs/on_conflict.rb +24 -0
- data/lib/sidekiq_unique_jobs/on_conflict/log.rb +20 -0
- data/lib/sidekiq_unique_jobs/on_conflict/null_strategy.rb +16 -0
- data/lib/sidekiq_unique_jobs/on_conflict/raise.rb +17 -0
- data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +72 -0
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +24 -0
- data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +28 -0
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +19 -4
- data/lib/sidekiq_unique_jobs/scripts.rb +31 -0
- data/lib/sidekiq_unique_jobs/server/middleware.rb +10 -0
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +15 -1
- data/lib/sidekiq_unique_jobs/timeout/calculator.rb +17 -4
- data/lib/sidekiq_unique_jobs/unique_args.rb +47 -5
- data/lib/sidekiq_unique_jobs/unlockable.rb +10 -0
- data/lib/sidekiq_unique_jobs/util.rb +12 -7
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/lib/sidekiq_unique_jobs/web.rb +51 -0
- data/lib/sidekiq_unique_jobs/web/helpers.rb +37 -0
- data/lib/sidekiq_unique_jobs/web/views/unique_digest.erb +28 -0
- data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +42 -0
- data/redis/create.lua +4 -2
- data/redis/delete.lua +3 -1
- data/redis/delete_by_digest.lua +22 -0
- data/redis/signal.lua +3 -1
- data/sidekiq-unique-jobs.gemspec +2 -0
- metadata +49 -3
- data/lib/sidekiq_unique_jobs/lock/while_executing_requeue.rb +0 -21
data/examples/just_a_worker.rb
CHANGED
@@ -4,8 +4,10 @@
|
|
4
4
|
|
5
5
|
class LongRunningJob
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
8
|
-
lock_expiration: 7_200,
|
7
|
+
sidekiq_options lock: :until_and_while_executing,
|
8
|
+
lock_expiration: 7_200,
|
9
|
+
queue: :customqueue,
|
10
|
+
retry: 10
|
9
11
|
def perform(one, two)
|
10
12
|
[one, two]
|
11
13
|
end
|
data/examples/main_job.rb
CHANGED
@@ -4,8 +4,9 @@
|
|
4
4
|
|
5
5
|
class MainJob
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
8
|
-
log_duplicate_payload: true
|
7
|
+
sidekiq_options lock: :until_executed,
|
8
|
+
log_duplicate_payload: true,
|
9
|
+
queue: :customqueue
|
9
10
|
|
10
11
|
def perform(arg)
|
11
12
|
[arg]
|
data/examples/my_unique_job.rb
CHANGED
@@ -4,11 +4,10 @@
|
|
4
4
|
|
5
5
|
class MyUniqueJob
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
lock_expiration: 7_200
|
7
|
+
sidekiq_options lock: :until_executed,
|
8
|
+
lock_expiration: 7_200,
|
9
|
+
queue: :customqueue,
|
10
|
+
retry: 10
|
12
11
|
|
13
12
|
def perform(one, two)
|
14
13
|
[one, two]
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class MyUniqueJobWithFilterMethod
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: :filtered_args
|
12
12
|
|
13
13
|
def perform(*)
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class MyUniqueJobWithFilterProc
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: (lambda do |args|
|
12
12
|
options = args.extract_options!
|
13
13
|
[args.first, options['type']]
|
data/examples/notify_worker.rb
CHANGED
data/examples/simple_worker.rb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
# - https://github.com/mhenrixon/sidekiq-unique-jobs/blob/master/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb
|
13
13
|
class UniqueAcrossWorkersJob
|
14
14
|
include Sidekiq::Worker
|
15
|
-
sidekiq_options
|
15
|
+
sidekiq_options lock: :until_executed, unique_across_workers: true
|
16
16
|
|
17
17
|
def perform(one, two)
|
18
18
|
[one, two]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
|
5
|
+
class UniqueJobOnConflictReschedule
|
6
|
+
include Sidekiq::Worker
|
7
|
+
sidekiq_options lock: :while_executing,
|
8
|
+
queue: :customqueue,
|
9
|
+
on_conflict: :reschedule
|
10
|
+
|
11
|
+
def perform(one, two)
|
12
|
+
[one, two]
|
13
|
+
end
|
14
|
+
end
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class UniqueJobWithoutUniqueArgsParameter
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: :unique_args
|
12
12
|
|
13
13
|
def perform(conditional = nil)
|
@@ -4,8 +4,11 @@
|
|
4
4
|
|
5
5
|
class UniqueJobWithFilterMethod
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
8
|
-
|
7
|
+
sidekiq_options backtrace: 10,
|
8
|
+
lock: :while_executing,
|
9
|
+
queue: :customqueue,
|
10
|
+
retry: 1,
|
11
|
+
unique_args: :filtered_args
|
9
12
|
|
10
13
|
def perform(*)
|
11
14
|
# NO-OP
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class UniqueJobWithNilUniqueArgs
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: :unique_args
|
12
12
|
|
13
13
|
def perform(args)
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class UniqueJobWithNoUniqueArgsMethod
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: :filtered_args
|
12
12
|
|
13
13
|
def perform(one, two)
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
class UniqueJobWithoutUniqueArgsParameter
|
6
6
|
include Sidekiq::Worker
|
7
|
-
sidekiq_options
|
7
|
+
sidekiq_options backtrace: true,
|
8
|
+
lock: :until_executed,
|
9
|
+
queue: :customqueue,
|
8
10
|
retry: true,
|
9
|
-
backtrace: true,
|
10
|
-
unique: :until_executed,
|
11
11
|
unique_args: :unique_args
|
12
12
|
|
13
13
|
def perform(optional = true)
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# queue removed it won't work.
|
9
9
|
class UniqueOnAllQueuesJob
|
10
10
|
include Sidekiq::Worker
|
11
|
-
sidekiq_options
|
11
|
+
sidekiq_options lock: :until_executed, unique_on_all_queues: true
|
12
12
|
|
13
13
|
def perform(one, two, three = nil)
|
14
14
|
[one, two, three]
|
@@ -5,7 +5,10 @@
|
|
5
5
|
class UntilAndWhileExecutingJob
|
6
6
|
include Sidekiq::Worker
|
7
7
|
|
8
|
-
sidekiq_options
|
8
|
+
sidekiq_options lock: :until_and_while_executing,
|
9
|
+
lock_expiration: nil,
|
10
|
+
lock_timeout: 0,
|
11
|
+
queue: :working
|
9
12
|
|
10
13
|
def perform(sleepy_time)
|
11
14
|
sleep(sleepy_time)
|
@@ -8,11 +8,11 @@
|
|
8
8
|
#
|
9
9
|
class UntilExecuted2Job
|
10
10
|
include Sidekiq::Worker
|
11
|
-
sidekiq_options
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
sidekiq_options backtrace: 10,
|
12
|
+
lock: :until_executed,
|
13
|
+
lock_timeout: 0,
|
14
|
+
queue: :working,
|
15
|
+
retry: 1
|
16
16
|
|
17
17
|
def perform(one, two)
|
18
18
|
[one, two]
|
@@ -8,12 +8,12 @@
|
|
8
8
|
#
|
9
9
|
class UntilExecutedJob
|
10
10
|
include Sidekiq::Worker
|
11
|
-
sidekiq_options
|
12
|
-
|
13
|
-
|
14
|
-
unique: :until_executed,
|
11
|
+
sidekiq_options backtrace: 10,
|
12
|
+
lock: :until_executed,
|
13
|
+
lock_expiration: 5_000,
|
15
14
|
lock_timeout: 0,
|
16
|
-
|
15
|
+
queue: :working,
|
16
|
+
retry: 1
|
17
17
|
|
18
18
|
def perform(one, two = nil)
|
19
19
|
[one, two]
|
data/lib/sidekiq_unique_jobs.rb
CHANGED
@@ -12,6 +12,7 @@ require 'sidekiq_unique_jobs/sidekiq_worker_methods'
|
|
12
12
|
require 'sidekiq_unique_jobs/connection'
|
13
13
|
require 'sidekiq_unique_jobs/exceptions'
|
14
14
|
require 'sidekiq_unique_jobs/util'
|
15
|
+
require 'sidekiq_unique_jobs/digests'
|
15
16
|
require 'sidekiq_unique_jobs/cli'
|
16
17
|
require 'sidekiq_unique_jobs/core_ext'
|
17
18
|
require 'sidekiq_unique_jobs/timeout'
|
@@ -19,10 +20,23 @@ require 'sidekiq_unique_jobs/scripts'
|
|
19
20
|
require 'sidekiq_unique_jobs/unique_args'
|
20
21
|
require 'sidekiq_unique_jobs/unlockable'
|
21
22
|
require 'sidekiq_unique_jobs/locksmith'
|
23
|
+
require 'sidekiq_unique_jobs/lock/base_lock'
|
24
|
+
require 'sidekiq_unique_jobs/lock/until_executed'
|
25
|
+
require 'sidekiq_unique_jobs/lock/until_executing'
|
26
|
+
require 'sidekiq_unique_jobs/lock/until_expired'
|
27
|
+
require 'sidekiq_unique_jobs/lock/while_executing'
|
28
|
+
require 'sidekiq_unique_jobs/lock/while_executing_reject'
|
29
|
+
require 'sidekiq_unique_jobs/lock/until_and_while_executing'
|
22
30
|
require 'sidekiq_unique_jobs/options_with_fallback'
|
23
31
|
require 'sidekiq_unique_jobs/middleware'
|
24
32
|
require 'sidekiq_unique_jobs/sidekiq_unique_ext'
|
33
|
+
require 'sidekiq_unique_jobs/on_conflict'
|
25
34
|
|
35
|
+
# Namespace for this gem
|
36
|
+
#
|
37
|
+
# Contains configuration and utility methods that belongs top level
|
38
|
+
#
|
39
|
+
# @author Mikael Henriksson <mikael@zoolutions.se>
|
26
40
|
module SidekiqUniqueJobs
|
27
41
|
include SidekiqUniqueJobs::Connection
|
28
42
|
|
@@ -36,6 +50,7 @@ module SidekiqUniqueJobs
|
|
36
50
|
:logger,
|
37
51
|
)
|
38
52
|
|
53
|
+
# The current configuration (See: {.configure} on how to configure)
|
39
54
|
def config
|
40
55
|
# Arguments here need to match the definition of the new class (see above)
|
41
56
|
@config ||= Concurrent::MutableStruct::Config.new(
|
@@ -46,14 +61,20 @@ module SidekiqUniqueJobs
|
|
46
61
|
)
|
47
62
|
end
|
48
63
|
|
64
|
+
# The current logger
|
65
|
+
# @return [Logger] the configured logger
|
49
66
|
def logger
|
50
67
|
config.logger
|
51
68
|
end
|
52
69
|
|
70
|
+
# Set a new logger
|
71
|
+
# @param [Logger] other a new logger
|
53
72
|
def logger=(other)
|
54
73
|
config.logger = other
|
55
74
|
end
|
56
75
|
|
76
|
+
# Change global configuration while yielding
|
77
|
+
# @yield control to the caller
|
57
78
|
def use_config(tmp_config)
|
58
79
|
fail ::ArgumentError, "#{name}.#{__method__} needs a block" unless block_given?
|
59
80
|
|
@@ -63,6 +84,15 @@ module SidekiqUniqueJobs
|
|
63
84
|
configure(old_config)
|
64
85
|
end
|
65
86
|
|
87
|
+
# Configure the gem
|
88
|
+
#
|
89
|
+
# This is usually called once at startup of an application
|
90
|
+
# @param [Hash] options global gem options
|
91
|
+
# @option options [Integer] :default_lock_timeout (default is 0)
|
92
|
+
# @option options [true,false] :enabled (default is true)
|
93
|
+
# @option options [String] :unique_prefix (default is 'uniquejobs')
|
94
|
+
# @option options [Logger] :logger (default is Sidekiq.logger)
|
95
|
+
# @yield control to the caller when given block
|
66
96
|
def configure(options = {})
|
67
97
|
if block_given?
|
68
98
|
yield config
|