sidekiq-unique-jobs 6.0.7 → 7.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1880 -156
- data/README.md +818 -238
- data/bin/uniquejobs +2 -2
- data/lib/sidekiq-unique-jobs.rb +1 -1
- data/lib/sidekiq_unique_jobs/batch_delete.rb +124 -0
- data/lib/sidekiq_unique_jobs/changelog.rb +78 -0
- data/lib/sidekiq_unique_jobs/cli.rb +68 -25
- data/lib/sidekiq_unique_jobs/config.rb +319 -0
- data/lib/sidekiq_unique_jobs/connection.rb +6 -5
- data/lib/sidekiq_unique_jobs/constants.rb +50 -20
- data/lib/sidekiq_unique_jobs/core_ext.rb +80 -0
- data/lib/sidekiq_unique_jobs/deprecation.rb +65 -0
- data/lib/sidekiq_unique_jobs/digests.rb +70 -87
- data/lib/sidekiq_unique_jobs/exceptions.rb +88 -12
- data/lib/sidekiq_unique_jobs/expiring_digests.rb +14 -0
- data/lib/sidekiq_unique_jobs/job.rb +47 -13
- data/lib/sidekiq_unique_jobs/json.rb +47 -0
- data/lib/sidekiq_unique_jobs/key.rb +98 -0
- data/lib/sidekiq_unique_jobs/lock/base_lock.rb +111 -82
- data/lib/sidekiq_unique_jobs/lock/client_validator.rb +28 -0
- data/lib/sidekiq_unique_jobs/lock/server_validator.rb +27 -0
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +45 -5
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +30 -4
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +26 -2
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +27 -15
- data/lib/sidekiq_unique_jobs/lock/validator.rb +96 -0
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +26 -7
- data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +3 -11
- data/lib/sidekiq_unique_jobs/lock.rb +342 -0
- data/lib/sidekiq_unique_jobs/lock_args.rb +127 -0
- data/lib/sidekiq_unique_jobs/lock_config.rb +126 -0
- data/lib/sidekiq_unique_jobs/lock_digest.rb +79 -0
- data/lib/sidekiq_unique_jobs/lock_info.rb +68 -0
- data/lib/sidekiq_unique_jobs/lock_timeout.rb +62 -0
- data/lib/sidekiq_unique_jobs/lock_ttl.rb +77 -0
- data/lib/sidekiq_unique_jobs/lock_type.rb +37 -0
- data/lib/sidekiq_unique_jobs/locksmith.rb +324 -95
- data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +44 -0
- data/lib/sidekiq_unique_jobs/logging.rb +208 -30
- data/lib/sidekiq_unique_jobs/lua/delete.lua +51 -0
- data/lib/sidekiq_unique_jobs/lua/delete_by_digest.lua +42 -0
- data/lib/sidekiq_unique_jobs/lua/delete_job_by_digest.lua +38 -0
- data/lib/sidekiq_unique_jobs/lua/find_digest_in_queues.lua +26 -0
- data/lib/sidekiq_unique_jobs/lua/lock.lua +99 -0
- data/lib/sidekiq_unique_jobs/lua/lock_until_expired.lua +92 -0
- data/lib/sidekiq_unique_jobs/lua/locked.lua +35 -0
- data/lib/sidekiq_unique_jobs/lua/queue.lua +87 -0
- data/lib/sidekiq_unique_jobs/lua/reap_orphans.lua +122 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +40 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_current_time.lua +8 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_queue.lua +22 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua +18 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua +53 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_queues.lua +43 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_sorted_set.lua +24 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_hgetall.lua +13 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_upgrades.lua +3 -0
- data/lib/sidekiq_unique_jobs/lua/unlock.lua +107 -0
- data/lib/sidekiq_unique_jobs/lua/update_version.lua +40 -0
- data/lib/sidekiq_unique_jobs/lua/upgrade.lua +68 -0
- data/lib/sidekiq_unique_jobs/middleware/client.rb +42 -0
- data/lib/sidekiq_unique_jobs/middleware/server.rb +31 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +33 -30
- data/lib/sidekiq_unique_jobs/normalizer.rb +4 -4
- data/lib/sidekiq_unique_jobs/on_conflict/log.rb +9 -5
- data/lib/sidekiq_unique_jobs/on_conflict/null_strategy.rb +1 -1
- data/lib/sidekiq_unique_jobs/on_conflict/raise.rb +2 -2
- data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +63 -17
- data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +54 -14
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +16 -5
- data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +26 -7
- data/lib/sidekiq_unique_jobs/on_conflict.rb +34 -16
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +39 -36
- data/lib/sidekiq_unique_jobs/orphans/lua_reaper.rb +29 -0
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +241 -0
- data/lib/sidekiq_unique_jobs/orphans/null_reaper.rb +24 -0
- data/lib/sidekiq_unique_jobs/orphans/observer.rb +42 -0
- data/lib/sidekiq_unique_jobs/orphans/reaper.rb +114 -0
- data/lib/sidekiq_unique_jobs/orphans/reaper_resurrector.rb +170 -0
- data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +298 -0
- data/lib/sidekiq_unique_jobs/redis/entity.rb +112 -0
- data/lib/sidekiq_unique_jobs/redis/hash.rb +56 -0
- data/lib/sidekiq_unique_jobs/redis/list.rb +32 -0
- data/lib/sidekiq_unique_jobs/redis/set.rb +32 -0
- data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +86 -0
- data/lib/sidekiq_unique_jobs/redis/string.rb +51 -0
- data/lib/sidekiq_unique_jobs/redis.rb +11 -0
- data/lib/sidekiq_unique_jobs/reflectable.rb +26 -0
- data/lib/sidekiq_unique_jobs/reflections.rb +79 -0
- data/lib/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options.rb +51 -0
- data/lib/sidekiq_unique_jobs/rspec/matchers.rb +26 -0
- data/lib/sidekiq_unique_jobs/script/caller.rb +127 -0
- data/lib/sidekiq_unique_jobs/script.rb +15 -0
- data/lib/sidekiq_unique_jobs/server.rb +61 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +115 -66
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +304 -0
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +51 -29
- data/lib/sidekiq_unique_jobs/testing.rb +104 -31
- data/lib/sidekiq_unique_jobs/timer_task.rb +299 -0
- data/lib/sidekiq_unique_jobs/timing.rb +58 -0
- data/lib/sidekiq_unique_jobs/unlockable.rb +20 -4
- data/lib/sidekiq_unique_jobs/update_version.rb +25 -0
- data/lib/sidekiq_unique_jobs/upgrade_locks.rb +155 -0
- data/lib/sidekiq_unique_jobs/version.rb +3 -1
- data/lib/sidekiq_unique_jobs/version_check.rb +114 -0
- data/lib/sidekiq_unique_jobs/web/helpers.rb +140 -15
- data/lib/sidekiq_unique_jobs/web/views/_paging.erb +4 -4
- data/lib/sidekiq_unique_jobs/web/views/changelogs.erb +54 -0
- data/lib/sidekiq_unique_jobs/web/views/lock.erb +110 -0
- data/lib/sidekiq_unique_jobs/web/views/locks.erb +54 -0
- data/lib/sidekiq_unique_jobs/web.rb +86 -29
- data/lib/sidekiq_unique_jobs.rb +78 -105
- data/lib/tasks/changelog.rake +23 -0
- metadata +154 -218
- data/.codeclimate.yml +0 -35
- data/.csslintrc +0 -2
- data/.dockerignore +0 -4
- data/.editorconfig +0 -14
- data/.eslintignore +0 -1
- data/.eslintrc +0 -213
- data/.fasterer.yml +0 -23
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
- data/.gitignore +0 -28
- data/.reek.yml +0 -87
- data/.rspec +0 -2
- data/.rubocop.yml +0 -127
- data/.simplecov +0 -20
- data/.travis.yml +0 -47
- data/.yardopts +0 -7
- data/Appraisals +0 -29
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -24
- data/Guardfile +0 -55
- data/Rakefile +0 -12
- data/_config.yml +0 -1
- data/assets/unique_digests_1.png +0 -0
- data/assets/unique_digests_2.png +0 -0
- data/bin/bench +0 -20
- data/examples/another_unique_job.rb +0 -15
- data/examples/custom_queue_job.rb +0 -12
- data/examples/custom_queue_job_with_filter_method.rb +0 -13
- data/examples/custom_queue_job_with_filter_proc.rb +0 -16
- data/examples/expiring_job.rb +0 -12
- data/examples/inline_worker.rb +0 -12
- data/examples/just_a_worker.rb +0 -13
- data/examples/long_running_job.rb +0 -14
- data/examples/main_job.rb +0 -14
- data/examples/my_job.rb +0 -12
- data/examples/my_unique_job.rb +0 -15
- data/examples/my_unique_job_with_filter_method.rb +0 -21
- data/examples/my_unique_job_with_filter_proc.rb +0 -19
- data/examples/notify_worker.rb +0 -14
- data/examples/plain_class.rb +0 -13
- data/examples/simple_worker.rb +0 -15
- data/examples/spawn_simple_worker.rb +0 -12
- data/examples/test_class.rb +0 -9
- data/examples/unique_across_workers_job.rb +0 -20
- data/examples/unique_job_on_conflict_raise.rb +0 -14
- data/examples/unique_job_on_conflict_reject.rb +0 -14
- data/examples/unique_job_on_conflict_reschedule.rb +0 -14
- data/examples/unique_job_with_conditional_parameter.rb +0 -18
- data/examples/unique_job_with_filter_method.rb +0 -21
- data/examples/unique_job_with_nil_unique_args.rb +0 -20
- data/examples/unique_job_with_no_unique_args_method.rb +0 -16
- data/examples/unique_job_withthout_unique_args_parameter.rb +0 -18
- data/examples/unique_on_all_queues_job.rb +0 -16
- data/examples/until_and_while_executing_job.rb +0 -17
- data/examples/until_executed_2_job.rb +0 -24
- data/examples/until_executed_job.rb +0 -25
- data/examples/until_executing_job.rb +0 -11
- data/examples/until_expired_job.rb +0 -12
- data/examples/until_global_expired_job.rb +0 -12
- data/examples/while_executing_job.rb +0 -15
- data/examples/while_executing_reject_job.rb +0 -14
- data/examples/without_argument_job.rb +0 -13
- data/lib/sidekiq_unique_jobs/client/middleware.rb +0 -56
- data/lib/sidekiq_unique_jobs/scripts.rb +0 -89
- data/lib/sidekiq_unique_jobs/server/middleware.rb +0 -40
- data/lib/sidekiq_unique_jobs/timeout/calculator.rb +0 -63
- data/lib/sidekiq_unique_jobs/timeout.rb +0 -8
- data/lib/sidekiq_unique_jobs/unique_args.rb +0 -149
- data/lib/sidekiq_unique_jobs/util.rb +0 -103
- data/lib/sidekiq_unique_jobs/web/views/unique_digest.erb +0 -28
- data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +0 -42
- data/redis/acquire_lock.lua +0 -21
- data/redis/delete.lua +0 -14
- data/redis/delete_by_digest.lua +0 -24
- data/redis/delete_job_by_digest.lua +0 -60
- data/redis/lock.lua +0 -58
- data/redis/release_stale_locks.lua +0 -90
- data/redis/unlock.lua +0 -32
- data/sidekiq-unique-jobs.gemspec +0 -42
@@ -0,0 +1,155 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SidekiqUniqueJobs
|
4
|
+
#
|
5
|
+
# Upgrades locks between gem version upgrades
|
6
|
+
#
|
7
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
|
+
#
|
9
|
+
class UpgradeLocks # rubocop:disable Metrics/ClassLength
|
10
|
+
#
|
11
|
+
# @return [Integer] the number of keys to batch upgrade
|
12
|
+
BATCH_SIZE = 100
|
13
|
+
#
|
14
|
+
# @return [Array<String>] suffixes for old version
|
15
|
+
OLD_SUFFIXES = %w[
|
16
|
+
GRABBED
|
17
|
+
AVAILABLE
|
18
|
+
EXISTS
|
19
|
+
VERSION
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
include SidekiqUniqueJobs::Logging
|
23
|
+
include SidekiqUniqueJobs::Connection
|
24
|
+
|
25
|
+
#
|
26
|
+
# Performs upgrade of old locks
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# @return [Integer] the number of upgrades locks
|
30
|
+
#
|
31
|
+
def self.call
|
32
|
+
redis do |conn|
|
33
|
+
new(conn).call
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :conn
|
38
|
+
|
39
|
+
def initialize(conn)
|
40
|
+
@count = 0
|
41
|
+
@conn = conn
|
42
|
+
redis_version # Avoid pipelined calling redis_version and getting a future.
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Performs upgrade of old locks
|
47
|
+
#
|
48
|
+
#
|
49
|
+
# @return [Integer] the number of upgrades locks
|
50
|
+
#
|
51
|
+
def call
|
52
|
+
with_logging_context do
|
53
|
+
return log_info("Already upgraded to #{version}") if conn.hget(upgraded_key, version)
|
54
|
+
# TODO: Needs handling of v7.0.0 => v7.0.1 where we don't want to
|
55
|
+
return log_info("Skipping upgrade because #{DEAD_VERSION} has been set") if conn.get(DEAD_VERSION)
|
56
|
+
|
57
|
+
log_info("Start - Upgrading Locks")
|
58
|
+
|
59
|
+
upgrade_v6_locks
|
60
|
+
delete_unused_v6_keys
|
61
|
+
delete_supporting_v6_keys
|
62
|
+
|
63
|
+
conn.hset(upgraded_key, version, now_f)
|
64
|
+
log_info("Done - Upgrading Locks")
|
65
|
+
end
|
66
|
+
|
67
|
+
@count
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def upgraded_key
|
73
|
+
@upgraded_key ||= "#{LIVE_VERSION}:UPGRADED"
|
74
|
+
end
|
75
|
+
|
76
|
+
def upgrade_v6_locks
|
77
|
+
log_info("Start - Converting v6 locks to v7")
|
78
|
+
conn.scan_each(match: "*:GRABBED", count: BATCH_SIZE) do |grabbed_key|
|
79
|
+
upgrade_v6_lock(grabbed_key)
|
80
|
+
@count += 1
|
81
|
+
end
|
82
|
+
log_info("Done - Converting v6 locks to v7")
|
83
|
+
end
|
84
|
+
|
85
|
+
def upgrade_v6_lock(grabbed_key)
|
86
|
+
locked_key = grabbed_key.gsub(":GRABBED", ":LOCKED")
|
87
|
+
digest = grabbed_key.gsub(":GRABBED", "")
|
88
|
+
locks = conn.hgetall(grabbed_key)
|
89
|
+
|
90
|
+
conn.pipelined do |pipeline|
|
91
|
+
pipeline.hmset(locked_key, *locks.to_a)
|
92
|
+
pipeline.zadd(DIGESTS, locks.values.first, digest)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def delete_unused_v6_keys
|
97
|
+
log_info("Start - Deleting v6 keys")
|
98
|
+
OLD_SUFFIXES.each do |suffix|
|
99
|
+
delete_suffix(suffix)
|
100
|
+
end
|
101
|
+
log_info("Done - Deleting v6 keys")
|
102
|
+
end
|
103
|
+
|
104
|
+
def delete_supporting_v6_keys
|
105
|
+
batch_delete("unique:keys")
|
106
|
+
end
|
107
|
+
|
108
|
+
def delete_suffix(suffix)
|
109
|
+
batch_scan(match: "*:#{suffix}", count: BATCH_SIZE) do |keys|
|
110
|
+
batch_delete(*keys)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def batch_delete(*keys)
|
115
|
+
return if keys.empty?
|
116
|
+
|
117
|
+
conn.pipelined do |pipeline|
|
118
|
+
if VersionCheck.satisfied?(redis_version, ">= 4.0.0")
|
119
|
+
pipeline.unlink(*keys)
|
120
|
+
else
|
121
|
+
pipeline.del(*keys)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def batch_scan(match:, count:)
|
127
|
+
cursor = "0"
|
128
|
+
loop do
|
129
|
+
cursor, values = conn.scan(cursor, match: match, count: count)
|
130
|
+
yield values
|
131
|
+
break if cursor == "0"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def version
|
136
|
+
SidekiqUniqueJobs.version
|
137
|
+
end
|
138
|
+
|
139
|
+
def now_f
|
140
|
+
SidekiqUniqueJobs.now_f
|
141
|
+
end
|
142
|
+
|
143
|
+
def redis_version
|
144
|
+
@redis_version ||= SidekiqUniqueJobs.config.redis_version
|
145
|
+
end
|
146
|
+
|
147
|
+
def logging_context
|
148
|
+
if logger_context_hash?
|
149
|
+
{ "uniquejobs" => :upgrade_locks }
|
150
|
+
else
|
151
|
+
"uniquejobs-upgrade_locks"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SidekiqUniqueJobs
|
4
|
+
#
|
5
|
+
# Handles checking if a version is compliant with given constraint
|
6
|
+
#
|
7
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
|
+
#
|
9
|
+
class VersionCheck
|
10
|
+
PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength, Lint/MixedRegexpCaptureTypes
|
11
|
+
|
12
|
+
#
|
13
|
+
# Checks if a version is constraint is satisfied
|
14
|
+
#
|
15
|
+
# @example A satisfied constraint
|
16
|
+
# VersionCheck.satisfied?("5.0.0", ">= 4.0.0") #=> true
|
17
|
+
#
|
18
|
+
# @example An unsatisfied constraint
|
19
|
+
# VersionCheck.satisfied?("5.0.0", "<= 4.0.0") #=> false
|
20
|
+
#
|
21
|
+
#
|
22
|
+
# @param [String] version a version string `5.0.0`
|
23
|
+
# @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
|
24
|
+
#
|
25
|
+
# @return [true, false] <description>
|
26
|
+
#
|
27
|
+
def self.satisfied?(version, constraint)
|
28
|
+
new(version, constraint).satisfied?
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Checks if a version is constraint is unfulfilled
|
33
|
+
#
|
34
|
+
# @example A satisfied constraint
|
35
|
+
# VersionCheck.unfulfilled?("5.0.0", ">= 4.0.0") #=> false
|
36
|
+
#
|
37
|
+
# @example An unfulfilled constraint
|
38
|
+
# VersionCheck.unfulfilled?("5.0.0", "<= 4.0.0") #=> true
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# @param [String] version a version string `5.0.0`
|
42
|
+
# @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
|
43
|
+
#
|
44
|
+
# @return [true, false] <description>
|
45
|
+
#
|
46
|
+
def self.unfulfilled?(version, constraint)
|
47
|
+
!satisfied?(version, constraint)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# @!attribute [r] version
|
52
|
+
# @return [String] a version string `5.0.0`
|
53
|
+
attr_reader :version
|
54
|
+
#
|
55
|
+
# @!attribute [r] match
|
56
|
+
# @return [String] a version constraint `>= 5.0.0 <= 5.1.1`
|
57
|
+
attr_reader :match
|
58
|
+
|
59
|
+
#
|
60
|
+
# Initialize a new VersionCheck instance
|
61
|
+
#
|
62
|
+
# @param [String] version a version string `5.0.0`
|
63
|
+
# @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
|
64
|
+
#
|
65
|
+
def initialize(version, constraint)
|
66
|
+
@version = Gem::Version.new(version)
|
67
|
+
@match = PATTERN.match(constraint.to_s)
|
68
|
+
|
69
|
+
raise ArgumentError, "A version (eg. 5.0) is required to compare against" unless @version
|
70
|
+
raise ArgumentError, "At least one operator and version is required (eg. >= 5.1)" unless constraint
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Checks if all constraints were met
|
75
|
+
#
|
76
|
+
#
|
77
|
+
# @return [true,false]
|
78
|
+
#
|
79
|
+
def satisfied?
|
80
|
+
constraints.all? do |expected, operator|
|
81
|
+
compare(expected, operator)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def compare(expected, operator)
|
88
|
+
Gem::Version.new(version).send(operator, Gem::Version.new(expected))
|
89
|
+
end
|
90
|
+
|
91
|
+
def constraints
|
92
|
+
result = { version_one => operator_one }
|
93
|
+
result[version_two] = operator_two if version_two
|
94
|
+
|
95
|
+
result
|
96
|
+
end
|
97
|
+
|
98
|
+
def version_one
|
99
|
+
match[:version1]
|
100
|
+
end
|
101
|
+
|
102
|
+
def operator_one
|
103
|
+
match[:operator1]
|
104
|
+
end
|
105
|
+
|
106
|
+
def version_two
|
107
|
+
match[:version2]
|
108
|
+
end
|
109
|
+
|
110
|
+
def operator_two
|
111
|
+
match[:operator2]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -2,28 +2,120 @@
|
|
2
2
|
|
3
3
|
module SidekiqUniqueJobs
|
4
4
|
module Web
|
5
|
+
#
|
6
|
+
# Provides view helpers for the Sidekiq::Web extension
|
7
|
+
#
|
8
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
9
|
+
#
|
5
10
|
module Helpers
|
6
|
-
|
11
|
+
#
|
12
|
+
# @return [String] the path to gem specific views
|
13
|
+
VIEW_PATH = File.expand_path("../web/views", __dir__).freeze
|
14
|
+
#
|
15
|
+
# @return [Array<String>] safe params
|
16
|
+
SAFE_CPARAMS = %w[
|
17
|
+
filter count cursor prev_cursor poll direction
|
18
|
+
].freeze
|
7
19
|
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Opens a template file contained within this gem
|
24
|
+
#
|
25
|
+
# @param [Symbol] name the name of the template
|
26
|
+
#
|
27
|
+
# @return [String] the file contents of the template
|
28
|
+
#
|
8
29
|
def unique_template(name)
|
9
|
-
File.
|
30
|
+
File.read(unique_filename(name))
|
10
31
|
end
|
11
32
|
|
12
|
-
|
33
|
+
#
|
34
|
+
# Construct template file name
|
35
|
+
#
|
36
|
+
# @param [Symbol] name the name of the template
|
37
|
+
#
|
38
|
+
# @return [String] the full name of the file
|
39
|
+
#
|
40
|
+
def unique_filename(name)
|
41
|
+
File.join(VIEW_PATH, "#{name}.erb")
|
42
|
+
end
|
13
43
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
44
|
+
#
|
45
|
+
# The collection of digests
|
46
|
+
#
|
47
|
+
#
|
48
|
+
# @return [SidekiqUniqueJobs::Digests] the sorted set with digests
|
49
|
+
#
|
50
|
+
def digests
|
51
|
+
@digests ||= SidekiqUniqueJobs::Digests.new
|
52
|
+
end
|
19
53
|
|
20
|
-
|
54
|
+
#
|
55
|
+
# The collection of digests
|
56
|
+
#
|
57
|
+
#
|
58
|
+
# @return [SidekiqUniqueJobs::ExpiringDigests] the sorted set with expiring digests
|
59
|
+
#
|
60
|
+
def expiring_digests
|
61
|
+
@expiring_digests ||= SidekiqUniqueJobs::ExpiringDigests.new
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# The collection of changelog entries
|
66
|
+
#
|
67
|
+
#
|
68
|
+
# @return [SidekiqUniqueJobs::Digests] the sorted set with digests
|
69
|
+
#
|
70
|
+
def changelog
|
71
|
+
@changelog ||= SidekiqUniqueJobs::Changelog.new
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Creates url safe parameters
|
76
|
+
#
|
77
|
+
# @param [Hash] options the key/value to parameterize
|
78
|
+
#
|
79
|
+
# @return [String] a url safe parameter string
|
80
|
+
#
|
81
|
+
def cparams(options)
|
82
|
+
stringified_options = options.transform_keys(&:to_s)
|
83
|
+
params.merge(stringified_options).map do |key, value|
|
21
84
|
next unless SAFE_CPARAMS.include?(key)
|
22
85
|
|
23
86
|
"#{key}=#{CGI.escape(value.to_s)}"
|
24
|
-
end.compact.join(
|
87
|
+
end.compact.join("&")
|
25
88
|
end
|
26
89
|
|
90
|
+
#
|
91
|
+
# Used to avoid incompatibility with older sidekiq versions
|
92
|
+
#
|
93
|
+
#
|
94
|
+
# @param [Array] args the unique arguments to display
|
95
|
+
# @param [Integer] truncate_after_chars
|
96
|
+
#
|
97
|
+
# @return [String] a string containing all non-truncated arguments
|
98
|
+
#
|
99
|
+
def display_lock_args(args, truncate_after_chars = 2000)
|
100
|
+
return "Invalid job payload, args is nil" if args.nil?
|
101
|
+
return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array)
|
102
|
+
|
103
|
+
begin
|
104
|
+
args.map do |arg|
|
105
|
+
h(truncate(to_display(arg), truncate_after_chars))
|
106
|
+
end.join(", ")
|
107
|
+
rescue StandardError
|
108
|
+
"Illegal job arguments: #{h args.inspect}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Redirect to with falback
|
114
|
+
#
|
115
|
+
# @param [String] subpath the path to redirect to
|
116
|
+
#
|
117
|
+
# @return a redirect to the new subpath
|
118
|
+
#
|
27
119
|
def redirect_to(subpath)
|
28
120
|
if respond_to?(:to)
|
29
121
|
# Sinatra-based web UI
|
@@ -34,15 +126,48 @@ module SidekiqUniqueJobs
|
|
34
126
|
end
|
35
127
|
end
|
36
128
|
|
129
|
+
#
|
130
|
+
# Gets a relative time as html
|
131
|
+
#
|
132
|
+
# @param [Time] time an instance of Time
|
133
|
+
#
|
134
|
+
# @return [String] a html safe string with relative time information
|
135
|
+
#
|
136
|
+
def relative_time(time)
|
137
|
+
stamp = time.getutc.iso8601
|
138
|
+
%(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>)
|
139
|
+
end
|
140
|
+
|
141
|
+
#
|
142
|
+
# Gets a relative time as html without crashing
|
143
|
+
#
|
144
|
+
# @param [Float, Integer, String, Time] time a representation of a timestamp
|
145
|
+
#
|
146
|
+
# @return [String] a html safe string with relative time information
|
147
|
+
#
|
37
148
|
def safe_relative_time(time)
|
38
|
-
time =
|
39
|
-
Time.at(time)
|
40
|
-
else
|
41
|
-
Time.parse(time)
|
42
|
-
end
|
149
|
+
time = parse_time(time)
|
43
150
|
|
44
151
|
relative_time(time)
|
45
152
|
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# Constructs a time from a number of different types
|
156
|
+
#
|
157
|
+
# @param [Float, Integer, String, Time] time a representation of a timestamp
|
158
|
+
#
|
159
|
+
# @return [Time]
|
160
|
+
#
|
161
|
+
def parse_time(time)
|
162
|
+
case time
|
163
|
+
when Time
|
164
|
+
time
|
165
|
+
when Integer, Float
|
166
|
+
Time.at(time)
|
167
|
+
else
|
168
|
+
Time.parse(time.to_s)
|
169
|
+
end
|
170
|
+
end
|
46
171
|
end
|
47
172
|
end
|
48
173
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<ul class="pagination pull-right flip">
|
2
2
|
<% if @prev_cursor %>
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
<li>
|
4
|
+
<a href="<%= url %>?<%= cparams(filter: @filter, cursor: @prev_cursor, prev_cursor: @next_cursor) %>">Previous <%= @count %></a>
|
5
|
+
</li>
|
6
6
|
<% end %>
|
7
7
|
<li>
|
8
|
-
<a href="<%= url %>?<%= cparams(cursor: @next_cursor, prev_cursor: @current_cursor) %>">Next <%= @count %></a>
|
8
|
+
<a href="<%= url %>?<%= cparams(filter: @filter, cursor: @next_cursor, prev_cursor: @current_cursor) %>">Next <%= @count %></a>
|
9
9
|
</li>
|
10
10
|
</ul>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
<header class="row">
|
2
|
+
<div class="col-sm-5">
|
3
|
+
<h3>
|
4
|
+
<%= t('Changelog Entries') %>
|
5
|
+
</h3>
|
6
|
+
</div>
|
7
|
+
<form action="<%= root_path %>changelogs" class="form form-inline" method="get">
|
8
|
+
<%= csrf_tag %>
|
9
|
+
<input name="filter" class="form-control" type="text" value="<%= @filter %>" />
|
10
|
+
<button class="btn btn-default" type="submit">
|
11
|
+
<%= t('Filter') %>
|
12
|
+
</button>
|
13
|
+
</form>
|
14
|
+
<% if @changelogs.any? && @total_size > @count.to_i %>
|
15
|
+
<div class="col-sm-4">
|
16
|
+
<%= erb unique_template(:_paging), locals: { url: "#{root_path}changelogs" } %>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
</header>
|
20
|
+
<% if @changelogs.any? %>
|
21
|
+
<div class="table_container">
|
22
|
+
<form action="<%= root_path %>changelogs/delete_all" method="get">
|
23
|
+
<input class="btn btn-danger btn-xs" type="submit" name="delete_all" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSure') %>" />
|
24
|
+
</form>
|
25
|
+
<br/>
|
26
|
+
<table class="table table-striped table-bordered table-hover">
|
27
|
+
<thead>
|
28
|
+
<tr>
|
29
|
+
<th><%= t('Time') %></th>
|
30
|
+
<th><%= t('Digest') %></th>
|
31
|
+
<th><%= t('Script') %></th>
|
32
|
+
<th><%= t('JID') %></th>
|
33
|
+
<th><%= t('Prev JID') %></th>
|
34
|
+
<th><%= t('Message') %></th>
|
35
|
+
</tr>
|
36
|
+
</thead>
|
37
|
+
<tbody>
|
38
|
+
<% @changelogs.each do |changelog| %>
|
39
|
+
<tr class="changelog-row">
|
40
|
+
<td><%= safe_relative_time(changelog["time"]) %></td>
|
41
|
+
<td><%= changelog["digest"] %></td>
|
42
|
+
<td><%= changelog["script"] %></td>
|
43
|
+
<td><%= changelog["job_id"] %></td>
|
44
|
+
<td><%= changelog["prev_jid"] %></td>
|
45
|
+
<td><%= changelog["message"] %></th>
|
46
|
+
</tr>
|
47
|
+
<% end %>
|
48
|
+
</tbody>
|
49
|
+
</table>
|
50
|
+
<form action="<%= root_path %>changelogs/delete_all" method="get">
|
51
|
+
<input class="btn btn-danger btn-xs" type="submit" name="delete_all" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSure') %>" />
|
52
|
+
</form>
|
53
|
+
</div>
|
54
|
+
<% end %>
|
@@ -0,0 +1,110 @@
|
|
1
|
+
<header class="row">
|
2
|
+
<div class="col-sm-5">
|
3
|
+
<h3>
|
4
|
+
<%= t('Lock information') %> <a class="btn btn-default btn-xs" href="<%= root_path %>locks"><%= t('GoBack') %></a>
|
5
|
+
</h3>
|
6
|
+
</div>
|
7
|
+
<div class="col-sm-7 table-responsive">
|
8
|
+
<% if @lock.info.none? %>
|
9
|
+
<h3>No Lock Information Available</h3>
|
10
|
+
<% unless SidekiqUniqueJobs.config.lock_info %>
|
11
|
+
<p>To use it turn the following setting on:
|
12
|
+
<code>SidekiqUniqueJobs.config.lock_info = true</code>
|
13
|
+
</p>
|
14
|
+
<% end %>
|
15
|
+
<% else %>
|
16
|
+
<table class="table table-striped table-bordered table-white table-hover">
|
17
|
+
<caption>Information about lock</caption>
|
18
|
+
<tbody>
|
19
|
+
<tr>
|
20
|
+
<th scope=row><%= t('Worker') %></td>
|
21
|
+
<td><%= @lock.info["worker"] %></td>
|
22
|
+
</tr>
|
23
|
+
<tr>
|
24
|
+
<th scope=row><%= t('Queue') %></td>
|
25
|
+
<td><%= @lock.info["queue"] %></td>
|
26
|
+
</tr>
|
27
|
+
<tr>
|
28
|
+
<th scope=row><%= t('Limit') %></td>
|
29
|
+
<td><%= @lock.info["limit"] %></td>
|
30
|
+
</tr>
|
31
|
+
<tr>
|
32
|
+
<th scope=row><%= t('TTL') %></td>
|
33
|
+
<td><%= @lock.info["ttl"] %></td>
|
34
|
+
</tr>
|
35
|
+
<tr>
|
36
|
+
<th scope=row><%= t('Timeout') %></td>
|
37
|
+
<td><%= @lock.info["timeout"] %></td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<th scope=row><%= t('Args') %></td>
|
41
|
+
<td>
|
42
|
+
<code class="code-wrap">
|
43
|
+
<!-- We don't want to truncate any job arguments when viewing a single job's status page -->
|
44
|
+
<div class="args-extended"><%= display_lock_args(@lock.info["lock_args"], nil) %></div>
|
45
|
+
</code>
|
46
|
+
</td>
|
47
|
+
</tr>
|
48
|
+
</tbody>
|
49
|
+
</table>
|
50
|
+
<% end %>
|
51
|
+
</div>
|
52
|
+
</header>
|
53
|
+
<div class="row">
|
54
|
+
<div class="col-sm-6 table-responsive">
|
55
|
+
<table class="table table-striped table-bordered table-hover">
|
56
|
+
<caption>Digest: <strong class="text-muted"><%= @lock.key %></strong></caption>
|
57
|
+
<thead>
|
58
|
+
<tr>
|
59
|
+
<th scope="col"><%= t('Locked JIDs') %></th>
|
60
|
+
<th scope="col"><%= t('Since') %></th>
|
61
|
+
<th scope="col"></th>
|
62
|
+
</tr>
|
63
|
+
</thead>
|
64
|
+
<tbody>
|
65
|
+
<% @lock.locked_jids(with_values: true).each do |job_id, time| %>
|
66
|
+
<tr>
|
67
|
+
<td><%= job_id %></td>
|
68
|
+
<td><%= safe_relative_time(time.to_f) %></td>
|
69
|
+
<td>
|
70
|
+
<form action="<%= root_path %>locks/<%= @lock.key %>/jobs/<%= job_id %>/delete" method="get">
|
71
|
+
<%= csrf_tag %>
|
72
|
+
<input class="btn btn-danger btn-xs flip" type="submit" name="delete" value="<%= t('Unlock') %>" data-confirm="<%= t('AreYouSure') %>" />
|
73
|
+
</form>
|
74
|
+
</td>
|
75
|
+
</tr>
|
76
|
+
<% end %>
|
77
|
+
</tbody>
|
78
|
+
</table>
|
79
|
+
</div>
|
80
|
+
<div class="col-sm-6 table-responsive">
|
81
|
+
<% if @lock.changelog.count.positive? %>
|
82
|
+
<table class="table table-striped table-bordered table-hover">
|
83
|
+
<caption>Changelogs</caption>
|
84
|
+
<thead>
|
85
|
+
<tr>
|
86
|
+
<th scope="col"><%= t('At') %></th>
|
87
|
+
<th scope="col"><%= t('JID') %></th>
|
88
|
+
<th scope="col"><%= t('Message') %></th>
|
89
|
+
<th scope="col"><%= t('Script') %></th>
|
90
|
+
</tr>
|
91
|
+
</thead>
|
92
|
+
<tbody>
|
93
|
+
<% @lock.changelogs.each do |entry| %>
|
94
|
+
<tr>
|
95
|
+
<td scope="row"><%= safe_relative_time(entry["time"].to_f) %></td>
|
96
|
+
<td><%= entry["job_id"] %></td>
|
97
|
+
<td><%= entry["message"] %></td>
|
98
|
+
<td><%= entry["script"] %></td>
|
99
|
+
</tr>
|
100
|
+
<% end %>
|
101
|
+
</tbody>
|
102
|
+
</table>
|
103
|
+
<% end %>
|
104
|
+
</div>
|
105
|
+
</div>
|
106
|
+
<form action="<%= root_path %>locks/<%= @lock.key %>/delete" method="get">
|
107
|
+
<%= csrf_tag %>
|
108
|
+
<a class="btn btn-default btn-xs" href="<%= root_path %>locks"><%= t('GoBack') %></a>
|
109
|
+
<input class="btn btn-danger btn-xs flip" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
|
110
|
+
</form>
|