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.

Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +6 -7
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  4. data/.reek.yml +17 -48
  5. data/.rubocop.yml +3 -0
  6. data/.yardopts +7 -0
  7. data/CHANGELOG.md +2 -0
  8. data/README.md +65 -23
  9. data/assets/unique_digests_1.png +0 -0
  10. data/assets/unique_digests_2.png +0 -0
  11. data/examples/another_unique_job.rb +4 -2
  12. data/examples/custom_queue_job_with_filter_method.rb +1 -1
  13. data/examples/custom_queue_job_with_filter_proc.rb +1 -1
  14. data/examples/expiring_job.rb +1 -1
  15. data/examples/inline_worker.rb +1 -1
  16. data/examples/just_a_worker.rb +1 -1
  17. data/examples/long_running_job.rb +4 -2
  18. data/examples/main_job.rb +3 -2
  19. data/examples/my_unique_job.rb +4 -5
  20. data/examples/my_unique_job_with_filter_method.rb +3 -3
  21. data/examples/my_unique_job_with_filter_proc.rb +3 -3
  22. data/examples/notify_worker.rb +2 -2
  23. data/examples/simple_worker.rb +2 -2
  24. data/examples/unique_across_workers_job.rb +1 -1
  25. data/examples/unique_job_on_conflict_raise.rb +14 -0
  26. data/examples/unique_job_on_conflict_reject.rb +14 -0
  27. data/examples/unique_job_on_conflict_reschedule.rb +14 -0
  28. data/examples/unique_job_with_conditional_parameter.rb +3 -3
  29. data/examples/unique_job_with_filter_method.rb +5 -2
  30. data/examples/unique_job_with_nil_unique_args.rb +3 -3
  31. data/examples/unique_job_with_no_unique_args_method.rb +3 -3
  32. data/examples/unique_job_withthout_unique_args_parameter.rb +3 -3
  33. data/examples/unique_on_all_queues_job.rb +1 -1
  34. data/examples/until_and_while_executing_job.rb +4 -1
  35. data/examples/until_executed_2_job.rb +5 -5
  36. data/examples/until_executed_job.rb +5 -5
  37. data/examples/until_executing_job.rb +1 -1
  38. data/examples/until_expired_job.rb +1 -1
  39. data/examples/until_global_expired_job.rb +1 -1
  40. data/examples/while_executing_job.rb +2 -2
  41. data/examples/while_executing_reject_job.rb +2 -2
  42. data/examples/without_argument_job.rb +1 -1
  43. data/lib/sidekiq_unique_jobs.rb +30 -0
  44. data/lib/sidekiq_unique_jobs/client/middleware.rb +12 -1
  45. data/lib/sidekiq_unique_jobs/connection.rb +5 -1
  46. data/lib/sidekiq_unique_jobs/constants.rb +3 -0
  47. data/lib/sidekiq_unique_jobs/digests.rb +111 -0
  48. data/lib/sidekiq_unique_jobs/exceptions.rb +15 -16
  49. data/lib/sidekiq_unique_jobs/lock/base_lock.rb +44 -3
  50. data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +13 -3
  51. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +8 -1
  52. data/lib/sidekiq_unique_jobs/lock/until_executing.rb +8 -1
  53. data/lib/sidekiq_unique_jobs/lock/until_expired.rb +14 -2
  54. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +19 -5
  55. data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +16 -63
  56. data/lib/sidekiq_unique_jobs/locksmith.rb +36 -13
  57. data/lib/sidekiq_unique_jobs/logging.rb +24 -1
  58. data/lib/sidekiq_unique_jobs/normalizer.rb +6 -0
  59. data/lib/sidekiq_unique_jobs/on_conflict.rb +24 -0
  60. data/lib/sidekiq_unique_jobs/on_conflict/log.rb +20 -0
  61. data/lib/sidekiq_unique_jobs/on_conflict/null_strategy.rb +16 -0
  62. data/lib/sidekiq_unique_jobs/on_conflict/raise.rb +17 -0
  63. data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +72 -0
  64. data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +24 -0
  65. data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +28 -0
  66. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +19 -4
  67. data/lib/sidekiq_unique_jobs/scripts.rb +31 -0
  68. data/lib/sidekiq_unique_jobs/server/middleware.rb +10 -0
  69. data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +15 -1
  70. data/lib/sidekiq_unique_jobs/timeout/calculator.rb +17 -4
  71. data/lib/sidekiq_unique_jobs/unique_args.rb +47 -5
  72. data/lib/sidekiq_unique_jobs/unlockable.rb +10 -0
  73. data/lib/sidekiq_unique_jobs/util.rb +12 -7
  74. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  75. data/lib/sidekiq_unique_jobs/web.rb +51 -0
  76. data/lib/sidekiq_unique_jobs/web/helpers.rb +37 -0
  77. data/lib/sidekiq_unique_jobs/web/views/unique_digest.erb +28 -0
  78. data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +42 -0
  79. data/redis/create.lua +4 -2
  80. data/redis/delete.lua +3 -1
  81. data/redis/delete_by_digest.lua +22 -0
  82. data/redis/signal.lua +3 -1
  83. data/sidekiq-unique-jobs.gemspec +2 -0
  84. metadata +49 -3
  85. data/lib/sidekiq_unique_jobs/lock/while_executing_requeue.rb +0 -21
