line_up 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 893ebb96aa6db1f8b61b41954630d0f3a7922da6
4
- data.tar.gz: 82cd227d22fd25c02785675164a263fefd841ba1
2
+ SHA256:
3
+ metadata.gz: ce18ce8d73e695503b1817970a0f7c134a716f9bfc6c040e0572f9ef5df9a26f
4
+ data.tar.gz: b6ffe2e2f83caef827038c9b2d0015a0c9561f03f711ba008105116605d6560c
5
5
  SHA512:
6
- metadata.gz: 010f5577b11b26d98d93c7dedd378cbc196525a1b300cfcaed0834f62fe591a29aa044f60cc3210de4478fb45c3ff8e1932fe33cc00d8dff3f919ad3a1ef5e28
7
- data.tar.gz: 46c76b54b0932de54d07828a0ffb1c0b260a07e5b0132cee83c28b745adebe378fb5ace719944c13ab27cb17044b62ef4ca1c7af398231759f0f82ccc327d5cd
6
+ metadata.gz: 278311aa84959ea1d7fd8148c273eef5420494699070a9dd80ec42498d27ab2157ea63c5a73b436d016b0e7a3e38082e3ab11d3b0a18e65a937d8de2c13901e3
7
+ data.tar.gz: 9fcd63dd92472f090fe8e168b36442daf14cd673d617ea2aa2c4d8f5a75989256594776d633d9c2c464e007d8bc9c5fa1d746888b220f99f2b4d407e414f5627
data/README.md CHANGED
@@ -41,11 +41,7 @@ With the setup above, Resque lies in the `myapp:resque`-namespace. So you can en
41
41
  This is how you can enqueue a job for another applications:
42
42
 
43
43
  ```ruby
44
- if LineUp.push :otherApp, :SomeJob, 12345, some: thing
45
- # Yey, everything went well
46
- else
47
- # The "Trouble"-gem, has been notified and I can process the failure if I like
48
- end
44
+ LineUp.push :otherApp, :SomeJob, 12345, some: thing
49
45
  ```
50
46
 
51
47
  This will enqueue to `other_app:resque:some_job` with arguments `[12345, { 'some' => 'thing' }]` and make sure that the `other_app:resque:queues` Set references the queue List.
@@ -2,7 +2,7 @@ module LineUp
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
data/lib/line_up.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'trouble'
2
-
3
1
  require 'line_up/configuration'
4
2
  require 'line_up/job'
5
3
 
@@ -13,10 +11,6 @@ module LineUp
13
11
  redis.rpush "queue:#{job.queue_name}", job.encode
14
12
  end
15
13
  log caller, application, jobclass, *args
16
- true
17
- rescue Exception => exception
18
- Trouble.notify exception, caller: caller[1], message: "LineUp could not enqueue a Job", code: :enqueue_failed, redis: config.redis.inspect, application: application.inspect, job: jobclass.inspect, args: args.inspect
19
- false
20
14
  end
21
15
 
22
16
  def self.ensure(application, jobclass, *args)
@@ -25,39 +19,15 @@ module LineUp
25
19
  end
26
20
  end
27
21
 
28
- def self.push_throttled(application, jobclass, *args)
29
- job = Job.new jobclass, *args
30
- unless recent? application, job
31
- push(application, jobclass, *args)
32
- recent! application, job
33
- end
34
- end
35
-
36
22
  def self.queue_length(application, jobclass)
37
23
  redis_for application do |r|
38
24
  job = Job.new jobclass
39
25
  return r.llen "queue:#{job.queue_name}"
40
26
  end
41
- rescue Exception => e
42
- 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
43
- false
44
27
  end
45
28
 
46
29
  private
47
30
 
48
- def self.recent?(application, job)
49
- redis_for application do |r|
50
- return true if r.exists "throttled:#{job.checksum}"
51
- end
52
- false
53
- end
54
-
55
- def self.recent!(application, job)
56
- redis_for application do |r|
57
- r.setex "throttled:#{job.checksum}", config.recency_ttl, "true"
58
- end
59
- end
60
-
61
31
  def self.redis_for(application, &block)
62
32
  config.redis.namespace [StringExtensions.underscore(application), :resque].compact.join(':'), &block
63
33
  end
@@ -66,5 +36,4 @@ module LineUp
66
36
  return unless config.logger
67
37
  config.logger.debug "LINEUP ENQUEUED JOB #{jobclass.inspect} for #{application.inspect} at #{caller.first} with arguments #{args.inspect}"
68
38
  end
69
-
70
39
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe LineUp do
4
4
 
5
- let(:logger) { mock(:logger) }
6
-
5
+ let(:rails) { Module.new }
6
+ let(:logger) { double(:logger) }
7
7
  let(:lineup) { LineUp }
