delayed_job_groups_mongoid 0.2.3 → 0.2.4

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/Gemfile CHANGED
@@ -15,4 +15,5 @@ group :test do
15
15
  gem 'autotest-growl'
16
16
  gem 'database_cleaner'
17
17
  gem 'ruby-debug'
18
+ gem 'awesome_print'
18
19
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_job_groups_mongoid}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["opsb"]
@@ -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[:lock_group]}
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
- group_a_job1 = GroupedJob.new(:repository => "repo1")
56
- group_a_job2 = GroupedJob.new(:repository => "repo1")
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
- [group_a_job1, @group_b_job1].each{ |job| Delayed::Job.enqueue job }
60
- queued_job = Delayed::Job.enqueue group_a_job2
61
- queued_job.lock_exclusively!(MAX_RUN_TIME, WORKER)
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 no unlocked jobs" do
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{ Delayed::Job.enqueue GroupedJob.new(:repository => "repo2") }
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 no jobs that are ready to run" do
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 no jobs that are ready to run" do
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
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'bundler/setup'
5
5
  require 'logger'
6
6
  require 'mongoid'
7
+ require 'ap'
7
8
 
8
9
 
9
10
 
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: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - opsb