job_hunter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +60 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/job_hunter.gemspec +27 -0
- data/lib/job_hunter/dj_wrappers.rb +20 -0
- data/lib/job_hunter/version.rb +3 -0
- data/lib/job_hunter.rb +4 -0
- data/spec/job_hunter_spec.rb +83 -0
- data/spec/spec_helper.rb +38 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c244340865960e0c4717ffd181cc0e12f11b4ed1
|
4
|
+
data.tar.gz: b714e3c2548e5303b23095470b2f8fd426b5cb6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29221c28c88302be1a112924f2bfa5467101f39886ac7936ceba6b00ec3ffdf5ef95a33d3fa3c9dc9b5979735eaf2b59a38d9b883e32d098f3ffb7abb3a14e43
|
7
|
+
data.tar.gz: c0777983d23b3d20c83328b0eafe5b2ab2702665f61c78e915094cf52b1496fc501331b877cb3f3072c60e32b4e35c0d45c28d8800629290124dc7d7f44913d0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
job_hunter (0.0.0)
|
5
|
+
delayed_job (>= 3.0, < 5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.1.1)
|
11
|
+
activesupport (= 4.1.1)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activerecord (4.1.1)
|
14
|
+
activemodel (= 4.1.1)
|
15
|
+
activesupport (= 4.1.1)
|
16
|
+
arel (~> 5.0.0)
|
17
|
+
activesupport (4.1.1)
|
18
|
+
i18n (~> 0.6, >= 0.6.9)
|
19
|
+
json (~> 1.7, >= 1.7.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
thread_safe (~> 0.1)
|
22
|
+
tzinfo (~> 1.1)
|
23
|
+
arel (5.0.1.20140414130214)
|
24
|
+
builder (3.2.2)
|
25
|
+
delayed_job (4.0.1)
|
26
|
+
activesupport (>= 3.0, < 4.2)
|
27
|
+
delayed_job_active_record (4.0.1)
|
28
|
+
activerecord (>= 3.0, < 4.2)
|
29
|
+
delayed_job (>= 3.0, < 4.1)
|
30
|
+
diff-lcs (1.2.5)
|
31
|
+
i18n (0.6.9)
|
32
|
+
json (1.8.1)
|
33
|
+
minitest (5.3.3)
|
34
|
+
rake (10.3.1)
|
35
|
+
rspec (3.0.0.beta2)
|
36
|
+
rspec-core (= 3.0.0.beta2)
|
37
|
+
rspec-expectations (= 3.0.0.beta2)
|
38
|
+
rspec-mocks (= 3.0.0.beta2)
|
39
|
+
rspec-core (3.0.0.beta2)
|
40
|
+
rspec-support (= 3.0.0.beta2)
|
41
|
+
rspec-expectations (3.0.0.beta2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (= 3.0.0.beta2)
|
44
|
+
rspec-mocks (3.0.0.beta2)
|
45
|
+
rspec-support (= 3.0.0.beta2)
|
46
|
+
rspec-support (3.0.0.beta2)
|
47
|
+
sqlite3 (1.3.9)
|
48
|
+
thread_safe (0.3.3)
|
49
|
+
tzinfo (1.1.0)
|
50
|
+
thread_safe (~> 0.1)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
delayed_job_active_record
|
57
|
+
job_hunter!
|
58
|
+
rake
|
59
|
+
rspec (= 3.0.0.beta2)
|
60
|
+
sqlite3 (~> 1)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ryan Moser
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/job_hunter.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'job_hunter/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = 'job_hunter'
|
9
|
+
gem.version = JobHunter::VERSION
|
10
|
+
gem.date = '2014-05-09'
|
11
|
+
gem.authors = ['Ryan Moser']
|
12
|
+
gem.email = 'ryanpmoser@gmail.com'
|
13
|
+
gem.homepage = 'https://github.com/moserrya/job_hunter'
|
14
|
+
gem.summary = 'A helper for custom Delayed Jobs'
|
15
|
+
gem.description = 'A gem to help reduce boilerplate when enqueing, finding, and deleting Delayed Jobs'
|
16
|
+
gem.license = 'MIT'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ['lib']
|
21
|
+
|
22
|
+
gem.add_dependency 'delayed_job', ['>= 3.0', '< 5.0']
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rake', '~> 10'
|
25
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
26
|
+
gem.add_development_dependency 'sqlite3', '~> 1'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JobHunter
|
2
|
+
def create(*args)
|
3
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
4
|
+
Delayed::Job.enqueue(new(*args), options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(*args)
|
8
|
+
handler = new(*args).to_yaml
|
9
|
+
Delayed::Job.where(handler: handler).first
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_or_create(*args)
|
13
|
+
job_args = args.last.is_a?(Hash) ? args[0..-2] : args
|
14
|
+
find(*job_args) or create(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy(*args)
|
18
|
+
find(*args).try(:destroy)
|
19
|
+
end
|
20
|
+
end
|
data/lib/job_hunter.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class KustomJob < Struct.new(:model_id, :details)
|
4
|
+
extend JobHunter
|
5
|
+
|
6
|
+
def perform
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe JobHunter do
|
11
|
+
let(:model_id) { 47 }
|
12
|
+
let(:details) { 'Party Solver' }
|
13
|
+
let(:run_at) { DateTime.parse('January 28, 2015 0800') }
|
14
|
+
let(:options) { { run_at: run_at } }
|
15
|
+
|
16
|
+
context '.create' do
|
17
|
+
it 'enqueues Delayed Jobs' do
|
18
|
+
expect {
|
19
|
+
KustomJob.create model_id, details
|
20
|
+
}.to change{Delayed::Job.count}.by(1)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'happily creates identical jobs' do
|
24
|
+
expect {
|
25
|
+
3.times { KustomJob.create model_id, details }
|
26
|
+
}.to change{Delayed::Job.count}.by(3)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'works with an options hash' do
|
30
|
+
expect {
|
31
|
+
KustomJob.create model_id, details, options
|
32
|
+
}.to change{Delayed::Job.count}.by(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '.find' do
|
37
|
+
before do
|
38
|
+
custom_job = KustomJob.new model_id, details
|
39
|
+
@job = Delayed::Job.enqueue custom_job
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'finds the job given the same arguments' do
|
43
|
+
expect(KustomJob.find(model_id, details)).to eq(@job)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '.find_or_create' do
|
48
|
+
it 'creates the job when it is not in the queue' do
|
49
|
+
expect {
|
50
|
+
KustomJob.find_or_create model_id, details, options
|
51
|
+
}.to change{Delayed::Job.count}.by(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'job already enqueued' do
|
55
|
+
before do
|
56
|
+
@job = KustomJob.create model_id, details
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'does not enqueue a job if one with the same arguments was already enqueued' do
|
60
|
+
expect {
|
61
|
+
KustomJob.find_or_create model_id, details, options
|
62
|
+
}.not_to change{Delayed::Job.count}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns the job if it was already enqueued' do
|
66
|
+
expect(KustomJob.find_or_create model_id, details, options).to eq(@job)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context '.destroy' do
|
72
|
+
it 'destroys the job, removing it from the queue' do
|
73
|
+
KustomJob.create model_id, details
|
74
|
+
expect {
|
75
|
+
KustomJob.destroy model_id, details
|
76
|
+
}.to change{Delayed::Job.count}.by(-1)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns nil if there is nothing to destory' do
|
80
|
+
expect(KustomJob.destroy model_id, details).to be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
require 'active_support/dependencies'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
require 'delayed_job_active_record'
|
7
|
+
|
8
|
+
require 'job_hunter'
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
11
|
+
ActiveRecord::Migration.verbose = false
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define do
|
14
|
+
create_table :delayed_jobs, :force => true do |table|
|
15
|
+
table.integer :priority, :default => 0
|
16
|
+
table.integer :attempts, :default => 0
|
17
|
+
table.text :handler
|
18
|
+
table.text :last_error
|
19
|
+
table.datetime :run_at
|
20
|
+
table.datetime :locked_at
|
21
|
+
table.datetime :failed_at
|
22
|
+
table.string :locked_by
|
23
|
+
table.string :queue
|
24
|
+
table.timestamps
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.expect_with :rspec do |c|
|
32
|
+
c.syntax = :expect
|
33
|
+
end
|
34
|
+
|
35
|
+
config.after(:each) do
|
36
|
+
Delayed::Job.delete_all
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: job_hunter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Moser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: delayed_job
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: sqlite3
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1'
|
75
|
+
description: A gem to help reduce boilerplate when enqueing, finding, and deleting
|
76
|
+
Delayed Jobs
|
77
|
+
email: ryanpmoser@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- Gemfile
|
84
|
+
- Gemfile.lock
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- job_hunter.gemspec
|
89
|
+
- lib/job_hunter.rb
|
90
|
+
- lib/job_hunter/dj_wrappers.rb
|
91
|
+
- lib/job_hunter/version.rb
|
92
|
+
- spec/job_hunter_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: https://github.com/moserrya/job_hunter
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: A helper for custom Delayed Jobs
|
118
|
+
test_files:
|
119
|
+
- spec/job_hunter_spec.rb
|
120
|
+
- spec/spec_helper.rb
|