8
8
 
9
9
  describe '.config' do
@@ -12,22 +12,18 @@ describe LineUp do
12
12
  end
13
13
 
14
14
  it 'is an STDOUT logger' do
15
- Logger.should_receive(:new).with(STDOUT).and_return logger
16
- lineup.config.logger.should be logger
15
+ expect(Logger).to receive(:new).with(STDOUT).and_return logger
16
+ expect(lineup.config.logger).to eq(logger)
17
17
  end
18
18
 
19
19
  context 'with Rails' do
20
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)
21
+ allow(rails).to receive(:logger).and_return(logger)
22
+ stub_const("Rails", rails)
27
23
  end
28
24
 
29
25
  it 'is the Rails logger' do
30
- lineup.config.logger.should be Rails.logger
26
+ expect(lineup.config.logger).to eq(Rails.logger)
31
27
  end
32
28
  end
33
29
  end
@@ -6,26 +6,22 @@ describe LineUp do
6
6
  let(:job) { :SendEmail }
7
7
  let(:args) { [123, some: :thing] }
8
8
  let(:redis) { $raw_redis }
9
- let(:logger) { mock(:logger) }
9
+ let(:logger) { double(:logger) }
10
10
  let(:lineup_job) { LineUp::Job.new job, *args }
11
11
 
12
12
  let(:lineup) { LineUp }
13
13
 
14
14
  describe '.push' do
15
- it 'returns true if successful' do
16
- lineup.push(application, job, *args).should be_true
17
- end
18
-
19
15
  it 'registers the queue' do
20
16
  lineup.push application, job, *args
21
- queues = redis.smembers('other_app:resque:queues').should == %w{ send_email }
17
+ expect(redis.smembers('other_app:resque:queues')).to eq(%w{ send_email })
22
18
  end
23
19
 
24
20
  it 'enqueues the job' do
25
21
  lineup.push application, job, *args
26
22
  jobs = redis.lrange('other_app:resque:queue:send_email', 0, -1)
27
- jobs.size.should == 1
28
- MultiJson.load(jobs.first).should == { 'class' => 'SendEmail', 'args' => [123, 'some' => 'thing'] }
23
+ expect(jobs.size).to eq(1)
24
+ expect(MultiJson.load(jobs.first)).to eq({ 'class' => 'SendEmail', 'args' => [123, 'some' => 'thing'] })
29
25
  end
30
26
 
31
27
  context 'with a Logger' do
@@ -34,120 +30,36 @@ describe LineUp do
34
30
  end
35
31
 
36
32
  it 'logs the enqueueing and returns true' do
37
- logger.should_receive(:debug) do |string|
38
- string.should include('LINEUP ENQUEUED')
39
- string.should include('line_up_spec.rb')
40
- string.should include(':otherApp')
41
- string.should include(':SendEmail')
42
- string.should include('[123, {:some=>:thing}]')
43
- end
44
- lineup.push(application, job, *args).should be_true
45
- end
46
- end
47
-
48
- context 'when the key for the Queue Set is occupied by the wrong data format' do
49
- before do
50
- redis.set 'other_app:resque:queues', :anything_but_a_list
51
- end
52
-
53
- it 'catches the error and returns false' do
54
- Trouble.should_receive(:notify) do |exception, metadata|
55
- exception.should be_instance_of Redis::CommandError
56
- metadata[:code].should == :enqueue_failed
57
- metadata[:application].should == ':otherApp'
58
- metadata[:job].should == ':SendEmail'
59
- metadata[:args].should == '[123, {:some=>:thing}]'
60
- metadata[:caller].should include('line_up_spec.rb')
33
+ expect(logger).to receive(:debug) do |string|
34
+ expect(string).to include('LINEUP ENQUEUED')
35
+ expect(string).to include('line_up_spec.rb')
36
+ expect(string).to include(':otherApp')
37
+ expect(string).to include(':SendEmail')
38
+ expect(string).to include('[123, {:some=>:thing}]')
61
39
  end
62
- lineup.push(application, job, *args).should be_false
63
- end
64
- end
65
-
66
- context 'when the key for the List Job Queue is occupied by the wrong data format' do
67
- before do
68
- redis.set 'other_app:resque:queue:send_email', :anything_but_a_list
69
- end
70
-
71
- it 'catches the error and returns false' do
72
- Trouble.should_receive(:notify) do |exception, metadata|
73
- exception.should be_instance_of Redis::CommandError
74
- metadata[:code].should == :enqueue_failed
75
- metadata[:application].should == ':otherApp'
76
- metadata[:job].should == ':SendEmail'
77
- metadata[:args].should == '[123, {:some=>:thing}]'
78
- metadata[:caller].should include('line_up_spec.rb')
79
- end
80
- lineup.push(application, job, *args).should be_false
40
+ lineup.push application, job, *args
81
41
  end
