delayed_job_groups_mongoid 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/delayed_job_groups_mongoid.gemspec +1 -1
- data/lib/delayed_job_groups/mongoid_groups.rb +1 -1
- data/spec/delayed_job_groups_spec.rb +19 -14
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
data/Gemfile
CHANGED
@@ -7,7 +7,7 @@ module Delayed
|
|
7
7
|
scope :in_unlocked_group, lambda{ where(:lock_group.nin => self.locked_groups) }
|
8
8
|
|
9
9
|
def self.locked_groups
|
10
|
-
Delayed::Job.only(:lock_group).where(:locked_by.ne => nil).map{|grouping| grouping[
|
10
|
+
Delayed::Job.only(:lock_group).where(:locked_by.ne => nil).group.map{ |grouping| grouping["lock_group"] }
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_time)
|
@@ -52,16 +52,21 @@ describe Delayed::Job do
|
|
52
52
|
|
53
53
|
context "with 2 jobs in the same group, one locked, one unlocked and 1 job in a different group" do
|
54
54
|
before do
|
55
|
-
|
56
|
-
|
57
|
-
@group_b_job1 = GroupedJob.new(:repository => "repo2")
|
55
|
+
a, b, c = ['repo1', 'repo1', 'repo2'].map{ |repo| GroupedJob.new(:repository => repo) }
|
56
|
+
job_a, job_b, job_c = [a, b, c].map{ |group_job| Delayed::Job.enqueue group_job }
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
2.times do
|
59
|
+
GroupedJob.new(:repository => 'repo1')
|
60
|
+
end
|
61
|
+
1.times{ GroupedJob.new(:repository => 'repo2') }
|
62
|
+
Delayed::Job.where(:lock_group => "repo1").first.lock_exclusively!(MAX_RUN_TIME, WORKER)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have one locked group" do
|
66
|
+
Delayed::Job.locked_groups.should == ['repo1']
|
62
67
|
end
|
63
68
|
|
64
|
-
it "should find
|
69
|
+
it "should find only the job in the different group" do
|
65
70
|
Delayed::Job.find_available(WORKER, MAX_RUN_TIME).count.should == 1
|
66
71
|
end
|
67
72
|
end
|
@@ -80,13 +85,13 @@ describe Delayed::Job do
|
|
80
85
|
2.times do
|
81
86
|
User.create(:role => "admin").send_welcome_email
|
82
87
|
end
|
83
|
-
1.times{
|
84
|
-
Delayed::Job.first.lock_exclusively!(MAX_RUN_TIME, WORKER)
|
85
|
-
|
88
|
+
1.times{ User.create(:role => "PA").send_welcome_email }
|
89
|
+
Delayed::Job.where(:lock_group => "admin").first.lock_exclusively!(MAX_RUN_TIME, WORKER)
|
86
90
|
end
|
87
91
|
|
88
|
-
it "should find
|
92
|
+
it "should only find the job in the different group" do
|
89
93
|
Delayed::Job.find_available(WORKER, MAX_RUN_TIME).count.should == 1
|
94
|
+
Delayed::Job.find_available(WORKER, MAX_RUN_TIME).first.lock_group.should == "PA"
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
@@ -96,12 +101,12 @@ describe Delayed::Job do
|
|
96
101
|
User.create(:role => "admin").delay.expensive_operation
|
97
102
|
end
|
98
103
|
1.times{ Delayed::Job.enqueue GroupedJob.new(:repository => "repo2") }
|
99
|
-
Delayed::Job.first.lock_exclusively!(MAX_RUN_TIME, WORKER)
|
100
|
-
|
104
|
+
Delayed::Job.where(:lock_group => "admin").first.lock_exclusively!(MAX_RUN_TIME, WORKER)
|
101
105
|
end
|
102
106
|
|
103
|
-
it "should find
|
107
|
+
it "should find only the job in the different group" do
|
104
108
|
Delayed::Job.find_available(WORKER, MAX_RUN_TIME).count.should == 1
|
109
|
+
Delayed::Job.find_available(WORKER, MAX_RUN_TIME).first.lock_group.should == "repo2"
|
105
110
|
end
|
106
111
|
end
|
107
112
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_groups_mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- opsb
|