dj_unique 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/dj_unique.gemspec +25 -0
- data/lib/dj_unique.rb +6 -0
- data/lib/dj_unique/unique_job.rb +15 -0
- data/lib/dj_unique/version.rb +3 -0
- data/spec/database.yml +14 -0
- data/spec/helper.rb +39 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/test/heavy_duty.rb +5 -0
- data/spec/unique_job_spec.rb +21 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be24903483318f5ccea0fc2c62ca00d1e2a71972
|
4
|
+
data.tar.gz: 2700c7d2942964a70905d083a18b0a15b8a409cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6373dbe739044393c2299245b467ec3ebbc1bac5a6e8df469a8cab1cf93f74c37b38d64d6885d3ef0043376f9593ab1f52fc9532028258340b8e3681a7a65a0
|
7
|
+
data.tar.gz: 026811872e264a3d2d8ead1510d9f726769497a1b1177f44aee797d2a388c73a47ab16c603dbd90cb56eb47eafd63fc4b38539c095ec65e2029f855295af42b0
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
dj_unique
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
platforms :jruby do
|
5
|
+
gem 'activerecord-jdbcmysql-adapter'
|
6
|
+
gem 'jdbc-mysql'
|
7
|
+
|
8
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
9
|
+
gem 'jdbc-postgres'
|
10
|
+
|
11
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
12
|
+
gem 'jdbc-sqlite3'
|
13
|
+
end
|
14
|
+
|
15
|
+
platforms :ruby, :mswin, :mingw do
|
16
|
+
gem 'mysql', '~> 2.8.1'
|
17
|
+
gem 'pg'
|
18
|
+
gem 'sqlite3'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Specify your gem's dependencies in dj_unique.gemspec
|
23
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Swapnil Abnave
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# DjUnique
|
2
|
+
|
3
|
+
An armour for delayed_job_active_record to ensure no duplicate jobs are enqueued.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dj_unique'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dj_unique
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dj_unique.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dj_unique/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dj_unique"
|
8
|
+
spec.version = DjUnique::VERSION
|
9
|
+
spec.authors = ["Swapnil Abnave"]
|
10
|
+
spec.email = ["swapnilabnave42@gmail.com"]
|
11
|
+
spec.description = %q{An armour for delayed_job_active_record to ensure no duplicate jobs are enqueued}
|
12
|
+
spec.summary = %q{dj stands for delayed_job}
|
13
|
+
spec.homepage = "https://github.com/swapnilabnave/dj_unique"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
17
|
+
spec.add_development_dependency "rake"
|
18
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
19
|
+
spec.add_dependency "delayed_job_active_record", "~> 4.0.0"
|
20
|
+
|
21
|
+
spec.files = `git ls-files`.split($/)
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
end
|
data/lib/dj_unique.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Delayed
|
2
|
+
class UniqueJob < Job
|
3
|
+
def self.enqueue(*args)
|
4
|
+
super unless active_jobs(args.first)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.active_jobs(object)
|
8
|
+
working_OR_successful_OR_pending.find_by_handler(object.to_yaml)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.working_OR_successful_OR_pending
|
12
|
+
where('locked_at IS NOT NULL OR last_error IS NULL OR attempts = 0')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/database.yml
ADDED
data/spec/helper.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'protected_attributes'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'delayed_job_active_record'
|
10
|
+
|
11
|
+
ENV['RAILS_ENV'] = 'test'
|
12
|
+
|
13
|
+
db_adapter, gemfile = ENV["ADAPTER"], ENV["BUNDLE_GEMFILE"]
|
14
|
+
db_adapter ||= gemfile && gemfile[%r(gemfiles/(.*?)/)] && $1
|
15
|
+
db_adapter ||= 'sqlite3'
|
16
|
+
|
17
|
+
config = YAML.load(File.read('spec/database.yml'))
|
18
|
+
ActiveRecord::Base.establish_connection config[db_adapter]
|
19
|
+
ActiveRecord::Migration.verbose = false
|
20
|
+
|
21
|
+
ActiveRecord::Schema.define do
|
22
|
+
create_table :delayed_jobs, :force => true do |table|
|
23
|
+
table.integer :priority, :default => 0
|
24
|
+
table.integer :attempts, :default => 0
|
25
|
+
table.text :handler
|
26
|
+
table.text :last_error
|
27
|
+
table.datetime :run_at
|
28
|
+
table.datetime :locked_at
|
29
|
+
table.datetime :failed_at
|
30
|
+
table.string :locked_by
|
31
|
+
table.string :queue
|
32
|
+
table.timestamps
|
33
|
+
end
|
34
|
+
|
35
|
+
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Add this directory so the ActiveSupport autoloading works
|
39
|
+
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'spec_helper'
|
3
|
+
require "test/heavy_duty"
|
4
|
+
|
5
|
+
describe Delayed::UniqueJob do
|
6
|
+
before do
|
7
|
+
@performable = HeavyDuty.new('Coding Machine')
|
8
|
+
Delayed::UniqueJob.enqueue(@performable)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'get active_jobs for the performable object' do
|
12
|
+
@active_jobs = Delayed::UniqueJob.active_jobs(@performable)
|
13
|
+
@active_jobs.should_not be_blank
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'reject active jobs with non matching handler' do
|
17
|
+
@performable = HeavyDuty.new('werewolf')
|
18
|
+
@active_jobs = Delayed::UniqueJob.active_jobs(@performable)
|
19
|
+
@active_jobs.should be_blank
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dj_unique
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Swapnil Abnave
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: delayed_job_active_record
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
description: An armour for delayed_job_active_record to ensure no duplicate jobs are
|
70
|
+
enqueued
|
71
|
+
email:
|
72
|
+
- swapnilabnave42@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .ruby-gemset
|
79
|
+
- .ruby-version
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- dj_unique.gemspec
|
85
|
+
- lib/dj_unique.rb
|
86
|
+
- lib/dj_unique/unique_job.rb
|
87
|
+
- lib/dj_unique/version.rb
|
88
|
+
- spec/database.yml
|
89
|
+
- spec/helper.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/test/heavy_duty.rb
|
92
|
+
- spec/unique_job_spec.rb
|
93
|
+
homepage: https://github.com/swapnilabnave/dj_unique
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.0.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: dj stands for delayed_job
|
117
|
+
test_files:
|
118
|
+
- spec/database.yml
|
119
|
+
- spec/helper.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/test/heavy_duty.rb
|
122
|
+
- spec/unique_job_spec.rb
|