line_up 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/bukowskis/line_up.png)](https://travis-ci.org/bukowskis/line_up)
2
+
1
3
  # LineUp
2
4
 
3
5
  With LineUp you can enqueue Resque jobs in arbitrary Redis namespaces.
@@ -1,8 +1,8 @@
1
1
  module LineUp
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 3
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
data/lib/line_up.rb CHANGED
@@ -19,6 +19,22 @@ module LineUp
19
19
  false
20
20
  end
21
21
 
22
+ def self.ensure(application, jobclass, *args)
23
+ if queue_length(application, jobclass) == 0
24
+ push(application, jobclass, *args)
25
+ end
26
+ end
27
+
28
+ def self.queue_length(application, jobclass)
29
+ redis_for application do |r|
30
+ job = Job.new jobclass
31
+ return r.llen "queue:#{job.queue_name}"
32
+ end
33
+ rescue Exception => e
34
+ Trouble.notify e, caller: caller[1], message: "LineUp could not get the queue length", code: :getting_queue_length_failed, redis: config.redis.inspect, application: application.inspect, job: jobclass.inspect
35
+ false
36
+ end
37
+
22
38
  private
23
39
 
24
40
  def self.redis_for(application, &block)
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe LineUp do
4
+
5
+ let(:logger) { mock(:logger) }
6
+
7
+ let(:lineup) { LineUp }
8
+
9
+ describe '.config' do
10
+ before do
11
+ LineUp.reset!
12
+ end
13
+
14
+ it 'is an STDOUT logger' do
15
+ Logger.should_receive(:new).with(STDOUT).and_return logger
16
+ lineup.config.logger.should be logger
17
+ end
18
+
19
+ context 'with Rails' do
20
+ before do
21
+ ensure_module :Rails
22
+ Rails.stub!(:logger).and_return(logger)
23
+ end
24
+
25
+ after do
26
+ Object.send(:remove_const, :Rails)
27
+ end
28
+
29
+ it 'is the Rails logger' do
30
+ lineup.config.logger.should be Rails.logger
31
+ end
32
+ end
33
+ end
34
+ end
@@ -81,26 +81,47 @@ describe LineUp do
81
81
  end
82
82
  end
83
83
 
84
- describe '.config' do
85
- before do
86
- LineUp.reset!
87
- end
84
+ describe ".queue_length" do
88
85
 
89
- it 'is an STDOUT logger' do
90
- Logger.should_receive(:new).with(STDOUT).and_return logger
91
- lineup.config.logger.should be logger
86
+ it "returns the length of the given queue in the given application" do
87
+ lineup.push(application, job, 1)
88
+ lineup.push(application, job, 2)
89
+ lineup.queue_length(application, job).should == 2
92
90
  end
93
91
 
94
- context 'with Rails' do
92
+ context 'when the key for the List Job Queue is occupied by the wrong data format' do
95
93
  before do
96
- ensure_module :Rails
97
- Rails.stub!(:logger).and_return(logger)
94
+ redis.set 'other_app:resque:queue:send_email', :anything_but_a_list
98
95
  end
99
96
 
100
- it 'is the Rails logger' do
101
- lineup.config.logger.should be Rails.logger
97
+ it 'logs the error' do
98
+ Trouble.should_receive(:notify) do |exception, metadata|
99
+ exception.should be_instance_of Redis::CommandError
100
+ metadata[:code].should == :getting_queue_length_failed
101
+ metadata[:application].should == ':otherApp'
102
+ metadata[:job].should == ':SendEmail'
103
+ metadata[:caller].should include('line_up_spec.rb')
104
+ end
105
+ lineup.queue_length(application, job)
106
+ end
107
+
108
+ it "returns false" do
109
+ lineup.queue_length(application, job).should be_false
102
110
  end
103
111
  end
104
112
  end
105
113
 
114
+ describe ".ensure" do
115
+
116
+ it "pushes the job if the queue is empty" do
117
+ lineup.should_receive(:push).with(application, job, *args)
118
+ lineup.ensure application, job, *args
119
+ end
120
+
121
+ it "does not push the job if the queue already has a job with the same name" do
122
+ lineup.push application, job, *args
123
+ lineup.should_not_receive(:push)
124
+ lineup.ensure application, job, *args
125
+ end
126
+ end
106
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trouble
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 1.3.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.3.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ files:
119
119
  - lib/line_up/string_extensions.rb
120
120
  - lib/line_up/version.rb
121
121
  - lib/line_up.rb
122
+ - spec/lib/line_up/configuration_spec.rb
122
123
  - spec/lib/line_up_spec.rb
123
124
  - spec/spec_helper.rb
124
125
  - README.md