delayed_job_mongoid 1.0.0.rc → 1.0.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.
- data/README.md +8 -4
- data/lib/delayed/backend/mongoid.rb +14 -13
- data/lib/delayed/serialization/mongoid.rb +3 -3
- data/spec/spec_helper.rb +3 -8
- metadata +10 -13
data/README.md
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
## Installation
|
4
4
|
|
5
|
-
Add the gems to
|
5
|
+
Add the gems to your Gemfile:
|
6
|
+
|
7
|
+
gem 'delayed_job', '2.1.0.pre2'
|
8
|
+
gem 'delayed_job_mongoid', '1.0.0.rc'
|
9
|
+
|
10
|
+
Create the indexes:
|
11
|
+
|
12
|
+
script/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes'
|
6
13
|
|
7
|
-
gem 'delayed_job', '2.1.0.pre2'
|
8
|
-
gem 'delayed_job_mongoid', '1.0.0.rc'
|
9
|
-
|
10
14
|
That's it. Use [delayed_job as normal](http://github.com/collectiveidea/delayed_job).
|
@@ -10,33 +10,34 @@ module Delayed
|
|
10
10
|
field :handler, :type=> String
|
11
11
|
field :run_at, :type=> Time
|
12
12
|
field :locked_at, :type=> Time
|
13
|
-
field :locked_by, :type=> String
|
13
|
+
field :locked_by, :type=> String
|
14
14
|
field :failed_at, :type=> Time
|
15
15
|
field :last_error, :type=> String
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
index :locked_by
|
18
|
+
|
18
19
|
before_save :set_default_run_at
|
19
|
-
|
20
|
+
|
20
21
|
def self.before_fork
|
21
22
|
::Mongoid.master.connection.close
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.after_fork
|
25
|
-
::Mongoid.master.connection.
|
26
|
+
::Mongoid.master.connection.connect
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
def self.db_time_now
|
29
30
|
Time.now.utc
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
|
33
34
|
right_now = db_time_now
|
34
35
|
|
35
36
|
conditions = {:run_at => {"$lte" => right_now}, :failed_at => nil}
|
36
37
|
(conditions[:priority] ||= {})['$gte'] = Worker.min_priority.to_i if Worker.min_priority
|
37
38
|
(conditions[:priority] ||= {})['$lte'] = Worker.max_priority.to_i if Worker.max_priority
|
38
|
-
|
39
|
-
|
39
|
+
|
40
|
+
|
40
41
|
where = "this.locked_at == null || this.locked_at < #{make_date(right_now - max_run_time)}"
|
41
42
|
results = self.where(conditions.merge(:locked_by => worker_name)).limit(-limit).order_by([['priority', 1], ['run_at', 1]]).to_a
|
42
43
|
results += self.where(conditions.merge('$where' => where)).limit(-limit+results.size).order_by([['priority', 1], ['run_at', 1]]).to_a if results.size < limit
|
@@ -46,16 +47,16 @@ module Delayed
|
|
46
47
|
def self.clear_locks!(worker_name)
|
47
48
|
self.collection.update({:locked_by => worker_name}, {"$set" => {:locked_at => nil, :locked_by => nil}}, :multi => true)
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
# Lock this job for this worker.
|
51
52
|
# Returns true if we have the lock, false otherwise.
|
52
53
|
def lock_exclusively!(max_run_time, worker = worker_name)
|
53
54
|
right_now = self.class.db_time_now
|
54
55
|
overtime = right_now - max_run_time.to_i
|
55
|
-
|
56
|
+
|
56
57
|
query = "this.locked_at == null || this.locked_at < #{make_date(overtime)} || this.locked_by == #{worker.to_json}"
|
57
58
|
conditions = {:_id => id, :run_at => {"$lte" => right_now}, "$where" => query}
|
58
|
-
|
59
|
+
|
59
60
|
self.collection.update(conditions, {"$set" => {:locked_at => right_now, :locked_by => worker}})
|
60
61
|
affected_rows = self.collection.find({:_id => id, :locked_by => worker}).count
|
61
62
|
if affected_rows == 1
|
@@ -66,7 +67,7 @@ module Delayed
|
|
66
67
|
return false
|
67
68
|
end
|
68
69
|
end
|
69
|
-
|
70
|
+
|
70
71
|
private
|
71
72
|
|
72
73
|
def self.make_date(date_or_seconds)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
Mongoid::Document.class_eval do
|
2
2
|
yaml_as "tag:ruby.yaml.org,2002:Mongoid"
|
3
|
-
|
3
|
+
|
4
4
|
def self.yaml_new(klass, tag, val)
|
5
5
|
begin
|
6
6
|
klass.find(val['attributes']['_id'])
|
7
7
|
rescue Mongoid::Errors::DocumentNotFound
|
8
|
-
|
8
|
+
raise Delayed::DeserializationError
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def to_yaml_properties
|
13
13
|
['@attributes']
|
14
14
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,22 +2,17 @@ require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
require '
|
6
|
-
require 'spec/autorun'
|
5
|
+
require 'rspec'
|
7
6
|
require 'delayed_job_mongoid'
|
8
7
|
require 'delayed/backend/shared_spec'
|
9
8
|
|
10
|
-
Spec::Runner.configure do |config|
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
9
|
Mongoid.configure do |config|
|
15
|
-
config.master = config.master = Mongo::Connection.new.db('dl_spec')
|
10
|
+
config.master = config.master = Mongo::Connection.new.db('dl_spec')
|
16
11
|
end
|
17
12
|
|
18
13
|
class Story
|
19
14
|
include ::Mongoid::Document
|
20
|
-
def tell; text; end
|
15
|
+
def tell; text; end
|
21
16
|
def whatever(n, _); tell*n; end
|
22
17
|
def self.count; end
|
23
18
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0.rc
|
9
|
+
version: 1.0.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Brandon Keepers
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-14 00:00:00 -06:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +40,8 @@ dependencies:
|
|
41
40
|
segments:
|
42
41
|
- 2
|
43
42
|
- 1
|
44
|
-
|
43
|
+
- 1
|
44
|
+
version: 2.1.1
|
45
45
|
type: :runtime
|
46
46
|
version_requirements: *id002
|
47
47
|
- !ruby/object:Gem::Dependency
|
@@ -52,10 +52,9 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
segments:
|
55
|
-
- 1
|
56
55
|
- 2
|
57
|
-
-
|
58
|
-
version:
|
56
|
+
- 0
|
57
|
+
version: "2.0"
|
59
58
|
type: :development
|
60
59
|
version_requirements: *id003
|
61
60
|
description:
|
@@ -94,13 +93,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
93
|
version: "0"
|
95
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
95
|
requirements:
|
97
|
-
- - "
|
96
|
+
- - ">="
|
98
97
|
- !ruby/object:Gem::Version
|
99
98
|
segments:
|
100
|
-
-
|
101
|
-
|
102
|
-
- 1
|
103
|
-
version: 1.3.1
|
99
|
+
- 0
|
100
|
+
version: "0"
|
104
101
|
requirements: []
|
105
102
|
|
106
103
|
rubyforge_project:
|