@@ -5,7 +5,7 @@
5
5
  class JustAWorker
6
6
  include Sidekiq::Worker
7
7
 
8
- sidekiq_options unique: :until_executed, queue: :testqueue
8
+ sidekiq_options lock: :until_executed, queue: :testqueue
9
9
 
10
10
  def perform(options = {})
11
11
  options
@@ -4,8 +4,10 @@
4
4
 
5
5
  class LongRunningJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options queue: :customqueue, retry: true, unique: :until_and_while_executing,
8
- lock_expiration: 7_200, retry_count: 10
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 queue: :customqueue, unique: :until_executed,
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]
@@ -4,11 +4,10 @@
4
4
 
5
5
  class MyUniqueJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options queue: :customqueue,
8
- retry: true,
9
- retry_count: 10,
10
- unique: :until_executed,
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 queue: :customqueue,
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 queue: :customqueue,
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']]
@@ -5,8 +5,8 @@
5
5
  class NotifyWorker
6
6
  include Sidekiq::Worker
7
7
 
8
- sidekiq_options queue: :notify_worker,
9
- unique: :until_executed
8
+ sidekiq_options lock: :until_executed,
9
+ queue: :notify_worker
10
10
 
11
11
  def perform(pid, blob)
12
12
  [pid, blob]
@@ -4,8 +4,8 @@
4
4
 
5
5
  class SimpleWorker
6
6
  include Sidekiq::Worker
7
- sidekiq_options queue: :default,
8
- unique: :until_executed,
7
+ sidekiq_options lock: :until_executed,
8
+ queue: :default,
9
9
  unique_args: ->(args) { [args.first] }
10
10
 
11
11
  def perform(args)
@@ -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 unique: :until_executed, unique_across_workers: true
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 UniqueJobOnConflictRaise
6
+ include Sidekiq::Worker
7
+ sidekiq_options lock: :while_executing,
8
+ queue: :customqueue,
9
+ on_conflict: :raise
10
+
11
+ def perform(one, two)
12
+ [one, two]
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+
5
+ class UniqueJobOnConflictReject
6
+ include Sidekiq::Worker
7
+ sidekiq_options lock: :while_executing,
8
+ queue: :customqueue,
9
+ on_conflict: :reject
10
+
11
+ def perform(one, two)
12
+ [one, two]
13
+ end
14
+ end
@@ -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 queue: :customqueue,
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 queue: :customqueue, retry: 1, backtrace: 10,
8
- unique: :while_executing, unique_args: :filtered_args
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 queue: :customqueue,
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 queue: :customqueue,
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 queue: :customqueue,
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 unique: :until_executed, unique_on_all_queues: true
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 queue: :working, unique: :until_and_while_executing, lock_timeout: 0, lock_expiration: nil
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 queue: :working,
12
- retry: 1,
13
- backtrace: 10,
14
- unique: :until_executed,
15
- lock_timeout: 0
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 queue: :working,
12
- retry: 1,
13
- backtrace: 10,
14
- unique: :until_executed,
11
+ sidekiq_options backtrace: 10,
12
+ lock: :until_executed,
13
+ lock_expiration: 5_000,
15
14
  lock_timeout: 0,
16
- lock_expiration: 5000
15
+ queue: :working,
16
+ retry: 1
17
17
 
18
18
  def perform(one, two = nil)
19
19
  [one, two]
@@ -5,7 +5,7 @@
5
5
  class UntilExecutingJob
6
6
  include Sidekiq::Worker
7
7
 
8
- sidekiq_options queue: :working, unique: :until_executing
8
+ sidekiq_options lock: :until_executing, queue: :working
9
9
 
10
10
  def perform; end
11
11
  end
@@ -4,7 +4,7 @@
4
4
 
5
5
  class UntilExpiredJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options unique: :until_expired, lock_expiration: 1, lock_timeout: 0
7
+ sidekiq_options lock: :until_expired, lock_expiration: 1, lock_timeout: 0
8
8
 
9
9
  def perform(one)
10
10
  TestClass.run(one)
@@ -4,7 +4,7 @@
4
4
 
5
5
  class UntilGlobalExpiredJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options unique: :until_expired
7
+ sidekiq_options lock: :until_expired
8
8
 
9
9
  def perform(arg)
10
10
  TestClass.run(arg)
@@ -5,9 +5,9 @@
5
5
  class WhileExecutingJob
6
6
  include Sidekiq::Worker
7
7
  sidekiq_options backtrace: 10,
8
+ lock: :while_executing,
8
9
  queue: :working,
9
- retry: 1,
10
- unique: :while_executing
10
+ retry: 1
11
11
 
12
12
  def perform(args)
13
13
  [args]
@@ -4,8 +4,8 @@
4
4
 
5
5
  class WhileExecutingRejectJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options queue: :rejecting,
8
- unique: :while_executing_reject
7
+ sidekiq_options lock: :while_executing_reject,
8
+ queue: :rejecting
9
9
 
10
10
  def perform(args)
11
11
  sleep 5
@@ -4,7 +4,7 @@
4
4
 
5
5
  class WithoutArgumentJob
6
6
  include Sidekiq::Worker
7
- sidekiq_options unique: :until_executed,
7
+ sidekiq_options lock: :until_executed,
8
8
  log_duplicate_payload: true
9
9
 
10
10
  def perform
@@ -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