82
42
  end
83
43
  end
84
44
 
85
45
  describe ".queue_length" do
86
-
87
46
  it "returns the length of the given queue in the given application" do
88
47
  lineup.push(application, job, 1)
89
48
  lineup.push(application, job, 2)
90
- lineup.queue_length(application, job).should == 2
91
- end
92
-
93
- context 'when the key for the List Job Queue is occupied by the wrong data format' do
94
- before do
95
- redis.set 'other_app:resque:queue:send_email', :anything_but_a_list
96
- end
97
-
98
- it 'logs the error' do
99
- Trouble.should_receive(:notify) do |exception, metadata|
100
- exception.should be_instance_of Redis::CommandError
101
- metadata[:code].should == :getting_queue_length_failed
102
- metadata[:application].should == ':otherApp'
103
- metadata[:job].should == ':SendEmail'
104
- metadata[:caller].should include('line_up_spec.rb')
105
- end
106
- lineup.queue_length(application, job)
107
- end
108
-
109
- it "returns false" do
110
- lineup.queue_length(application, job).should be_false
111
- end
49
+ expect(lineup.queue_length(application, job)).to eq(2)
112
50
  end
113
51
  end
114
52
 
115
53
  describe ".ensure" do
116
-
117
54
  it "pushes the job if the queue is empty" do
118
- lineup.should_receive(:push).with(application, job, *args)
55
+ expect(lineup).to receive(:push).with(application, job, *args)
119
56
  lineup.ensure application, job, *args
120
57
  end
121
58
 
122
59
  it "does not push the job if the queue already has a job with the same name" do
123
60
  lineup.push application, job, *args
124
- lineup.should_not_receive(:push)
61
+ expect(lineup).not_to receive(:push)
125
62
  lineup.ensure application, job, *args
126
63
  end
127
64
  end
128
-
129
- describe ".push_throttled" do
130
-
131
- it "pushes same consecutive job just once" do
132
- lineup.should_receive(:push).once
133
- lineup.push_throttled application, job, *args
134
- lineup.push_throttled application, job, *args
135
- end
136
-
137
- it "pushes again when previous identical job has expired" do
138
- lineup.should_receive(:push).twice
139
-
140
- lineup.push_throttled application, job, *args
141
- redis.del "other_app:resque:throttled:#{lineup_job.checksum}"
142
- lineup.push_throttled application, job, *args
143
- end
144
-
145
- it "stores throttle with configured ttl" do
146
- lineup.push_throttled application, job, *args
147
- ttl = redis.ttl "other_app:resque:throttled:#{lineup_job.checksum}"
148
- ttl.should == lineup.config.recency_ttl
149
- end
150
-
151
- end
152
-
153
65
  end
data/spec/spec_helper.rb CHANGED
@@ -1,40 +1,16 @@
1
1
  require 'redis-namespace'
2
2
  require 'line_up'
3
3
 
4
- def ensure_class_or_module(full_name, class_or_module)
5
- full_name.to_s.split(/::/).inject(Object) do |context, name|
6
- begin
7
- context.const_get(name)
8
- rescue NameError
9
- if class_or_module == :class
10
- context.const_set(name, Class.new)
11
- else
12
- context.const_set(name, Module.new)
13
- end
14
- end
15
- end
16
- end
17
-
18
- def ensure_module(name)
19
- ensure_class_or_module(name, :module)
20
- end
21
-
22
- def ensure_class(name)
23
- ensure_class_or_module(name, :class)
24
- end
25
-
26
4
  RSpec.configure do |config|
27
5
 
28
6
  config.before do
29
7
  $raw_redis = Redis.new(db: 14)
30
8
  LineUp.config.redis = Redis::Namespace.new :myapp, redis: $raw_redis
31
9
  LineUp.config.logger = nil
32
- Trouble.stub!(:notify)
33
10
  end
34
11
 
35
12
  config.after do
36
13
  $raw_redis.flushdb
37
14
  LineUp.reset!
38
15
  end
39
-
40
16
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bukowskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: trouble
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: multi_json
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -66,34 +52,6 @@ dependencies:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rb-fsevent
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
55
  description: No more need to maintain two separate redis connections when using namespaces.
98
56
  LineUp does not even need Resque itself.
99
57
  email:
@@ -132,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
90
  - !ruby/object:Gem::Version
133
91
  version: '0'
134
92
  requirements: []
135
- rubyforge_project:
136
- rubygems_version: 2.2.2
93
+ rubygems_version: 3.0.3.1
137
94
  signing_key:
138
95
  specification_version: 4
139
96
  summary: Enqueue Resque Jobs directly via Redis so that you can choose the namespace