sidekiq-unique-jobs 6.0.23 → 7.1.12
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/CHANGELOG.md +922 -41
- data/README.md +821 -284
- data/lib/sidekiq_unique_jobs/batch_delete.rb +123 -0
- data/lib/sidekiq_unique_jobs/changelog.rb +78 -0
- data/lib/sidekiq_unique_jobs/cli.rb +34 -31
- data/lib/sidekiq_unique_jobs/config.rb +314 -0
- data/lib/sidekiq_unique_jobs/connection.rb +6 -5
- data/lib/sidekiq_unique_jobs/constants.rb +45 -24
- 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 -102
- data/lib/sidekiq_unique_jobs/exceptions.rb +88 -12
- data/lib/sidekiq_unique_jobs/job.rb +41 -12
- data/lib/sidekiq_unique_jobs/json.rb +47 -0
- data/lib/sidekiq_unique_jobs/key.rb +93 -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 +40 -15
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +25 -7
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +22 -2
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +26 -16
- data/lib/sidekiq_unique_jobs/lock/validator.rb +96 -0
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +23 -12
- data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +3 -3
- data/lib/sidekiq_unique_jobs/lock.rb +325 -0
- data/lib/sidekiq_unique_jobs/lock_args.rb +123 -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/locksmith.rb +275 -102
- data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +44 -0
- data/lib/sidekiq_unique_jobs/logging.rb +188 -33
- 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 +93 -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 +94 -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 +102 -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 +40 -0
- data/lib/sidekiq_unique_jobs/middleware/server.rb +29 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +29 -31
- 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 +1 -1
- data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +61 -15
- 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 +25 -6
- data/lib/sidekiq_unique_jobs/on_conflict.rb +23 -10
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +35 -32
- data/lib/sidekiq_unique_jobs/orphans/lua_reaper.rb +29 -0
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +248 -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 +231 -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 +49 -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 +114 -65
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +241 -35
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +18 -16
- data/lib/sidekiq_unique_jobs/testing.rb +62 -21
- data/lib/sidekiq_unique_jobs/timer_task.rb +78 -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 +23 -4
- data/lib/sidekiq_unique_jobs/web/helpers.rb +128 -13
- 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 +108 -0
- data/lib/sidekiq_unique_jobs/web/views/locks.erb +54 -0
- data/lib/sidekiq_unique_jobs/web.rb +57 -27
- data/lib/sidekiq_unique_jobs.rb +52 -7
- data/lib/tasks/changelog.rake +15 -15
- metadata +124 -184
- data/lib/sidekiq_unique_jobs/client/middleware.rb +0 -56
- data/lib/sidekiq_unique_jobs/scripts.rb +0 -118
- data/lib/sidekiq_unique_jobs/server/middleware.rb +0 -46
- 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 -150
- 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 -46
- data/redis/acquire_lock.lua +0 -21
- data/redis/convert_legacy_lock.lua +0 -13
- data/redis/delete.lua +0 -14
- data/redis/delete_by_digest.lua +0 -23
- data/redis/delete_job_by_digest.lua +0 -60
- data/redis/lock.lua +0 -62
- data/redis/release_stale_locks.lua +0 -90
- data/redis/unlock.lua +0 -35
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SidekiqUniqueJobs
|
4
|
+
#
|
5
|
+
# Class UpdateVersion sets the right version in redis
|
6
|
+
#
|
7
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
|
+
#
|
9
|
+
class UpdateVersion
|
10
|
+
#
|
11
|
+
# Sets the right versions in redis
|
12
|
+
#
|
13
|
+
# @note the version isn't used yet but will be for automatic upgrades
|
14
|
+
#
|
15
|
+
# @return [true] when version changed
|
16
|
+
#
|
17
|
+
def self.call
|
18
|
+
Script::Caller.call_script(
|
19
|
+
:update_version,
|
20
|
+
keys: [LIVE_VERSION, DEAD_VERSION],
|
21
|
+
argv: [SidekiqUniqueJobs.version],
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -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
|
91
|
+
conn.hmset(locked_key, *locks.to_a)
|
92
|
+
conn.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
|
118
|
+
if VersionCheck.satisfied?(redis_version, ">= 4.0.0")
|
119
|
+
conn.unlink(*keys)
|
120
|
+
else
|
121
|
+
conn.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
|
@@ -4,13 +4,13 @@ module SidekiqUniqueJobs
|
|
4
4
|
#
|
5
5
|
# Handles checking if a version is compliant with given constraint
|
6
6
|
#
|
7
|
-
# @author Mikael Henriksson <mikael@
|
7
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
8
|
#
|
9
9
|
class VersionCheck
|
10
|
-
PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength
|
10
|
+
PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength, Lint/MixedRegexpCaptureTypes
|
11
11
|
|
12
12
|
#
|
13
|
-
# Checks if a version is
|
13
|
+
# Checks if a version is constraint is satisfied
|
14
14
|
#
|
15
15
|
# @example A satisfied constraint
|
16
16
|
# VersionCheck.satisfied?("5.0.0", ">= 4.0.0") #=> true
|
@@ -22,12 +22,31 @@ module SidekiqUniqueJobs
|
|
22
22
|
# @param [String] version a version string `5.0.0`
|
23
23
|
# @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
|
24
24
|
#
|
25
|
-
# @return [
|
25
|
+
# @return [true, false] <description>
|
26
26
|
#
|
27
27
|
def self.satisfied?(version, constraint)
|
28
28
|
new(version, constraint).satisfied?
|
29
29
|
end
|
30
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
|
+
|
31
50
|
#
|
32
51
|
# @!attribute [r] version
|
33
52
|
# @return [String] a version string `5.0.0`
|
@@ -2,28 +2,110 @@
|
|
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.open(
|
30
|
+
File.open(unique_filename(name)).read
|
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 changelog entries
|
56
|
+
#
|
57
|
+
#
|
58
|
+
# @return [SidekiqUniqueJobs::Digests] the sorted set with digests
|
59
|
+
#
|
60
|
+
def changelog
|
61
|
+
@changelog ||= SidekiqUniqueJobs::Changelog.new
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Creates url safe parameters
|
66
|
+
#
|
67
|
+
# @param [Hash] options the key/value to parameterize
|
68
|
+
#
|
69
|
+
# @return [String] a url safe parameter string
|
70
|
+
#
|
71
|
+
def cparams(options)
|
72
|
+
stringified_options = options.transform_keys(&:to_s)
|
73
|
+
params.merge(stringified_options).map do |key, value|
|
21
74
|
next unless SAFE_CPARAMS.include?(key)
|
22
75
|
|
23
76
|
"#{key}=#{CGI.escape(value.to_s)}"
|
24
77
|
end.compact.join("&")
|
25
78
|
end
|
26
79
|
|
80
|
+
#
|
81
|
+
# Used to avoid incompatibility with older sidekiq versions
|
82
|
+
#
|
83
|
+
#
|
84
|
+
# @param [Array] args the unique arguments to display
|
85
|
+
# @param [Integer] truncate_after_chars
|
86
|
+
#
|
87
|
+
# @return [String] a string containing all non-truncated arguments
|
88
|
+
#
|
89
|
+
def display_lock_args(args, truncate_after_chars = 2000)
|
90
|
+
return "Invalid job payload, args is nil" if args.nil?
|
91
|
+
return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array)
|
92
|
+
|
93
|
+
begin
|
94
|
+
args.map do |arg|
|
95
|
+
h(truncate(to_display(arg), truncate_after_chars))
|
96
|
+
end.join(", ")
|
97
|
+
rescue StandardError
|
98
|
+
"Illegal job arguments: #{h args.inspect}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Redirect to with falback
|
104
|
+
#
|
105
|
+
# @param [String] subpath the path to redirect to
|
106
|
+
#
|
107
|
+
# @return a redirect to the new subpath
|
108
|
+
#
|
27
109
|
def redirect_to(subpath)
|
28
110
|
if respond_to?(:to)
|
29
111
|
# Sinatra-based web UI
|
@@ -34,14 +116,47 @@ module SidekiqUniqueJobs
|
|
34
116
|
end
|
35
117
|
end
|
36
118
|
|
119
|
+
#
|
120
|
+
# Gets a relative time as html
|
121
|
+
#
|
122
|
+
# @param [Time] time an instance of Time
|
123
|
+
#
|
124
|
+
# @return [String] a html safe string with relative time information
|
125
|
+
#
|
126
|
+
def relative_time(time)
|
127
|
+
stamp = time.getutc.iso8601
|
128
|
+
%(<time class="ltr" dir="ltr" title="#{stamp}" datetime="#{stamp}">#{time}</time>)
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Gets a relative time as html without crashing
|
133
|
+
#
|
134
|
+
# @param [Float, Integer, String, Time] time a representation of a timestamp
|
135
|
+
#
|
136
|
+
# @return [String] a html safe string with relative time information
|
137
|
+
#
|
37
138
|
def safe_relative_time(time)
|
38
|
-
time =
|
139
|
+
time = parse_time(time)
|
140
|
+
|
141
|
+
relative_time(time)
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Constructs a time from a number of different types
|
146
|
+
#
|
147
|
+
# @param [Float, Integer, String, Time] time a representation of a timestamp
|
148
|
+
#
|
149
|
+
# @return [Time]
|
150
|
+
#
|
151
|
+
def parse_time(time)
|
152
|
+
case time
|
153
|
+
when Time
|
154
|
+
time
|
155
|
+
when Integer, Float
|
39
156
|
Time.at(time)
|
40
157
|
else
|
41
|
-
Time.parse(time)
|
158
|
+
Time.parse(time.to_s)
|
42
159
|
end
|
43
|
-
|
44
|
-
relative_time(time)
|
45
160
|
end
|
46
161
|
end
|
47
162
|
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,108 @@
|
|
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
|
+
<p>To use it turn the following setting on:
|
11
|
+
<code>SidekiqUniqueJobs.config.lock_info = true</code>
|
12
|
+
</p>
|
13
|
+
<% else %>
|
14
|
+
<table class="table table-striped table-bordered table-white table-hover">
|
15
|
+
<caption>Information about lock</caption>
|
16
|
+
<tbody>
|
17
|
+
<tr>
|
18
|
+
<th scope=row><%= t('Worker') %></td>
|
19
|
+
<td><%= @lock.info["worker"] %></td>
|
20
|
+
</tr>
|
21
|
+
<tr>
|
22
|
+
<th scope=row><%= t('Queue') %></td>
|
23
|
+
<td><%= @lock.info["queue"] %></td>
|
24
|
+
</tr>
|
25
|
+
<tr>
|
26
|
+
<th scope=row><%= t('Limit') %></td>
|
27
|
+
<td><%= @lock.info["limit"] %></td>
|
28
|
+
</tr>
|
29
|
+
<tr>
|
30
|
+
<th scope=row><%= t('TTL') %></td>
|
31
|
+
<td><%= @lock.info["ttl"] %></td>
|
32
|
+
</tr>
|
33
|
+
<tr>
|
34
|
+
<th scope=row><%= t('Timeout') %></td>
|
35
|
+
<td><%= @lock.info["timeout"] %></td>
|
36
|
+
</tr>
|
37
|
+
<tr>
|
38
|
+
<th scope=row><%= t('Args') %></td>
|
39
|
+
<td>
|
40
|
+
<code class="code-wrap">
|
41
|
+
<!-- We don't want to truncate any job arguments when viewing a single job's status page -->
|
42
|
+
<div class="args-extended"><%= display_lock_args(@lock.info["lock_args"], nil) %></div>
|
43
|
+
</code>
|
44
|
+
</td>
|
45
|
+
</tr>
|
46
|
+
</tbody>
|
47
|
+
</table>
|
48
|
+
<% end %>
|
49
|
+
</div>
|
50
|
+
</header>
|
51
|
+
<div class="row">
|
52
|
+
<div class="col-sm-6 table-responsive">
|
53
|
+
<table class="table table-striped table-bordered table-hover">
|
54
|
+
<caption>Digest: <strong class="text-muted"><%= @lock.key %></strong></caption>
|
55
|
+
<thead>
|
56
|
+
<tr>
|
57
|
+
<th scope="col"><%= t('Locked JIDs') %></th>
|
58
|
+
<th scope="col"><%= t('Since') %></th>
|
59
|
+
<th scope="col"></th>
|
60
|
+
</tr>
|
61
|
+
</thead>
|
62
|
+
<tbody>
|
63
|
+
<% @lock.locked_jids(with_values: true).each do |job_id, time| %>
|
64
|
+
<tr>
|
65
|
+
<td><%= job_id %></td>
|
66
|
+
<td><%= safe_relative_time(time.to_f) %></td>
|
67
|
+
<td>
|
68
|
+
<form action="<%= root_path %>locks/<%= @lock.key %>/jobs/<%= job_id %>/delete" method="get">
|
69
|
+
<%= csrf_tag %>
|
70
|
+
<input class="btn btn-danger btn-xs flip" type="submit" name="delete" value="<%= t('Unlock') %>" data-confirm="<%= t('AreYouSure') %>" />
|
71
|
+
</form>
|
72
|
+
</td>
|
73
|
+
</tr>
|
74
|
+
<% end %>
|
75
|
+
</tbody>
|
76
|
+
</table>
|
77
|
+
</div>
|
78
|
+
<div class="col-sm-6 table-responsive">
|
79
|
+
<% if @lock.changelog.count.positive? %>
|
80
|
+
<table class="table table-striped table-bordered table-hover">
|
81
|
+
<caption>Changelogs</caption>
|
82
|
+
<thead>
|
83
|
+
<tr>
|
84
|
+
<th scope="col"><%= t('At') %></th>
|
85
|
+
<th scope="col"><%= t('JID') %></th>
|
86
|
+
<th scope="col"><%= t('Message') %></th>
|
87
|
+
<th scope="col"><%= t('Script') %></th>
|
88
|
+
</tr>
|
89
|
+
</thead>
|
90
|
+
<tbody>
|
91
|
+
<% @lock.changelogs.each do |entry| %>
|
92
|
+
<tr>
|
93
|
+
<td scope="row"><%= safe_relative_time(entry["time"].to_f) %></td>
|
94
|
+
<td><%= entry["job_id"] %></td>
|
95
|
+
<td><%= entry["message"] %></td>
|
96
|
+
<td><%= entry["script"] %></td>
|
97
|
+
</tr>
|
98
|
+
<% end %>
|
99
|
+
</tbody>
|
100
|
+
</table>
|
101
|
+
<% end %>
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
<form action="<%= root_path %>locks/<%= @lock.key %>/delete" method="get">
|
105
|
+
<%= csrf_tag %>
|
106
|
+
<a class="btn btn-default btn-xs" href="<%= root_path %>locks"><%= t('GoBack') %></a>
|
107
|
+
<input class="btn btn-danger btn-xs flip" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
|
108
|
+
</form>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
<header class="row">
|
2
|
+
<div class="col-sm-5">
|
3
|
+
<h3>
|
4
|
+
<%= t('Locks') %>
|
5
|
+
</h3>
|
6
|
+
</div>
|
7
|
+
<form action="<%= root_path %>locks" 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 @locks.any? && @total_size > @count %>
|
15
|
+
<div class="col-sm-4">
|
16
|
+
<%= erb unique_template(:_paging), locals: { url: "#{root_path}locks" } %>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
</header>
|
20
|
+
<% if @locks.any? %>
|
21
|
+
<div class="table_container">
|
22
|
+
<table class="table table-striped table-bordered table-hover">
|
23
|
+
<thead>
|
24
|
+
<tr>
|
25
|
+
<th><%= t('Delete') %></th>
|
26
|
+
<th><%= t('Digest') %></th>
|
27
|
+
<th><%= t('Lock') %></th>
|
28
|
+
<th><%= t('Locks') %></th>
|
29
|
+
<th><%= t('Since') %></th>
|
30
|
+
</tr>
|
31
|
+
</thead>
|
32
|
+
<% @locks.each do |lock| %>
|
33
|
+
<tbody>
|
34
|
+
<tr class="lock-row">
|
35
|
+
<td>
|
36
|
+
<form action="<%= root_path %>locks/<%= lock.key %>/delete" method="get">
|
37
|
+
<%= csrf_tag %>
|
38
|
+
<input name="lock" value="<%= h lock.key %>" type="hidden" />
|
39
|
+
<input class="btn btn-danger btn-xs" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
|
40
|
+
</form>
|
41
|
+
</td>
|
42
|
+
<td><a href="<%= root_path %>locks/<%= lock.key %>"><%= lock.key %></a></td>
|
43
|
+
<td><%= lock.info["lock"] %></td>
|
44
|
+
<td><%= lock.locked.count %></td>
|
45
|
+
<td><%= safe_relative_time(lock.created_at) %></td>
|
46
|
+
</tr>
|
47
|
+
</tbody>
|
48
|
+
<% end %>
|
49
|
+
</table>
|
50
|
+
<form action="<%= root_path %>locks/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 %>
|