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
@@ -1,28 +0,0 @@
|
|
1
|
-
<header class="row">
|
2
|
-
<div class="col-sm-5">
|
3
|
-
<h3><%= t('Unique Digest') %> - <a class="btn btn-default btn-xs" href="<%= root_path %>unique_digests"><%= t('GoBack') %></a></h3>
|
4
|
-
</div>
|
5
|
-
</header>
|
6
|
-
|
7
|
-
<% if @unique_keys.size.positive? %>
|
8
|
-
<div class="table_container">
|
9
|
-
<table class="table table-striped table-bordered table-hover">
|
10
|
-
<thead>
|
11
|
-
<tr>
|
12
|
-
<th>
|
13
|
-
<%= t('Keys') %>
|
14
|
-
<span class="small text-muted">for (<%= @digest %>)</span>
|
15
|
-
</th>
|
16
|
-
</tr>
|
17
|
-
</thead>
|
18
|
-
<% @unique_keys.each do |key| %>
|
19
|
-
<tr><td colspan="2"><%= key %></td></tr>
|
20
|
-
<% end %>
|
21
|
-
</table>
|
22
|
-
</div>
|
23
|
-
<form action="<%= root_path %>unique_digests/<%= @digest %>/delete" method="get">
|
24
|
-
<%= csrf_tag %>
|
25
|
-
<a class="btn btn-default btn-xs" href="<%= root_path %>unique_digests"><%= t('GoBack') %></a>
|
26
|
-
<input class="btn btn-danger btn-xs flip" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
|
27
|
-
</form>
|
28
|
-
<% end %>
|
@@ -1,42 +0,0 @@
|
|
1
|
-
<header class="row">
|
2
|
-
<div class="col-sm-5">
|
3
|
-
<h3><%= t('Unique Digests') %></h3>
|
4
|
-
</div>
|
5
|
-
<form action="<%= root_path %>unique_digests" class="form form-inline" method="get">
|
6
|
-
<%= csrf_tag %>
|
7
|
-
<input name="filter" class="form-control" type="text" value="<%= @filter %>" />
|
8
|
-
<button class="btn btn-default" type="submit"><%= t('Filter') %></button>
|
9
|
-
</form>
|
10
|
-
<% if @unique_digests.size > 0 && @total_size > @count.to_i %>
|
11
|
-
<div class="col-sm-4">
|
12
|
-
<%= erb unique_template(:_paging), locals: { url: "#{root_path}unique_digests" } %>
|
13
|
-
</div>
|
14
|
-
<% end %>
|
15
|
-
</header>
|
16
|
-
|
17
|
-
<% if @unique_digests.size.positive? %>
|
18
|
-
<div class="table_container">
|
19
|
-
<table class="table table-striped table-bordered table-hover">
|
20
|
-
<thead>
|
21
|
-
<tr>
|
22
|
-
<th><%= t('Delete') %></th>
|
23
|
-
<th><%= t('Digest') %></th>
|
24
|
-
</tr>
|
25
|
-
</thead>
|
26
|
-
<% @unique_digests.each do |digest| %>
|
27
|
-
<tr>
|
28
|
-
<td>
|
29
|
-
<form action="<%= root_path %>unique_digests/<%= digest %>/delete" method="get">
|
30
|
-
<%= csrf_tag %>
|
31
|
-
<input name="digest" value="<%= h digest %>" type="hidden" />
|
32
|
-
<input class="btn btn-danger btn-xs" type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSure') %>" />
|
33
|
-
</form>
|
34
|
-
</td>
|
35
|
-
<td>
|
36
|
-
<a href="<%= root_path %>unique_digests/<%= digest %>"><%= digest %></a>
|
37
|
-
</td>
|
38
|
-
</tr>
|
39
|
-
<% end %>
|
40
|
-
</table>
|
41
|
-
</div>
|
42
|
-
<% end %>
|
data/redis/acquire_lock.lua
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
local unique_key = KEYS[1]
|
2
|
-
local job_id = ARGV[1]
|
3
|
-
local expires = tonumber(ARGV[2])
|
4
|
-
local stored_jid = redis.pcall('get', unique_key)
|
5
|
-
|
6
|
-
if stored_jid then
|
7
|
-
if stored_jid == job_id then
|
8
|
-
return 1
|
9
|
-
else
|
10
|
-
return 0
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
if redis.call('SET', unique_key, job_id, 'nx') then
|
15
|
-
if expires then
|
16
|
-
redis.call('EXPIRE', unique_key, expires)
|
17
|
-
end
|
18
|
-
return 1
|
19
|
-
else
|
20
|
-
return 0
|
21
|
-
end
|
data/redis/delete.lua
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
local exists_key = KEYS[1]
|
2
|
-
local grabbed_key = KEYS[2]
|
3
|
-
local available_key = KEYS[3]
|
4
|
-
local version_key = KEYS[4]
|
5
|
-
local unique_keys = KEYS[5]
|
6
|
-
local unique_digest = KEYS[6] -- TODO: Legacy support (Remove in v6.1)
|
7
|
-
|
8
|
-
redis.call('DEL', exists_key)
|
9
|
-
redis.call('SREM', unique_keys, unique_digest)
|
10
|
-
redis.call('DEL', grabbed_key)
|
11
|
-
redis.call('DEL', available_key)
|
12
|
-
redis.call('DEL', version_key)
|
13
|
-
redis.call('DEL', 'uniquejobs') -- TODO: Old job hash, just drop the darn thing
|
14
|
-
redis.call('DEL', unique_digest) -- TODO: Legacy support (Remove in v6.1)
|
data/redis/delete_by_digest.lua
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
-- redis.replicate_commands();
|
2
|
-
local unique_keys = KEYS[1]
|
3
|
-
local unique_digest = KEYS[2]
|
4
|
-
|
5
|
-
local exists_key = unique_digest .. ':EXISTS'
|
6
|
-
local grabbed_key = unique_digest .. ':GRABBED'
|
7
|
-
local available_key = unique_digest .. ':AVAILABLE'
|
8
|
-
local version_key = unique_digest .. ':VERSION'
|
9
|
-
local run_exists_key = unique_digest .. ':RUN:EXISTS'
|
10
|
-
local run_grabbed_key = unique_digest .. ':RUN:GRABBED'
|
11
|
-
local run_available_key = unique_digest .. ':RUN:AVAILABLE'
|
12
|
-
local run_version_key = unique_digest .. ':RUN:VERSION'
|
13
|
-
|
14
|
-
local count = redis.call('SREM', unique_keys, unique_digest)
|
15
|
-
redis.call('DEL', exists_key)
|
16
|
-
redis.call('DEL', grabbed_key)
|
17
|
-
redis.call('DEL', available_key)
|
18
|
-
redis.call('DEL', version_key)
|
19
|
-
redis.call('DEL', run_exists_key)
|
20
|
-
redis.call('DEL', run_grabbed_key)
|
21
|
-
redis.call('DEL', run_available_key)
|
22
|
-
redis.call('DEL', run_version_key)
|
23
|
-
|
24
|
-
return count
|
@@ -1,60 +0,0 @@
|
|
1
|
-
local queue = KEYS[1]
|
2
|
-
local schedule_set = KEYS[2]
|
3
|
-
local retry_set = KEYS[3]
|
4
|
-
local unique_digest = ARGV[1]
|
5
|
-
|
6
|
-
local function delete_from_sorted_set(name, digest)
|
7
|
-
local per = 50
|
8
|
-
local total = redis.call('zcard', name)
|
9
|
-
local index = 0
|
10
|
-
local result
|
11
|
-
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..")")
|
12
|
-
while (index < total) do
|
13
|
-
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - "..index.."-"..per)
|
14
|
-
local items = redis.call('ZRANGE', name, index, index + per -1)
|
15
|
-
for _, item in pairs(items) do
|
16
|
-
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - current item: " .. item)
|
17
|
-
if string.find(item, digest) then
|
18
|
-
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - deleting item")
|
19
|
-
redis.call('ZREM', name, item)
|
20
|
-
result = item
|
21
|
-
break
|
22
|
-
end
|
23
|
-
end
|
24
|
-
index = index + per
|
25
|
-
end
|
26
|
-
return result
|
27
|
-
end
|
28
|
-
|
29
|
-
local per = 50
|
30
|
-
local total = redis.call('LLEN', queue)
|
31
|
-
local index = 0
|
32
|
-
local result = nil
|
33
|
-
|
34
|
-
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - looping through: " .. queue)
|
35
|
-
while (index < total) do
|
36
|
-
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - " .. index .. "-" .. per)
|
37
|
-
local items = redis.call('LRANGE', queue, index, index + per -1)
|
38
|
-
for _, item in pairs(items) do
|
39
|
-
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - item: " .. item)
|
40
|
-
if string.find(item, unique_digest) then
|
41
|
-
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - found item with digest: " .. unique_digest .. " in: " ..queue)
|
42
|
-
redis.call('LREM', queue, 1, item)
|
43
|
-
result = item
|
44
|
-
break
|
45
|
-
end
|
46
|
-
end
|
47
|
-
index = index + per
|
48
|
-
end
|
49
|
-
|
50
|
-
if result then
|
51
|
-
return result
|
52
|
-
end
|
53
|
-
|
54
|
-
result = delete_from_sorted_set(schedule_set, unique_digest)
|
55
|
-
if result then
|
56
|
-
return result
|
57
|
-
end
|
58
|
-
|
59
|
-
result = delete_from_sorted_set(retry_set, unique_digest)
|
60
|
-
return result
|
data/redis/lock.lua
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
-- redis.replicate_commands();
|
2
|
-
|
3
|
-
local exists_key = KEYS[1]
|
4
|
-
local grabbed_key = KEYS[2]
|
5
|
-
local available_key = KEYS[3]
|
6
|
-
local unique_keys = KEYS[4]
|
7
|
-
local unique_digest = KEYS[5]
|
8
|
-
|
9
|
-
local job_id = ARGV[1]
|
10
|
-
local expiration = tonumber(ARGV[2])
|
11
|
-
|
12
|
-
local function current_time()
|
13
|
-
local time = redis.call('time')
|
14
|
-
local s = time[1]
|
15
|
-
local ms = time[2]
|
16
|
-
local number = tonumber((s .. '.' .. ms))
|
17
|
-
|
18
|
-
return number
|
19
|
-
end
|
20
|
-
|
21
|
-
-- redis.log(redis.LOG_DEBUG, "create.lua - investigate possibility of locking jid: " .. job_id)
|
22
|
-
|
23
|
-
local stored_token = redis.call('GET', exists_key)
|
24
|
-
if stored_token and stored_token ~= job_id then
|
25
|
-
-- redis.log(redis.LOG_DEBUG, "create.lua - jid: " .. job_id .. " - returning existing jid: " .. stored_token)
|
26
|
-
return stored_token
|
27
|
-
end
|
28
|
-
|
29
|
-
redis.call('SET', exists_key, job_id)
|
30
|
-
|
31
|
-
----------------------------------------------------------------
|
32
|
-
-- TODO: Legacy support (Remove in v6.1)
|
33
|
-
local old_token = redis.call('GET', unique_digest)
|
34
|
-
if old_token then
|
35
|
-
if old_token == job_id or old_token == '2' then
|
36
|
-
-- No need to return, we just delete the old key
|
37
|
-
redis.call('DEL', unique_digest)
|
38
|
-
else
|
39
|
-
return old_token
|
40
|
-
end
|
41
|
-
end
|
42
|
-
----------------------------------------------------------------
|
43
|
-
|
44
|
-
redis.call('SADD', unique_keys, unique_digest)
|
45
|
-
redis.call('DEL', grabbed_key)
|
46
|
-
-- TODO: Move this to LUA when redis 3.2 is the least supported
|
47
|
-
-- redis.call('HSET', grabbed_key, job_id, current_time())
|
48
|
-
---------------------------------------------------------------
|
49
|
-
redis.call('DEL', available_key)
|
50
|
-
redis.call('RPUSH', available_key, job_id)
|
51
|
-
|
52
|
-
if expiration then
|
53
|
-
redis.call('EXPIRE', available_key, expiration)
|
54
|
-
redis.call('EXPIRE', exists_key, expiration)
|
55
|
-
redis.call('EXPIRE', grabbed_key, expiration)
|
56
|
-
end
|
57
|
-
|
58
|
-
return job_id
|
@@ -1,90 +0,0 @@
|
|
1
|
-
redis.replicate_commands();
|
2
|
-
|
3
|
-
local exists_key = KEYS[1]
|
4
|
-
local grabbed_key = KEYS[2]
|
5
|
-
local available_key = KEYS[3]
|
6
|
-
local release_key = KEYS[4]
|
7
|
-
local version_key = KEYS[5]
|
8
|
-
|
9
|
-
local expires_in = tonumber(ARGV[1])
|
10
|
-
local stale_client_timeout = tonumber(ARGV[2])
|
11
|
-
local expiration = tonumber(ARGV[3])
|
12
|
-
|
13
|
-
local function current_time()
|
14
|
-
local time = redis.call('time')
|
15
|
-
local s = time[1]
|
16
|
-
local ms = time[2]
|
17
|
-
local number = tonumber((s .. '.' .. ms))
|
18
|
-
|
19
|
-
return number
|
20
|
-
end
|
21
|
-
|
22
|
-
local hgetall = function (key)
|
23
|
-
local bulk = redis.call('HGETALL', key)
|
24
|
-
local result = {}
|
25
|
-
local nextkey
|
26
|
-
for i, v in ipairs(bulk) do
|
27
|
-
if i % 2 == 1 then
|
28
|
-
nextkey = v
|
29
|
-
else
|
30
|
-
result[nextkey] = v
|
31
|
-
end
|
32
|
-
end
|
33
|
-
return result
|
34
|
-
end
|
35
|
-
|
36
|
-
local cached_current_time = current_time()
|
37
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - started at : " .. cached_current_time)
|
38
|
-
|
39
|
-
local my_lock_expires_at = cached_current_time + expires_in + 1
|
40
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - my_lock_expires_at: " .. my_lock_expires_at)
|
41
|
-
|
42
|
-
if not redis.call('SETNX', release_key, my_lock_expires_at) then
|
43
|
-
-- Check if expired
|
44
|
-
local other_lock_expires_at = tonumber(redis.call('GET', release_key))
|
45
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - other_lock_expires_at: " .. other_lock_expires_at)
|
46
|
-
|
47
|
-
if other_lock_expires_at < cached_current_time then
|
48
|
-
local old_expires_at = tonumber(redis.call('GETSET', release_key, my_lock_expires_at))
|
49
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - old_expires_at: " .. old_expires_at)
|
50
|
-
|
51
|
-
-- Check if another client started cleanup yet. If not,
|
52
|
-
-- then we now have the lock.
|
53
|
-
if not old_expires_at == other_lock_expires_at then
|
54
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua -could not retrieve lock: exiting 0")
|
55
|
-
return 0
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
local keys = hgetall(grabbed_key)
|
61
|
-
for key, locked_at in pairs(keys) do
|
62
|
-
local timed_out_at = tonumber(locked_at) + stale_client_timeout
|
63
|
-
redis.log(redis.LOG_DEBUG,
|
64
|
-
"release_stale_locks.lua - processing: " .. grabbed_key .. " key: " .. key .. " locked_at: " .. locked_at
|
65
|
-
)
|
66
|
-
|
67
|
-
if timed_out_at < current_time() then
|
68
|
-
redis.log(redis.LOG_DEBUG, "HDEL " .. grabbed_key .. ":" .. key)
|
69
|
-
redis.call('HDEL', grabbed_key, key)
|
70
|
-
redis.log(redis.LOG_DEBUG, "LPUSH " .. available_key .. ":" .. key)
|
71
|
-
redis.call('LPUSH', available_key, key)
|
72
|
-
|
73
|
-
if expiration then
|
74
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - EXPIRE " .. available_key .. " with " .. expiration)
|
75
|
-
redis.call('EXPIRE', available_key, expiration)
|
76
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - EXPIRE " .. exists_key .. " with " .. expiration)
|
77
|
-
redis.call('EXPIRE', exists_key, expiration)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
-- Make sure not to delete the lock in case someone else already expired
|
83
|
-
-- our lock, with one second in between to account for some lag.
|
84
|
-
if my_lock_expires_at > (current_time() - 1) then
|
85
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - DEL " .. release_key)
|
86
|
-
redis.call('DEL', release_key)
|
87
|
-
end
|
88
|
-
|
89
|
-
redis.log(redis.LOG_DEBUG, "release_stale_locks.lua - comleted at : " .. current_time())
|
90
|
-
return 1
|
data/redis/unlock.lua
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
local exists_key = KEYS[1]
|
2
|
-
local grabbed_key = KEYS[2]
|
3
|
-
local available_key = KEYS[3]
|
4
|
-
local version_key = KEYS[4]
|
5
|
-
local unique_keys = KEYS[5]
|
6
|
-
local unique_digest = KEYS[6] -- TODO: Legacy support (Remove in v6.1)
|
7
|
-
|
8
|
-
local token = ARGV[1]
|
9
|
-
local expiration = tonumber(ARGV[2])
|
10
|
-
|
11
|
-
redis.call('HDEL', grabbed_key, token)
|
12
|
-
redis.call('SREM', unique_keys, unique_digest)
|
13
|
-
|
14
|
-
if expiration then
|
15
|
-
redis.log(redis.LOG_DEBUG, "signal_locks.lua - expiring stale locks")
|
16
|
-
redis.call('SREM', unique_keys, unique_digest)
|
17
|
-
redis.call('EXPIRE', exists_key, expiration)
|
18
|
-
redis.call('EXPIRE', available_key, expiration)
|
19
|
-
redis.call('EXPIRE', version_key, expiration) -- TODO: Legacy support (Remove in v6.1)
|
20
|
-
redis.call('EXPIRE', unique_digest, expiration) -- TODO: Legacy support (Remove in v6.1)
|
21
|
-
else
|
22
|
-
redis.call('DEL', exists_key)
|
23
|
-
redis.call('SREM', unique_keys, unique_digest)
|
24
|
-
redis.call('DEL', grabbed_key)
|
25
|
-
redis.call('DEL', available_key)
|
26
|
-
redis.call('DEL', version_key) -- TODO: Legacy support (Remove in v6.1)
|
27
|
-
redis.call('DEL', 'uniquejobs') -- TODO: Old job hash, just drop the darn thing (Remove in v6.1)
|
28
|
-
redis.call('DEL', unique_digest) -- TODO: Legacy support (Remove in v6.1)
|
29
|
-
end
|
30
|
-
|
31
|
-
return redis.call('LPUSH', available_key, token)
|
32
|
-
|
data/sidekiq-unique-jobs.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path("../lib", __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
require 'sidekiq_unique_jobs/version'
|
7
|
-
|
8
|
-
Gem::Specification.new do |spec|
|
9
|
-
spec.name = 'sidekiq-unique-jobs'
|
10
|
-
spec.version = SidekiqUniqueJobs::VERSION
|
11
|
-
spec.authors = ['Mikael Henriksson']
|
12
|
-
spec.email = ['mikael@zoolutions.se']
|
13
|
-
|
14
|
-
spec.summary = 'Uniqueness for Sidekiq Jobs'
|
15
|
-
spec.description = 'Handles various types of unique jobs for Sidekiq'
|
16
|
-
spec.homepage = 'https://github.com/mhenrixon/sidekiq-unique-jobs'
|
17
|
-
spec.license = 'MIT'
|
18
|
-
|
19
|
-
spec.bindir = 'bin'
|
20
|
-
spec.executables = %w[uniquejobs]
|
21
|
-
|
22
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
-
`git ls-files -z`.split("\x0").reject do |file|
|
24
|
-
file.match(%r{^(test|spec|features|gemfiles|pkg|rails_example|tmp)/})
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
spec.require_paths = ['lib']
|
29
|
-
spec.add_dependency 'concurrent-ruby', '~> 1.0', '>= 1.0.5'
|
30
|
-
spec.add_dependency 'sidekiq', '>= 4.0', '< 6.0'
|
31
|
-
spec.add_dependency 'thor', '~> 0'
|
32
|
-
|
33
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
-
spec.add_development_dependency 'rspec', '~> 3.7'
|
35
|
-
spec.add_development_dependency 'rake', '~> 12.3'
|
36
|
-
spec.add_development_dependency 'timecop', '~> 0.9'
|
37
|
-
spec.add_development_dependency 'yard', '~> 0.9'
|
38
|
-
spec.add_development_dependency 'gem-release', '~> 1.0'
|
39
|
-
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
40
|
-
spec.add_development_dependency 'rack-test'
|
41
|
-
spec.add_development_dependency 'sinatra'
|
42
|
-
end
|