disquo 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Gemfile.lock +18 -1
- data/disquo.gemspec +2 -1
- data/lib/active_job/queue_adapters/disquo_adapter.rb +56 -0
- data/spec/active_job/queue_adapters/disquo_spec.rb +49 -0
- data/spec/disquo/job_spec.rb +2 -2
- data/spec/disquo/worker_spec.rb +1 -1
- data/spec/spec_helper.rb +17 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 478f669678db9f4b49df090cb601c6d2d4fad7f1
|
4
|
+
data.tar.gz: 62c78605fb663c5a4aea50c07911990e3ac1fac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ded5fc8a2aa03764d1c3cafdf6640d88462ed856515ef30a6c2f8e042889a92890c173873ea98dfc921f28f9909e4822a6262fa4bcdc3d8484257d765f678e14
|
7
|
+
data.tar.gz: 72f521a2a23ebcf6fe226e6fb49c8631d05c983ccabbca92e158280274329e8e7698cd80847a567c8d60e975ada140f9f2448d2ff92803c33a0fb0451d42bf32
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install:
|
3
|
-
- wget https://github.com/antirez/disque/archive/master.tar.gz
|
4
|
-
-
|
3
|
+
- test -d disque-master/src || wget -O- https://github.com/antirez/disque/archive/master.tar.gz | tar xz
|
4
|
+
- cd disque-master/src && make && PREFIX=../ make install && cd -
|
5
5
|
before_script:
|
6
6
|
- ./disque-master/bin/disque-server --daemonize yes
|
7
7
|
script:
|
@@ -9,3 +9,7 @@ script:
|
|
9
9
|
rvm:
|
10
10
|
- 2.4
|
11
11
|
- 2.3
|
12
|
+
cache:
|
13
|
+
bundler: true
|
14
|
+
directories:
|
15
|
+
- disque-master
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
disquo (0.3.
|
4
|
+
disquo (0.3.2)
|
5
5
|
concurrent-ruby
|
6
6
|
connection_pool
|
7
7
|
disque
|
@@ -9,12 +9,25 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
+
activejob (5.1.4)
|
13
|
+
activesupport (= 5.1.4)
|
14
|
+
globalid (>= 0.3.6)
|
15
|
+
activesupport (5.1.4)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
12
20
|
concurrent-ruby (1.0.5)
|
13
21
|
connection_pool (2.2.1)
|
14
22
|
diff-lcs (1.3)
|
15
23
|
disque (0.0.6)
|
16
24
|
redic (~> 1.5.0)
|
25
|
+
globalid (0.4.1)
|
26
|
+
activesupport (>= 4.2.0)
|
17
27
|
hiredis (0.6.1)
|
28
|
+
i18n (0.9.1)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
minitest (5.10.3)
|
18
31
|
rake (12.3.0)
|
19
32
|
redic (1.5.0)
|
20
33
|
hiredis
|
@@ -31,11 +44,15 @@ GEM
|
|
31
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
45
|
rspec-support (~> 3.7.0)
|
33
46
|
rspec-support (3.7.0)
|
47
|
+
thread_safe (0.3.6)
|
48
|
+
tzinfo (1.2.4)
|
49
|
+
thread_safe (~> 0.1)
|
34
50
|
|
35
51
|
PLATFORMS
|
36
52
|
ruby
|
37
53
|
|
38
54
|
DEPENDENCIES
|
55
|
+
activejob
|
39
56
|
disquo!
|
40
57
|
rake
|
41
58
|
rspec
|
data/disquo.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "disquo"
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.2"
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
|
8
8
|
s.licenses = ["Apache-2.0"]
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_development_dependency 'rake'
|
27
27
|
s.add_development_dependency 'rspec'
|
28
|
+
s.add_development_dependency 'activejob'
|
28
29
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "disquo"
|
2
|
+
|
3
|
+
module ActiveJob
|
4
|
+
module QueueAdapters
|
5
|
+
# == Disquo adapter for Active Job
|
6
|
+
#
|
7
|
+
# Read more about Disquo {here}[https://github.com/bsm/disquo].
|
8
|
+
#
|
9
|
+
# To use queue_adapter config to +:disquo+.
|
10
|
+
#
|
11
|
+
# require 'active_job/queue_adapters/disquo_adapter'
|
12
|
+
#
|
13
|
+
# Rails.application.config.active_job.queue_adapter = :disquo
|
14
|
+
#
|
15
|
+
# To pass extra options into the job, you can use custom serialization:
|
16
|
+
#
|
17
|
+
# class MyJob < ActiveJob::Base
|
18
|
+
# def serialize
|
19
|
+
# opts = { 'ttl' => 1.hour, 'async' => true }
|
20
|
+
# super.merge('disquo' => opts)
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
class DisquoAdapter
|
24
|
+
|
25
|
+
class JobWrapper #:nodoc:
|
26
|
+
include Disquo::Job
|
27
|
+
|
28
|
+
def perform(job_data)
|
29
|
+
ActiveJob::Base.execute job_data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def enqueue(job) #:nodoc:
|
34
|
+
enqueue_with_opts job
|
35
|
+
end
|
36
|
+
|
37
|
+
def enqueue_at(job, timestamp) #:nodoc:
|
38
|
+
delay = timestamp - Time.current.to_f
|
39
|
+
enqueue_with_opts job, delay: delay.to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def enqueue_with_opts(job, opts = {})
|
45
|
+
attrs = job.serialize
|
46
|
+
opts.update attrs["disquo"].symbolize_keys if attrs["disquo"].is_a?(Hash)
|
47
|
+
opts[:queue] = job.queue_name
|
48
|
+
|
49
|
+
job_id = JobWrapper.enqueue [attrs], opts
|
50
|
+
job.provider_job_id = job_id
|
51
|
+
job_id
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActiveJob::QueueAdapters::DisquoAdapter do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
TestActiveJob.set(wait: 60).perform_later("foo", 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:job_data) { show(subject.provider_job_id) }
|
10
|
+
|
11
|
+
it "should enqueue" do
|
12
|
+
expect(job_data).to include(
|
13
|
+
"additional-deliveries" => 0,
|
14
|
+
"id" => subject.provider_job_id,
|
15
|
+
"nacks" => 0,
|
16
|
+
"queue" => "__disquo_test__",
|
17
|
+
"state" => "active",
|
18
|
+
)
|
19
|
+
expect(job_data["delay"]).to be_within(5).of(60)
|
20
|
+
expect(job_data["retry"]).to be_within(5).of(360)
|
21
|
+
expect(job_data["ttl"]).to be_within(5).of(3600)
|
22
|
+
expect(Disquo.load_job(job_data["body"])).to eq([
|
23
|
+
"ActiveJob::QueueAdapters::DisquoAdapter::JobWrapper",
|
24
|
+
[{
|
25
|
+
"job_class" => "TestActiveJob",
|
26
|
+
"job_id" => subject.job_id,
|
27
|
+
"provider_job_id" => nil,
|
28
|
+
"queue_name" => "__disquo_test__",
|
29
|
+
"priority" => nil,
|
30
|
+
"arguments" => ["foo", 1],
|
31
|
+
"executions" => 0,
|
32
|
+
"locale" => "en",
|
33
|
+
"disquo" => {"ttl" => 3600},
|
34
|
+
}],
|
35
|
+
])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should perform' do
|
39
|
+
klass, args = Disquo.load_job(job_data["body"])
|
40
|
+
Object.const_get(klass).new.perform(*args)
|
41
|
+
|
42
|
+
expect(Disquo::TEST::PERFORMED.size).to eq(1)
|
43
|
+
expect(Disquo::TEST::PERFORMED.last).to include(
|
44
|
+
klass: "TestActiveJob",
|
45
|
+
args: ["foo", 1],
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/disquo/job_spec.rb
CHANGED
@@ -5,7 +5,7 @@ RSpec.describe Disquo::Job do
|
|
5
5
|
it "should enqueue jobs" do
|
6
6
|
jid1 = TestJob.enqueue ["foo", 1]
|
7
7
|
expect(qlen).to eq(1)
|
8
|
-
expect(jid1).to match(/^D\w+/)
|
8
|
+
expect(jid1).to match(/^D[\w\-]+/)
|
9
9
|
expect(show(jid1)).to include(
|
10
10
|
"id" => jid1,
|
11
11
|
"queue" => "__disquo_test__",
|
@@ -18,7 +18,7 @@ RSpec.describe Disquo::Job do
|
|
18
18
|
|
19
19
|
jid2 = TestJob.enqueue ["bar"], delay: 600
|
20
20
|
expect(qlen).to eq(1)
|
21
|
-
expect(jid2).to match(/^D\w+/)
|
21
|
+
expect(jid2).to match(/^D[\w\-]+/)
|
22
22
|
expect(show(jid2)).to include(
|
23
23
|
"id" => jid2,
|
24
24
|
"queue" => "__disquo_test__",
|
data/spec/disquo/worker_spec.rb
CHANGED
@@ -33,7 +33,7 @@ RSpec.describe Disquo::Worker do
|
|
33
33
|
klass: "TestJob",
|
34
34
|
queue: "__disquo_test__",
|
35
35
|
)
|
36
|
-
expect(Disquo::TEST::PERFORMED.last[:job_id]).to match(/^D\w+/)
|
36
|
+
expect(Disquo::TEST::PERFORMED.last[:job_id]).to match(/^D[\w\-]+/)
|
37
37
|
expect(Disquo::TEST::PERFORMED.map {|e| e[:args].first }).to match_array(0..199)
|
38
38
|
end
|
39
39
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,11 @@ require 'rspec'
|
|
2
2
|
require 'disquo'
|
3
3
|
require 'disquo/worker'
|
4
4
|
|
5
|
+
require 'active_job'
|
6
|
+
require 'active_job/queue_adapters/disquo_adapter'
|
7
|
+
ActiveJob::Base.queue_adapter = :disquo
|
8
|
+
ActiveJob::Base.logger = Logger.new(nil)
|
9
|
+
|
5
10
|
module Disquo::TEST
|
6
11
|
QUEUE = "__disquo_test__"
|
7
12
|
PERFORMED = []
|
@@ -17,6 +22,18 @@ class TestJob
|
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
25
|
+
class TestActiveJob < ActiveJob::Base
|
26
|
+
queue_as Disquo::TEST::QUEUE
|
27
|
+
|
28
|
+
def perform(*args)
|
29
|
+
Disquo::TEST::PERFORMED.push(klass: self.class.name, args: args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def serialize
|
33
|
+
super.merge('disquo' => {'ttl' => 3600})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
20
37
|
helpers = Module.new do
|
21
38
|
|
22
39
|
def qlen
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disquo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: disque
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activejob
|
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'
|
83
97
|
description: Concurrent background workers on top of Disque
|
84
98
|
email: dimitrij@blacksquaremedia.com
|
85
99
|
executables:
|
@@ -96,10 +110,12 @@ files:
|
|
96
110
|
- Rakefile
|
97
111
|
- bin/disquo
|
98
112
|
- disquo.gemspec
|
113
|
+
- lib/active_job/queue_adapters/disquo_adapter.rb
|
99
114
|
- lib/disquo.rb
|
100
115
|
- lib/disquo/cli.rb
|
101
116
|
- lib/disquo/job.rb
|
102
117
|
- lib/disquo/worker.rb
|
118
|
+
- spec/active_job/queue_adapters/disquo_spec.rb
|
103
119
|
- spec/disquo/job_spec.rb
|
104
120
|
- spec/disquo/worker_spec.rb
|
105
121
|
- spec/spec_helper.rb
|
@@ -128,6 +144,7 @@ signing_key:
|
|
128
144
|
specification_version: 4
|
129
145
|
summary: Concurrent background workers on top of Disque
|
130
146
|
test_files:
|
147
|
+
- spec/active_job/queue_adapters/disquo_spec.rb
|
131
148
|
- spec/disquo/job_spec.rb
|
132
149
|
- spec/disquo/worker_spec.rb
|
133
150
|
- spec/spec_helper.rb
|