sidekiq-concurrency_safety 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9438128442f866bab166dd89c3a60690fc9acf58658266bed19240ba55b4ac4f
4
+ data.tar.gz: b277205f3c8c26debb03eadb9f229dd38b0c17827419b4940307c7470ee0df9b
5
+ SHA512:
6
+ metadata.gz: bdd366d47c10aeb1b5f5803f96f180cb2d383d706b4582ae6457c5d265d73a72ebcbc441219c009a9c2c923d52fec48ef42fe5bdb49b26ab9a9a718e578517af
7
+ data.tar.gz: 810321dd393dc293ff2c4038cdc9e66c30ab4af1ef44dd9fa362f0138192e24d8edb9474e0cf140b51e9323464e7f6f71b971d17be45091a921ce1a43288976e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sidekiq-concurrency_safety.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "mock_redis"
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sidekiq-concurrency_safety (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ mock_redis (0.22.0)
11
+ rake (12.3.3)
12
+ rspec (3.9.0)
13
+ rspec-core (~> 3.9.0)
14
+ rspec-expectations (~> 3.9.0)
15
+ rspec-mocks (~> 3.9.0)
16
+ rspec-core (3.9.1)
17
+ rspec-support (~> 3.9.1)
18
+ rspec-expectations (3.9.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.9.0)
21
+ rspec-mocks (3.9.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.9.0)
24
+ rspec-support (3.9.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ mock_redis
31
+ rake (~> 12.0)
32
+ rspec (~> 3.0)
33
+ sidekiq-concurrency_safety!
34
+
35
+ BUNDLED WITH
36
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Sidekiq::ConcurrencySafety
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sidekiq/concurrency_safety`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sidekiq-concurrency_safety'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sidekiq-concurrency_safety
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sidekiq-concurrency_safety.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidekiq/concurrency_safety"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ require "sidekiq/concurrency_safety/version"
2
+
3
+ module Sidekiq
4
+ module ConcurrencySafety
5
+ class AlreadyRunningError < StandardError; end
6
+
7
+ def perform(*args)
8
+ @args = args
9
+
10
+ redis_key = key_generator
11
+
12
+ redis_pool.with do |r|
13
+ raise AlreadyRunningError unless r.set(redis_key, 1, ex: 25_000, nx: true)
14
+
15
+ begin
16
+ super
17
+ ensure
18
+ r.del(redis_key)
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :args
26
+
27
+ def key_generator
28
+ ["job_running", self.class.name, final_key].join(":")
29
+ end
30
+
31
+ def final_key
32
+ concurrency_key_exists? ? concurrency_key : args.map(&:to_s)
33
+ end
34
+
35
+ def concurrency_key_exists?
36
+ methods.include?(:concurrency_key)
37
+ end
38
+
39
+ def redis_pool
40
+ Sidekiq.redis_pool
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Sidekiq
2
+ module ConcurrencySafety
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/sidekiq/concurrency_safety/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sidekiq-concurrency_safety"
5
+ spec.version = Sidekiq::ConcurrencySafety::VERSION
6
+ spec.authors = ["Tom Chipchase"]
7
+ spec.email = ["tom.chipchase@farmdrop.co.uk"]
8
+
9
+ spec.summary = %q{Prevent multiple sidekiq jobs with the same arguments from running at the same time.}
10
+ spec.homepage = "https://github.com/tomchipchase/sidekiq-concurrency_safety"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+
13
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/master/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-concurrency_safety
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Chipchase
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - tom.chipchase@farmdrop.co.uk
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/sidekiq/concurrency_safety.rb
31
+ - lib/sidekiq/concurrency_safety/version.rb
32
+ - sidekiq-concurrency_safety.gemspec
33
+ homepage: https://github.com/tomchipchase/sidekiq-concurrency_safety
34
+ licenses: []
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/tomchipchase/sidekiq-concurrency_safety
38
+ source_code_uri: https://github.com/tomchipchase/sidekiq-concurrency_safety
39
+ changelog_uri: https://github.com/tomchipchase/sidekiq-concurrency_safety/master/CHANGELOG.md
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Prevent multiple sidekiq jobs with the same arguments from running at the
59
+ same time.
60
+ test_files: []