delayed_job_mongoid 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/delayed/backend/mongoid.rb +16 -12
- metadata +15 -8
@@ -42,11 +42,24 @@ module Delayed
|
|
42
42
|
(conditions[:priority] ||= {})['$gte'] = Worker.min_priority.to_i if Worker.min_priority
|
43
43
|
(conditions[:priority] ||= {})['$lte'] = Worker.max_priority.to_i if Worker.max_priority
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
if ::Mongoid.master.connection.server_version < '1.5.3'
|
46
|
+
lock_time = "new Date(#{(right_now - max_run_time).to_f * 1000})"
|
47
|
+
conditions['$where'] = "this.locked_by == '#{worker.name}' || this.locked_at == null || this.locked_at < #{lock_time}"
|
48
|
+
else
|
49
|
+
conditions['$or'] = [
|
50
|
+
{ :locked_by => worker.name },
|
51
|
+
{ :locked_at => nil },
|
52
|
+
{ :locked_at => { '$lt' => (right_now - max_run_time) }}
|
53
|
+
]
|
54
|
+
end
|
47
55
|
|
48
56
|
begin
|
49
|
-
result = self.db.collection(self.collection.name).find_and_modify(
|
57
|
+
result = self.db.collection(self.collection.name).find_and_modify(
|
58
|
+
:query => conditions,
|
59
|
+
:sort => [['locked_by', -1], ['priority', 1], ['run_at', 1]],
|
60
|
+
:update => {"$set" => {:locked_at => right_now, :locked_by => worker.name}}
|
61
|
+
)
|
62
|
+
|
50
63
|
# Return result as a Mongoid document.
|
51
64
|
# When Mongoid starts supporting findAndModify, this extra step should no longer be necessary.
|
52
65
|
self.find(:first, :conditions => {:_id => result["_id"]})
|
@@ -60,15 +73,6 @@ module Delayed
|
|
60
73
|
self.collection.update({:locked_by => worker_name}, {"$set" => {:locked_at => nil, :locked_by => nil}}, :multi => true)
|
61
74
|
end
|
62
75
|
|
63
|
-
private
|
64
|
-
|
65
|
-
def self.make_date(date_or_seconds)
|
66
|
-
"new Date(#{date_or_seconds.to_f * 1000})"
|
67
|
-
end
|
68
|
-
|
69
|
-
def make_date(date)
|
70
|
-
self.class.make_date(date)
|
71
|
-
end
|
72
76
|
end
|
73
77
|
end
|
74
78
|
end
|
metadata
CHANGED
@@ -5,21 +5,21 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
+
- Chris Gaffney
|
12
13
|
- Brandon Keepers
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-01-12 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: mongoid
|
22
|
-
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -28,12 +28,14 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 2
|
30
30
|
- 0
|
31
|
-
|
31
|
+
- 0
|
32
|
+
- rc
|
33
|
+
version: 2.0.0.rc
|
32
34
|
type: :runtime
|
35
|
+
prerelease: false
|
33
36
|
version_requirements: *id001
|
34
37
|
- !ruby/object:Gem::Dependency
|
35
38
|
name: delayed_job
|
36
|
-
prerelease: false
|
37
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
40
|
none: false
|
39
41
|
requirements:
|
@@ -45,10 +47,10 @@ dependencies:
|
|
45
47
|
- 1
|
46
48
|
version: 2.1.1
|
47
49
|
type: :runtime
|
50
|
+
prerelease: false
|
48
51
|
version_requirements: *id002
|
49
52
|
- !ruby/object:Gem::Dependency
|
50
53
|
name: rspec
|
51
|
-
prerelease: false
|
52
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
54
56
|
requirements:
|
@@ -59,9 +61,12 @@ dependencies:
|
|
59
61
|
- 0
|
60
62
|
version: "2.0"
|
61
63
|
type: :development
|
64
|
+
prerelease: false
|
62
65
|
version_requirements: *id003
|
63
66
|
description:
|
64
|
-
email:
|
67
|
+
email:
|
68
|
+
- chris@collectiveidea.com
|
69
|
+
- brandon@opensoul.com
|
65
70
|
executables: []
|
66
71
|
|
67
72
|
extensions: []
|
@@ -92,6 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
97
|
requirements:
|
93
98
|
- - ">="
|
94
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: -124528161725345693
|
95
101
|
segments:
|
96
102
|
- 0
|
97
103
|
version: "0"
|
@@ -100,6 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
106
|
requirements:
|
101
107
|
- - ">="
|
102
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: -124528161725345693
|
103
110
|
segments:
|
104
111
|
- 0
|
105
112
|
version: "0"
|