line_up 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -5
- data/lib/line_up/configuration.rb +9 -3
- data/lib/line_up/job.rb +5 -0
- data/lib/line_up/version.rb +1 -1
- data/lib/line_up.rb +0 -10
- data/spec/lib/line_up/configuration_spec.rb +7 -11
- data/spec/lib/line_up_spec.rb +15 -77
- data/spec/spec_helper.rb +0 -24
- metadata +22 -79
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce18ce8d73e695503b1817970a0f7c134a716f9bfc6c040e0572f9ef5df9a26f
|
4
|
+
data.tar.gz: b6ffe2e2f83caef827038c9b2d0015a0c9561f03f711ba008105116605d6560c
|
5
|
+
SHA512:
|
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
|
-
|
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,11 +2,12 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module LineUp
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :logger, :redis
|
5
|
+
attr_accessor :logger, :redis, :recency_ttl
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@logger
|
9
|
-
@redis
|
8
|
+
@logger = options[:logger] || default_logger
|
9
|
+
@redis = options[:redis] || default_redis
|
10
|
+
@recency_ttl = options[:recency_ttl] || default_recency_ttl
|
10
11
|
end
|
11
12
|
|
12
13
|
private
|
@@ -24,6 +25,11 @@ module LineUp
|
|
24
25
|
return Resque.redis if defined?(Resque)
|
25
26
|
Redis::Namespace.new nil
|
26
27
|
end
|
28
|
+
|
29
|
+
def default_recency_ttl
|
30
|
+
5
|
31
|
+
end
|
32
|
+
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
data/lib/line_up/job.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'line_up/string_extensions'
|
2
2
|
require 'multi_json'
|
3
|
+
require 'digest/sha1'
|
3
4
|
|
4
5
|
module LineUp
|
5
6
|
class Job
|
@@ -11,6 +12,10 @@ module LineUp
|
|
11
12
|
@args = args
|
12
13
|
end
|
13
14
|
|
15
|
+
def checksum
|
16
|
+
Digest::SHA1.hexdigest(encode)
|
17
|
+
end
|
18
|
+
|
14
19
|
def encode
|
15
20
|
MultiJson.dump class: klass.to_s, args: args
|
16
21
|
end
|
data/lib/line_up/version.rb
CHANGED
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)
|
@@ -30,9 +24,6 @@ module LineUp
|
|
30
24
|
job = Job.new jobclass
|
31
25
|
return r.llen "queue:#{job.queue_name}"
|
32
26
|
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
27
|
end
|
37
28
|
|
38
29
|
private
|
@@ -45,5 +36,4 @@ module LineUp
|
|
45
36
|
return unless config.logger
|
46
37
|
config.logger.debug "LINEUP ENQUEUED JOB #{jobclass.inspect} for #{application.inspect} at #{caller.first} with arguments #{args.inspect}"
|
47
38
|
end
|
48
|
-
|
49
39
|
end
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LineUp do
|
4
4
|
|
5
|
-
let(:
|
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.
|
16
|
-
lineup.config.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
|
-
|
22
|
-
Rails
|
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.
|
26
|
+
expect(lineup.config.logger).to eq(Rails.logger)
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
data/spec/lib/line_up_spec.rb
CHANGED
@@ -6,25 +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) {
|
9
|
+
let(:logger) { double(:logger) }
|
10
|
+
let(:lineup_job) { LineUp::Job.new job, *args }
|
10
11
|
|
11
12
|
let(:lineup) { LineUp }
|
12
13
|
|
13
14
|
describe '.push' do
|
14
|
-
it 'returns true if successful' do
|
15
|
-
lineup.push(application, job, *args).should be_true
|
16
|
-
end
|
17
|
-
|
18
15
|
it 'registers the queue' do
|
19
16
|
lineup.push application, job, *args
|
20
|
-
|
17
|
+
expect(redis.smembers('other_app:resque:queues')).to eq(%w{ send_email })
|
21
18
|
end
|
22
19
|
|
23
20
|
it 'enqueues the job' do
|
24
21
|
lineup.push application, job, *args
|
25
22
|
jobs = redis.lrange('other_app:resque:queue:send_email', 0, -1)
|
26
|
-
jobs.size.
|
27
|
-
MultiJson.load(jobs.first).
|
23
|
+
expect(jobs.size).to eq(1)
|
24
|
+
expect(MultiJson.load(jobs.first)).to eq({ 'class' => 'SendEmail', 'args' => [123, 'some' => 'thing'] })
|
28
25
|
end
|
29
26
|
|
30
27
|
context 'with a Logger' do
|
@@ -33,94 +30,35 @@ describe LineUp do
|
|
33
30
|
end
|
34
31
|
|
35
32
|
it 'logs the enqueueing and returns true' do
|
36
|
-
logger.
|
37
|
-
string.
|
38
|
-
string.
|
39
|
-
string.
|
40
|
-
string.
|
41
|
-
string.
|
42
|
-
end
|
43
|
-
lineup.push(application, job, *args).should be_true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when the key for the Queue Set is occupied by the wrong data format' do
|
48
|
-
before do
|
49
|
-
redis.set 'other_app:resque:queues', :anything_but_a_list
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'catches the error and returns false' do
|
53
|
-
Trouble.should_receive(:notify) do |exception, metadata|
|
54
|
-
exception.should be_instance_of Redis::CommandError
|
55
|
-
metadata[:code].should == :enqueue_failed
|
56
|
-
metadata[:application].should == ':otherApp'
|
57
|
-
metadata[:job].should == ':SendEmail'
|
58
|
-
metadata[:args].should == '[123, {:some=>:thing}]'
|
59
|
-
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}]')
|
60
39
|
end
|
61
|
-
lineup.push
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'when the key for the List Job Queue is occupied by the wrong data format' do
|
66
|
-
before do
|
67
|
-
redis.set 'other_app:resque:queue:send_email', :anything_but_a_list
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'catches the error and returns false' do
|
71
|
-
Trouble.should_receive(:notify) do |exception, metadata|
|
72
|
-
exception.should be_instance_of Redis::CommandError
|
73
|
-
metadata[:code].should == :enqueue_failed
|
74
|
-
metadata[:application].should == ':otherApp'
|
75
|
-
metadata[:job].should == ':SendEmail'
|
76
|
-
metadata[:args].should == '[123, {:some=>:thing}]'
|
77
|
-
metadata[:caller].should include('line_up_spec.rb')
|
78
|
-
end
|
79
|
-
lineup.push(application, job, *args).should be_false
|
40
|
+
lineup.push application, job, *args
|
80
41
|
end
|
81
42
|
end
|
82
43
|
end
|
83
44
|
|
84
45
|
describe ".queue_length" do
|
85
|
-
|
86
46
|
it "returns the length of the given queue in the given application" do
|
87
47
|
lineup.push(application, job, 1)
|
88
48
|
lineup.push(application, job, 2)
|
89
|
-
lineup.queue_length(application, job).
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when the key for the List Job Queue is occupied by the wrong data format' do
|
93
|
-
before do
|
94
|
-
redis.set 'other_app:resque:queue:send_email', :anything_but_a_list
|
95
|
-
end
|
96
|
-
|
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
|
110
|
-
end
|
49
|
+
expect(lineup.queue_length(application, job)).to eq(2)
|
111
50
|
end
|
112
51
|
end
|
113
52
|
|
114
53
|
describe ".ensure" do
|
115
|
-
|
116
54
|
it "pushes the job if the queue is empty" do
|
117
|
-
lineup.
|
55
|
+
expect(lineup).to receive(:push).with(application, job, *args)
|
118
56
|
lineup.ensure application, job, *args
|
119
57
|
end
|
120
58
|
|
121
59
|
it "does not push the job if the queue already has a job with the same name" do
|
122
60
|
lineup.push application, job, *args
|
123
|
-
lineup.
|
61
|
+
expect(lineup).not_to receive(:push)
|
124
62
|
lineup.ensure application, job, *args
|
125
63
|
end
|
126
64
|
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,112 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: line_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.1
|
4
|
+
version: 0.1.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- bukowskis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2023-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - ! '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
none: false
|
21
|
-
name: trouble
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
14
|
+
name: multi_json
|
24
15
|
requirement: !ruby/object:Gem::Requirement
|
25
16
|
requirements:
|
26
|
-
- -
|
17
|
+
- - ">="
|
27
18
|
- !ruby/object:Gem::Version
|
28
19
|
version: '0'
|
29
|
-
none: false
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
version_requirements: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ! '>='
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
none: false
|
37
|
-
name: multi_json
|
38
20
|
type: :runtime
|
39
21
|
prerelease: false
|
40
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
23
|
requirements:
|
42
|
-
- -
|
24
|
+
- - ">="
|
43
25
|
- !ruby/object:Gem::Version
|
44
26
|
version: '0'
|
45
|
-
none: false
|
46
27
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
28
|
+
name: redis-namespace
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
48
30
|
requirements:
|
49
|
-
- -
|
31
|
+
- - ">="
|
50
32
|
- !ruby/object:Gem::Version
|
51
33
|
version: 1.3.0
|
52
|
-
none: false
|
53
|
-
name: redis-namespace
|
54
34
|
type: :runtime
|
55
35
|
prerelease: false
|
56
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
37
|
requirements:
|
58
|
-
- -
|
38
|
+
- - ">="
|
59
39
|
- !ruby/object:Gem::Version
|
60
40
|
version: 1.3.0
|
61
|
-
none: false
|
62
41
|
- !ruby/object:Gem::Dependency
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ! '>='
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
none: false
|
69
42
|
name: rspec
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
43
|
requirement: !ruby/object:Gem::Requirement
|
73
44
|
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
none: false
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ! '>='
|
45
|
+
- - ">="
|
82
46
|
- !ruby/object:Gem::Version
|
83
47
|
version: '0'
|
84
|
-
none: false
|
85
|
-
name: guard-rspec
|
86
48
|
type: :development
|
87
49
|
prerelease: false
|
88
|
-
requirement: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - ! '>='
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '0'
|
93
|
-
none: false
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
50
|
version_requirements: !ruby/object:Gem::Requirement
|
96
51
|
requirements:
|
97
|
-
- -
|
52
|
+
- - ">="
|
98
53
|
- !ruby/object:Gem::Version
|
99
54
|
version: '0'
|
100
|
-
none: false
|
101
|
-
name: rb-fsevent
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
requirement: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - ! '>='
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
109
|
-
none: false
|
110
55
|
description: No more need to maintain two separate redis connections when using namespaces.
|
111
56
|
LineUp does not even need Resque itself.
|
112
57
|
email:
|
@@ -114,42 +59,40 @@ executables: []
|
|
114
59
|
extensions: []
|
115
60
|
extra_rdoc_files: []
|
116
61
|
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/line_up.rb
|
117
65
|
- lib/line_up/configuration.rb
|
118
66
|
- lib/line_up/job.rb
|
119
67
|
- lib/line_up/string_extensions.rb
|
120
68
|
- lib/line_up/version.rb
|
121
|
-
- lib/line_up.rb
|
122
69
|
- spec/lib/line_up/configuration_spec.rb
|
123
70
|
- spec/lib/line_up_spec.rb
|
124
71
|
- spec/spec_helper.rb
|
125
|
-
- README.md
|
126
|
-
- LICENSE
|
127
72
|
homepage: https://github.com/bukowskis/line_up
|
128
73
|
licenses:
|
129
74
|
- MIT
|
75
|
+
metadata: {}
|
130
76
|
post_install_message:
|
131
77
|
rdoc_options:
|
132
|
-
- --encoding
|
78
|
+
- "--encoding"
|
133
79
|
- UTF-8
|
134
80
|
require_paths:
|
135
81
|
- lib
|
136
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
83
|
requirements:
|
138
|
-
- -
|
84
|
+
- - ">="
|
139
85
|
- !ruby/object:Gem::Version
|
140
86
|
version: '0'
|
141
|
-
none: false
|
142
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
88
|
requirements:
|
144
|
-
- -
|
89
|
+
- - ">="
|
145
90
|
- !ruby/object:Gem::Version
|
146
91
|
version: '0'
|
147
|
-
none: false
|
148
92
|
requirements: []
|
149
|
-
|
150
|
-
rubygems_version: 1.8.23
|
93
|
+
rubygems_version: 3.0.3.1
|
151
94
|
signing_key:
|
152
|
-
specification_version:
|
95
|
+
specification_version: 4
|
153
96
|
summary: Enqueue Resque Jobs directly via Redis so that you can choose the namespace
|
154
97
|
yourself
|
155
98
|
test_files: []
|