talentbox-delayed_job_sequel 4.0.0.beta1.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f8e892e566b9bc3eb6eb7a1f2d35d94ffbde5a5
4
+ data.tar.gz: 2bba9ee791fa8e372ad39080a328be34655d8d69
5
+ SHA512:
6
+ metadata.gz: b9f5b3c244e2f6ae39260bd9423901cc3d596bc068234cc290ab9d4881227c3721f2f18c6c9f7159ab7305cf5e213605b9a0e56db588b81858598a0be485a1bf
7
+ data.tar.gz: 5df02d82391bf890322db2539d9cf2091ba041543c40aa40cebdf5db540cbb3482babf0179f31c6aaae10cdd68403724ab649e1c5623d699b98307547c232de8
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # DelayedJob Sequel Backend
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/TalentBox/delayed_job_sequel.png?branch=master)](http://travis-ci.org/TalentBox/delayed_job_sequel)
4
+ [![Code Climate](https://codeclimate.com/github/TalentBox/delayed_job_sequel.png)](https://codeclimate.com/github/TalentBox/delayed_job_sequel)
5
+
3
6
  ## Compatibility
4
7
 
5
8
  This gem works on Ruby (MRI/CRuby) 1.8.x, 1.9.x and Rubinius (1.8 and 1.9 mode).
@@ -35,9 +38,13 @@ Create the table (using the sequel migration syntax):
35
38
  index [:priority, :run_at]
36
39
  end
37
40
 
38
- ## Build Status
41
+ ## Contributors
39
42
 
40
- [![Build Status](https://secure.travis-ci.org/TalentBox/delayed_job_sequel.png?branch=master)](http://travis-ci.org/TalentBox/delayed_job_sequel)
43
+ Improvements has been made by those awesome contributors:
44
+
45
+ * Mark Rushakoff (mark-rushakoff)
46
+ * Phan Le
47
+ * Tim Labeeuw
41
48
 
42
49
  ## How to contribute
43
50
 
@@ -17,15 +17,17 @@ module Delayed
17
17
  db_time_now = model.db_time_now
18
18
  lock_upper_bound = db_time_now - max_run_time
19
19
  filter do
20
- ( (run_at <= db_time_now) &
21
- ({:locked_at => nil} | (locked_at < lock_upper_bound)) |
20
+ (
21
+ (run_at <= db_time_now) &
22
+ ::Sequel.expr(:locked_at => nil) |
23
+ (::Sequel.expr(:locked_at) < lock_upper_bound) |
22
24
  {:locked_by => worker_name}
23
25
  ) & {:failed_at => nil}
24
26
  end
25
27
  end
26
28
 
27
29
  def_dataset_method :by_priority do
28
- order(:priority.asc, :run_at.asc)
30
+ order(::Sequel.expr(:priority).asc, ::Sequel.expr(:run_at).asc)
29
31
  end
30
32
 
31
33
  def self.before_fork
@@ -38,49 +40,20 @@ module Delayed
38
40
  end
39
41
 
40
42
  def self.reserve(worker, max_run_time = Worker.max_run_time)
41
- set = ready_to_run(worker.name, max_run_time)
42
- set = set.filter("priority >= ?", Worker.min_priority) if Worker.min_priority
43
- set = set.filter("priority <= ?", Worker.max_priority) if Worker.max_priority
44
- set = set.filter(:queue => Worker.queues) if Worker.queues.any?
45
-
46
- job = set.by_priority.first
47
-
48
- now = self.db_time_now
49
-
50
- return unless job
51
- model.db.transaction do
52
- job.lock!
53
- job.locked_at = now
54
- job.locked_by = worker.name
55
- job.save(:raise_on_failure => true)
56
- end
57
- job
58
- end
59
-
60
- # Lock this job for this worker.
61
- # Returns true if we have the lock, false otherwise.
62
- def lock_exclusively!(max_run_time, worker)
63
- now = self.class.db_time_now
64
- affected_rows = if locked_by != worker
65
- # We don't own this job so we will update the locked_by name and the locked_at
66
- lock_upper_bound = now - max_run_time.to_i
67
- closure_pk = pk
68
- self.class.filter{
69
- {:id => closure_pk} &
70
- ({:locked_at => nil} | (locked_at < lock_upper_bound)) &
71
- (run_at <= now)
72
- }.update(:locked_at => now, :locked_by => worker)
73
- else
74
- # We already own this job, this may happen if the job queue crashes.
75
- # Simply resume and update the locked_at
76
- self.class.filter(:id => id, :locked_by => worker).update(:locked_at => now)
77
- end
78
- if affected_rows == 1
79
- self.locked_at = now
80
- self.locked_by = worker
81
- return true
82
- else
83
- return false
43
+ ds = ready_to_run(worker.name, max_run_time)
44
+ ds = ds.filter("priority >= ?", Worker.min_priority) if Worker.min_priority
45
+ ds = ds.filter("priority <= ?", Worker.max_priority) if Worker.max_priority
46
+ ds = ds.filter(:queue => Worker.queues) if Worker.queues.any?
47
+ ds = ds.by_priority
48
+ ds = ds.for_update
49
+
50
+ db.transaction do
51
+ if job = ds.first
52
+ job.locked_at = self.db_time_now
53
+ job.locked_by = worker.name
54
+ job.save(:raise_on_failure => true)
55
+ job
56
+ end
84
57
  end
85
58
  end
86
59
 
@@ -98,7 +71,7 @@ module Delayed
98
71
  end
99
72
 
100
73
  def self.delete_all
101
- delete
74
+ dataset.delete
102
75
  end
103
76
 
104
77
  def reload(*args)
@@ -147,7 +120,7 @@ module Delayed
147
120
  # This differs from ActiveRecord which checks class and id only.
148
121
  # To pass the specs we're reverting to what AR does here.
149
122
  def eql?(obj)
150
- (obj.class == model) && (obj.pk == pk)
123
+ (obj.class == self.class) && (obj.pk == pk)
151
124
  end
152
125
 
153
126
  end
@@ -8,6 +8,24 @@ describe Delayed::Backend::Sequel::Job do
8
8
 
9
9
  it_should_behave_like "a delayed_job backend"
10
10
 
11
+ it "does not allow more than 1 worker to grab the same job" do
12
+ expect {
13
+ 10.times do
14
+ described_class.create(payload_object: SimpleJob.new)
15
+ end
16
+
17
+ 20.times.map do |i|
18
+ Thread.new do
19
+ worker = Delayed::Worker.new
20
+ worker.name = "worker_#{i}"
21
+ worker.work_off(4)
22
+ end
23
+ end.map(&:join)
24
+ }.not_to raise_error
25
+
26
+ expect(Delayed::Job.count).to be < 10
27
+ end
28
+
11
29
  context ".count" do
12
30
  context "NewRelic sampler compat" do
13
31
  it "allow count with conditions" do
metadata CHANGED
@@ -1,64 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talentbox-delayed_job_sequel
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 4.0.0.beta1.1
4
+ version: 4.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonathan Tron
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-09 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sequel
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - ~>
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.38'
20
+ - - <
19
21
  - !ruby/object:Gem::Version
20
- version: '3.28'
21
- none: false
22
+ version: '5.0'
22
23
  type: :runtime
24
+ prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - ~>
27
+ - - '>='
26
28
  - !ruby/object:Gem::Version
27
- version: '3.28'
28
- none: false
29
- prerelease: false
29
+ version: '3.38'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: delayed_job
32
35
  requirement: !ruby/object:Gem::Requirement
33
36
  requirements:
34
37
  - - ~>
35
38
  - !ruby/object:Gem::Version
36
- version: 4.0.0.beta1
37
- none: false
39
+ version: 4.0.0
38
40
  type: :runtime
41
+ prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
44
  - - ~>
42
45
  - !ruby/object:Gem::Version
43
- version: 4.0.0.beta1
44
- none: false
45
- prerelease: false
46
+ version: 4.0.0
46
47
  - !ruby/object:Gem::Dependency
47
48
  name: tzinfo
48
49
  requirement: !ruby/object:Gem::Requirement
49
50
  requirements:
50
- - - ! '>='
51
+ - - '>='
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
- none: false
54
54
  type: :runtime
55
+ prerelease: false
55
56
  version_requirements: !ruby/object:Gem::Requirement
56
57
  requirements:
57
- - - ! '>='
58
+ - - '>='
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
60
- none: false
61
- prerelease: false
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: rspec
64
63
  requirement: !ruby/object:Gem::Requirement
@@ -66,31 +65,27 @@ dependencies:
66
65
  - - ~>
67
66
  - !ruby/object:Gem::Version
68
67
  version: '2.13'
69
- none: false
70
68
  type: :development
69
+ prerelease: false
71
70
  version_requirements: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ~>
74
73
  - !ruby/object:Gem::Version
75
74
  version: '2.13'
76
- none: false
77
- prerelease: false
78
75
  - !ruby/object:Gem::Dependency
79
76
  name: rake
80
77
  requirement: !ruby/object:Gem::Requirement
81
78
  requirements:
82
- - - ~>
79
+ - - '>='
83
80
  - !ruby/object:Gem::Version
84
- version: '0.8'
85
- none: false
81
+ version: '0'
86
82
  type: :development
83
+ prerelease: false
87
84
  version_requirements: !ruby/object:Gem::Requirement
88
85
  requirements:
89
- - - ~>
86
+ - - '>='
90
87
  - !ruby/object:Gem::Version
91
- version: '0.8'
92
- none: false
93
- prerelease: false
88
+ version: '0'
94
89
  description: Sequel backend for DelayedJob, originally authored by Tobias Luetke
95
90
  email:
96
91
  - jonathan@tron.name
@@ -111,6 +106,7 @@ files:
111
106
  - README.md
112
107
  homepage: http://github.com/TalentBox/delayed_job_sequel
113
108
  licenses: []
109
+ metadata: {}
114
110
  post_install_message:
115
111
  rdoc_options:
116
112
  - --main
@@ -121,24 +117,19 @@ require_paths:
121
117
  - lib
122
118
  required_ruby_version: !ruby/object:Gem::Requirement
123
119
  requirements:
124
- - - ! '>='
120
+ - - '>='
125
121
  - !ruby/object:Gem::Version
126
- segments:
127
- - 0
128
- hash: 3436972036027455601
129
122
  version: '0'
130
- none: false
131
123
  required_rubygems_version: !ruby/object:Gem::Requirement
132
124
  requirements:
133
- - - ! '>'
125
+ - - '>='
134
126
  - !ruby/object:Gem::Version
135
- version: 1.3.1
136
- none: false
127
+ version: '0'
137
128
  requirements: []
138
129
  rubyforge_project:
139
- rubygems_version: 1.8.23
130
+ rubygems_version: 2.1.9
140
131
  signing_key:
141
- specification_version: 3
132
+ specification_version: 4
142
133
  summary: Sequel backend for DelayedJob
143
134
  test_files:
144
135
  - spec/delayed/backend/sequel_spec.rb