sidekiq-unique-jobs 4.0.8 → 4.0.9
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/.fasterer.yml +23 -0
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +12 -1
- data/Gemfile +4 -3
- data/README.md +22 -5
- data/bin/jobs +6 -0
- data/gemfiles/sidekiq_2.15.gemfile +5 -5
- data/gemfiles/sidekiq_2.16.gemfile +5 -5
- data/gemfiles/sidekiq_2.17.gemfile +3 -2
- data/gemfiles/sidekiq_3.0.gemfile +3 -2
- data/gemfiles/sidekiq_3.1.gemfile +3 -2
- data/gemfiles/sidekiq_3.2.gemfile +3 -2
- data/gemfiles/sidekiq_3.3.gemfile +3 -2
- data/gemfiles/sidekiq_develop.gemfile +3 -2
- data/lib/sidekiq-unique-jobs.rb +13 -8
- data/lib/sidekiq/simulator.rb +75 -0
- data/lib/sidekiq_unique_jobs/cli.rb +34 -0
- data/lib/sidekiq_unique_jobs/lock/until_timeout.rb +5 -2
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +2 -3
- data/lib/sidekiq_unique_jobs/middleware.rb +5 -0
- data/lib/sidekiq_unique_jobs/scripts.rb +3 -7
- data/lib/sidekiq_unique_jobs/util.rb +77 -0
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/rails_example/.gitignore +13 -0
- data/rails_example/Gemfile +20 -0
- data/rails_example/Procfile +2 -0
- data/rails_example/README.rdoc +28 -0
- data/rails_example/Rakefile +6 -0
- data/rails_example/app/assets/images/.keep +0 -0
- data/rails_example/app/assets/javascripts/application.js +16 -0
- data/rails_example/app/assets/stylesheets/application.css +15 -0
- data/rails_example/app/controllers/application_controller.rb +5 -0
- data/rails_example/app/controllers/concerns/.keep +0 -0
- data/rails_example/app/controllers/work_controller.rb +10 -0
- data/rails_example/app/helpers/application_helper.rb +2 -0
- data/rails_example/app/mailers/.keep +0 -0
- data/rails_example/app/models/.keep +0 -0
- data/rails_example/app/models/concerns/.keep +0 -0
- data/rails_example/app/models/post.rb +2 -0
- data/rails_example/app/views/layouts/application.html.erb +15 -0
- data/rails_example/app/workers/simple_worker.rb +11 -0
- data/rails_example/app/workers/spawn_simple_worker.rb +7 -0
- data/rails_example/bin/bundle +3 -0
- data/rails_example/bin/rails +4 -0
- data/rails_example/bin/rake +4 -0
- data/rails_example/bin/setup +29 -0
- data/rails_example/config.ru +4 -0
- data/rails_example/config/application.rb +26 -0
- data/rails_example/config/boot.rb +3 -0
- data/rails_example/config/database.yml +26 -0
- data/rails_example/config/environment.rb +5 -0
- data/rails_example/config/environments/development.rb +41 -0
- data/rails_example/config/environments/production.rb +79 -0
- data/rails_example/config/environments/test.rb +42 -0
- data/rails_example/config/initializers/assets.rb +11 -0
- data/rails_example/config/initializers/backtrace_silencers.rb +8 -0
- data/rails_example/config/initializers/cookies_serializer.rb +3 -0
- data/rails_example/config/initializers/filter_parameter_logging.rb +4 -0
- data/rails_example/config/initializers/inflections.rb +16 -0
- data/rails_example/config/initializers/mime_types.rb +4 -0
- data/rails_example/config/initializers/session_store.rb +3 -0
- data/rails_example/config/initializers/sidekiq.rb +13 -0
- data/rails_example/config/initializers/wrap_parameters.rb +14 -0
- data/rails_example/config/locales/en.yml +23 -0
- data/rails_example/config/routes.rb +5 -0
- data/rails_example/config/secrets.yml +22 -0
- data/rails_example/config/sidekiq.yml +6 -0
- data/rails_example/db/development.sqlite3 +0 -0
- data/rails_example/db/migrate/20151107231835_create_posts.rb +10 -0
- data/rails_example/db/schema.rb +21 -0
- data/rails_example/db/seeds.rb +7 -0
- data/rails_example/db/test.sqlite3 +0 -0
- data/rails_example/lib/assets/.keep +0 -0
- data/rails_example/lib/tasks/.keep +0 -0
- data/rails_example/log/.keep +0 -0
- data/rails_example/public/404.html +67 -0
- data/rails_example/public/422.html +67 -0
- data/rails_example/public/500.html +66 -0
- data/rails_example/public/favicon.ico +0 -0
- data/rails_example/public/robots.txt +5 -0
- data/rails_example/simple.ru +12 -0
- data/rails_example/vendor/assets/javascripts/.keep +0 -0
- data/rails_example/vendor/assets/stylesheets/.keep +0 -0
- data/sidekiq-unique-jobs.gemspec +4 -2
- data/spec/celluloid_with_fallback.rb +9 -8
- data/spec/jobs/simple_worker.rb +11 -0
- data/spec/jobs/spawn_simple_worker.rb +8 -0
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +53 -1
- data/spec/lib/sidekiq_unique_jobs/lock/until_timeout_spec.rb +26 -0
- data/spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb +58 -3
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_jobs_spec.rb +6 -1
- data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +2 -3
- data/spec/lib/sidekiq_unique_jobs/util_spec.rb +53 -0
- data/spec/spec_helper.rb +1 -0
- metadata +105 -6
@@ -1,8 +1,8 @@
|
|
1
1
|
module SidekiqUniqueJobs
|
2
2
|
module Lock
|
3
3
|
class WhileExecuting
|
4
|
-
def self.synchronize(item, redis_pool = nil
|
5
|
-
new(item, redis_pool).synchronize
|
4
|
+
def self.synchronize(item, redis_pool = nil)
|
5
|
+
new(item, redis_pool).synchronize { yield }
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize(item, redis_pool = nil)
|
@@ -10,7 +10,6 @@ module SidekiqUniqueJobs
|
|
10
10
|
@mutex = Mutex.new
|
11
11
|
@redis_pool = redis_pool
|
12
12
|
@unique_digest = "#{create_digest}:run"
|
13
|
-
yield self if block_given?
|
14
13
|
end
|
15
14
|
|
16
15
|
def synchronize
|
@@ -15,6 +15,11 @@ module SidekiqUniqueJobs
|
|
15
15
|
|
16
16
|
def configure_server_middleware
|
17
17
|
Sidekiq.configure_server do |config|
|
18
|
+
config.client_middleware do |chain|
|
19
|
+
require 'sidekiq_unique_jobs/client/middleware'
|
20
|
+
chain.add SidekiqUniqueJobs::Client::Middleware
|
21
|
+
end
|
22
|
+
|
18
23
|
config.server_middleware do |chain|
|
19
24
|
require 'sidekiq_unique_jobs/server/middleware'
|
20
25
|
chain.add SidekiqUniqueJobs::Server::Middleware
|
@@ -5,13 +5,15 @@ module SidekiqUniqueJobs
|
|
5
5
|
ScriptError = Class.new(StandardError)
|
6
6
|
|
7
7
|
module Scripts
|
8
|
-
extend Forwardable
|
9
8
|
LUA_PATHNAME ||= Pathname.new(__FILE__).dirname.join('../../redis').freeze
|
10
9
|
SOURCE_FILES ||= Dir[LUA_PATHNAME.join('**/*.lua')].compact.freeze
|
11
10
|
DEFINED_METHODS ||= []
|
12
11
|
|
13
12
|
module_function
|
14
13
|
|
14
|
+
extend SingleForwardable
|
15
|
+
def_delegator :SidekiqUniqueJobs, :connection
|
16
|
+
|
15
17
|
def script_shas
|
16
18
|
@script_shas ||= {}
|
17
19
|
end
|
@@ -33,12 +35,6 @@ module SidekiqUniqueJobs
|
|
33
35
|
ex.backtrace.join("\n")
|
34
36
|
end
|
35
37
|
|
36
|
-
def connection(redis_pool, &_block)
|
37
|
-
SidekiqUniqueJobs.connection(redis_pool) do |conn|
|
38
|
-
yield conn
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
38
|
def script_source(file_name)
|
43
39
|
script_path(file_name).read
|
44
40
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module SidekiqUniqueJobs
|
2
|
+
module Util
|
3
|
+
SCAN_PATTERN ||= '*'.freeze
|
4
|
+
DEFAULT_COUNT ||= 1_000
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def keys(pattern = SCAN_PATTERN, count: DEFAULT_COUNT)
|
9
|
+
scan(pattern, count: count)
|
10
|
+
end
|
11
|
+
|
12
|
+
def del_by(pattern = SCAN_PATTERN, count:, dry_run: true)
|
13
|
+
logger.debug { "Deleting keys by: #{pattern}" }
|
14
|
+
keys, time = timed { scan(pattern, count: count) }
|
15
|
+
logger.debug { "#{keys.size} matching keys found in #{time} sec." }
|
16
|
+
keys = dry_run(keys)
|
17
|
+
logger.debug { "#{keys.size} matching keys after postprocessing" }
|
18
|
+
unless dry_run
|
19
|
+
logger.debug { "deleting #{keys}..." }
|
20
|
+
_, time = timed { del(keys) }
|
21
|
+
logger.debug { "Deleted in #{time} sec." }
|
22
|
+
end
|
23
|
+
keys.size
|
24
|
+
end
|
25
|
+
|
26
|
+
def del(keys)
|
27
|
+
connection do |conn|
|
28
|
+
keys.each_slice(500) do |chunk|
|
29
|
+
conn.pipelined do
|
30
|
+
chunk.each do |key|
|
31
|
+
conn.del key
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def dry_run(keys, pattern = nil)
|
39
|
+
return keys if pattern.nil?
|
40
|
+
regex = Regexp.new(pattern)
|
41
|
+
keys.select { |k| regex.match k }
|
42
|
+
end
|
43
|
+
|
44
|
+
def timed(&block)
|
45
|
+
start = Time.now
|
46
|
+
result = block.call
|
47
|
+
elapsed = (Time.now - start).round(2)
|
48
|
+
[result, elapsed]
|
49
|
+
end
|
50
|
+
|
51
|
+
def scan(pattern, count: 1000)
|
52
|
+
connection { |conn| conn.scan_each(match: prefix(pattern), count: count).to_a }
|
53
|
+
end
|
54
|
+
|
55
|
+
def prefix_keys(keys)
|
56
|
+
keys = Array(keys).flatten.compact
|
57
|
+
keys.map { |key| prefix(key) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def prefix(key)
|
61
|
+
return key if unique_prefix.nil?
|
62
|
+
"#{unique_prefix}:#{key}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def unique_prefix
|
66
|
+
SidekiqUniqueJobs.config.unique_prefix
|
67
|
+
end
|
68
|
+
|
69
|
+
def connection(&block)
|
70
|
+
SidekiqUniqueJobs.connection(&block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def logger
|
74
|
+
Sidekiq.logger
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore all logfiles and tempfiles.
|
11
|
+
/log/*
|
12
|
+
!/log/.keep
|
13
|
+
/tmp
|
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
ruby '2.2.3'
|
4
|
+
|
5
|
+
platforms :ruby do
|
6
|
+
gem 'sqlite3'
|
7
|
+
gem 'pry-byebug'
|
8
|
+
gem 'ruby-prof'
|
9
|
+
end
|
10
|
+
|
11
|
+
platforms :jruby do
|
12
|
+
gem 'jruby-openssl'
|
13
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'rails'
|
17
|
+
gem 'sidekiq-unique-jobs', path: '..'
|
18
|
+
gem 'sinatra'
|
19
|
+
gem 'web-console', '~> 2.0'
|
20
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>RailsExample</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
6
|
+
<%= javascript_include_tag 'application' %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= link_to 'Duplicate', duplicate_work_path %>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts '== Installing dependencies =='
|
12
|
+
system 'gem install bundler --conservative'
|
13
|
+
system 'bundle check || bundle install'
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system 'bin/rake db:setup'
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system 'rm -f log/*'
|
25
|
+
system 'rm -rf tmp/cache'
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system 'touch tmp/restart.txt'
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module RailsExample
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
16
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
17
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
18
|
+
|
19
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
20
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
21
|
+
# config.i18n.default_locale = :de
|
22
|
+
|
23
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
24
|
+
config.active_record.raise_in_transactional_callbacks = true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
26
|
+
|