qe 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +43 -35
- data/README.md +13 -1
- data/lib/qe/immediate.rb +4 -0
- data/lib/qe/testing.rb +5 -1
- data/lib/qe/testing/rspec.rb +44 -5
- data/lib/qe/version.rb +1 -1
- data/lib/qe/worker/class_methods.rb +1 -1
- data/spec/qe/immediate_spec.rb +10 -0
- data/spec/qe/matchers_spec.rb +49 -0
- data/spec/qe/testing_spec.rb +21 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6884801104bf918f5ebc6178ff92c2569125e3d
|
4
|
+
data.tar.gz: 99d7e22d878fde30c235f9b60544af0536f2c6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6dde3ab2aad881d8a1d7116c6a2994d51f0ed3dd2088abbcb4d8f86efc1e800a0b122d79d2e031969297c50da2134b19469e18093b292b6905852009be32e7d
|
7
|
+
data.tar.gz: b4f31aea83cb96b747309c330202314c42fbc64e14ae94fa421f935473bddb07e2af6fc713d499e54d0f8d3d70fd3ae129bc251a6ba82938a6ef88ba8c9fee8a
|
data/Gemfile.lock
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qe (0.3.
|
4
|
+
qe (0.3.1)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
builder (~> 3.
|
13
|
-
activerecord (
|
14
|
-
activemodel (=
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
activemodel (4.0.0)
|
11
|
+
activesupport (= 4.0.0)
|
12
|
+
builder (~> 3.1.0)
|
13
|
+
activerecord (4.0.0)
|
14
|
+
activemodel (= 4.0.0)
|
15
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
16
|
+
activesupport (= 4.0.0)
|
17
|
+
arel (~> 4.0.0)
|
18
|
+
activerecord-deprecated_finders (1.0.3)
|
19
|
+
activesupport (4.0.0)
|
20
|
+
i18n (~> 0.6, >= 0.6.4)
|
21
|
+
minitest (~> 4.2)
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
tzinfo (~> 0.3.37)
|
25
|
+
arel (4.0.0)
|
26
|
+
atomic (1.1.12)
|
22
27
|
awesome_print (1.1.0)
|
23
|
-
backburner (0.3
|
24
|
-
beaneater (~> 0.3.
|
28
|
+
backburner (0.4.3)
|
29
|
+
beaneater (~> 0.3.1)
|
25
30
|
dante (~> 0.1.5)
|
26
|
-
beaneater (0.3.
|
27
|
-
builder (3.
|
31
|
+
beaneater (0.3.1)
|
32
|
+
builder (3.1.4)
|
28
33
|
celluloid (0.14.1)
|
29
34
|
timers (>= 1.0.0)
|
30
35
|
coderay (1.0.9)
|
31
36
|
connection_pool (1.1.0)
|
32
37
|
dante (0.1.5)
|
33
|
-
delayed_job (4.0.0
|
38
|
+
delayed_job (4.0.0)
|
34
39
|
activesupport (>= 3.0, < 4.1)
|
35
|
-
delayed_job_active_record (4.0.0
|
40
|
+
delayed_job_active_record (4.0.0)
|
36
41
|
activerecord (>= 3.0, < 4.1)
|
37
42
|
delayed_job (>= 3.0, < 4.1)
|
38
43
|
diff-lcs (1.2.4)
|
39
|
-
i18n (0.6.
|
44
|
+
i18n (0.6.4)
|
40
45
|
json (1.8.0)
|
41
|
-
method_source (0.8.
|
46
|
+
method_source (0.8.2)
|
47
|
+
minitest (4.7.5)
|
42
48
|
mono_logger (1.1.0)
|
43
|
-
multi_json (1.7.
|
49
|
+
multi_json (1.7.8)
|
44
50
|
pry (0.9.12.2)
|
45
51
|
coderay (~> 1.0.5)
|
46
52
|
method_source (~> 0.8)
|
@@ -51,7 +57,7 @@ GEM
|
|
51
57
|
rack-protection (1.5.0)
|
52
58
|
rack
|
53
59
|
redis (3.0.4)
|
54
|
-
redis-namespace (1.3.
|
60
|
+
redis-namespace (1.3.1)
|
55
61
|
redis (~> 3.0.0)
|
56
62
|
resque (1.24.1)
|
57
63
|
mono_logger (~> 1.0)
|
@@ -63,28 +69,30 @@ GEM
|
|
63
69
|
redis (>= 2.0.1)
|
64
70
|
resque (>= 1.20.0)
|
65
71
|
rufus-scheduler
|
66
|
-
rspec (2.14.
|
67
|
-
rspec-core (
|
68
|
-
rspec-expectations (
|
69
|
-
rspec-mocks (
|
70
|
-
rspec-core (2.14.
|
71
|
-
rspec-expectations (2.14.0
|
72
|
+
rspec (2.14.1)
|
73
|
+
rspec-core (~> 2.14.0)
|
74
|
+
rspec-expectations (~> 2.14.0)
|
75
|
+
rspec-mocks (~> 2.14.0)
|
76
|
+
rspec-core (2.14.4)
|
77
|
+
rspec-expectations (2.14.0)
|
72
78
|
diff-lcs (>= 1.1.3, < 2.0)
|
73
|
-
rspec-mocks (2.14.
|
74
|
-
rufus-scheduler (2.0.
|
79
|
+
rspec-mocks (2.14.2)
|
80
|
+
rufus-scheduler (2.0.23)
|
75
81
|
tzinfo (>= 0.3.23)
|
76
|
-
sidekiq (2.
|
82
|
+
sidekiq (2.13.0)
|
77
83
|
celluloid (>= 0.14.1)
|
78
84
|
connection_pool (>= 1.0.0)
|
79
85
|
json
|
80
86
|
redis (>= 3.0)
|
81
87
|
redis-namespace
|
82
|
-
sinatra (1.4.
|
83
|
-
rack (~> 1.
|
88
|
+
sinatra (1.4.3)
|
89
|
+
rack (~> 1.4)
|
84
90
|
rack-protection (~> 1.4)
|
85
91
|
tilt (~> 1.3, >= 1.3.4)
|
86
|
-
slop (3.4.
|
92
|
+
slop (3.4.6)
|
87
93
|
sqlite3 (1.3.7)
|
94
|
+
thread_safe (0.1.2)
|
95
|
+
atomic
|
88
96
|
tilt (1.4.1)
|
89
97
|
timers (1.1.0)
|
90
98
|
tzinfo (0.3.37)
|
data/README.md
CHANGED
@@ -75,7 +75,7 @@ MailerWorker.enqueue({
|
|
75
75
|
})
|
76
76
|
```
|
77
77
|
|
78
|
-
You can specify when this job must be processed by setting the
|
78
|
+
You can specify when this job must be processed by setting the `:run_at` option.
|
79
79
|
|
80
80
|
``` ruby
|
81
81
|
MailerWorker.enqueue({
|
@@ -86,6 +86,18 @@ MailerWorker.enqueue({
|
|
86
86
|
})
|
87
87
|
```
|
88
88
|
|
89
|
+
### Setting the queue name
|
90
|
+
|
91
|
+
Sometimes setting the queue name is important.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class HelloWorker
|
95
|
+
include Qe::Worker
|
96
|
+
|
97
|
+
queue :hello
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
89
101
|
### Defining actions
|
90
102
|
|
91
103
|
Sometimes you want to create several actions in a single worker, just because is easier. Instead of manually dispatch the action on your perform method, you can
|
data/lib/qe/immediate.rb
CHANGED
data/lib/qe/testing.rb
CHANGED
@@ -5,7 +5,11 @@ module Qe
|
|
5
5
|
|
6
6
|
class Testing
|
7
7
|
def self.enqueue(worker, options = {})
|
8
|
-
Qe.jobs << {:
|
8
|
+
Qe.jobs << {worker: worker, options: options}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.schedule(worker, run_at, options = {})
|
12
|
+
Qe.jobs << {worker: worker, options: options, run_at: run_at}
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/qe/testing/rspec.rb
CHANGED
@@ -3,10 +3,12 @@ require "qe/testing"
|
|
3
3
|
module Qe
|
4
4
|
module EnqueueMatcher
|
5
5
|
class Matcher
|
6
|
-
attr_reader :worker, :options
|
6
|
+
attr_reader :worker, :options, :date, :scheduled
|
7
7
|
|
8
|
-
def initialize(worker)
|
8
|
+
def initialize(worker, scheduled)
|
9
9
|
@worker = worker
|
10
|
+
@options = nil
|
11
|
+
@scheduled = scheduled
|
10
12
|
end
|
11
13
|
|
12
14
|
def with(options)
|
@@ -14,16 +16,34 @@ module Qe
|
|
14
16
|
self
|
15
17
|
end
|
16
18
|
|
19
|
+
def on(date)
|
20
|
+
@date = date
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
17
24
|
def matches?(block)
|
18
25
|
block.call
|
19
26
|
|
20
|
-
|
27
|
+
jobs.any? do |job|
|
21
28
|
condition = job[:worker] == worker
|
29
|
+
condition = condition && datetime? if scheduled
|
22
30
|
condition = condition && job[:options] == options if options
|
31
|
+
condition = condition && job[:run_at].to_i == date.to_i if date
|
23
32
|
condition
|
24
33
|
end != nil
|
25
34
|
end
|
26
35
|
|
36
|
+
def does_not_match?(block)
|
37
|
+
block.call
|
38
|
+
|
39
|
+
jobs.none? do |job|
|
40
|
+
condition = job[:worker] != worker
|
41
|
+
condition = condition && job[:options] != options if options
|
42
|
+
condition = condition && job[:run_at].to_i != date.to_i if date
|
43
|
+
condition
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
27
47
|
def description
|
28
48
|
"enqueue job for #{worker.inspect} worker"
|
29
49
|
end
|
@@ -37,7 +57,19 @@ module Qe
|
|
37
57
|
end
|
38
58
|
|
39
59
|
def build_message(base)
|
40
|
-
base << (options.empty? ? "" : " with #{options.inspect}")
|
60
|
+
base << ((options || {}).empty? ? "" : " with #{options.inspect}")
|
61
|
+
base << " on #{date.inspect}" if date
|
62
|
+
base
|
63
|
+
end
|
64
|
+
|
65
|
+
def jobs
|
66
|
+
Qe.jobs.select do |job|
|
67
|
+
scheduled ? job.key?(:run_at) : true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def datetime?
|
72
|
+
[Date, Time, DateTime].find {|klass| date.kind_of?(klass) }
|
41
73
|
end
|
42
74
|
end
|
43
75
|
|
@@ -45,7 +77,14 @@ module Qe
|
|
45
77
|
# expect {}.to enqueue(MailerWorker).with(options)
|
46
78
|
#
|
47
79
|
def enqueue(worker)
|
48
|
-
Matcher.new(worker)
|
80
|
+
Matcher.new(worker, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# expect {}.to schedule(MailerWorker).on(Time.now).with(options)
|
85
|
+
#
|
86
|
+
def schedule(worker)
|
87
|
+
Matcher.new(worker, true)
|
49
88
|
end
|
50
89
|
end
|
51
90
|
end
|
data/lib/qe/version.rb
CHANGED
data/spec/qe/immediate_spec.rb
CHANGED
@@ -18,4 +18,14 @@ describe Qe::Immediate do
|
|
18
18
|
|
19
19
|
Qe::Immediate.enqueue(HelloWorker)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "schedules job" do
|
23
|
+
date = Time.now
|
24
|
+
|
25
|
+
Qe::Immediate
|
26
|
+
.should_receive(:enqueue)
|
27
|
+
.with(HelloWorker, :a => 1)
|
28
|
+
|
29
|
+
Qe::Immediate.schedule(HelloWorker, date, :a => 1)
|
30
|
+
end
|
21
31
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Qe::EnqueueMatcher do
|
4
|
+
let(:date) { Time.now }
|
5
|
+
|
6
|
+
before { Qe.jobs.clear }
|
7
|
+
|
8
|
+
it "enqueues job" do
|
9
|
+
expect {
|
10
|
+
HelloWorker.enqueue(a: 1)
|
11
|
+
}.to enqueue(HelloWorker).with(a: 1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "enqueues job without mentioning options" do
|
15
|
+
expect {
|
16
|
+
HelloWorker.enqueue(a: 1)
|
17
|
+
}.to enqueue(HelloWorker)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't enqueue job" do
|
21
|
+
expect {
|
22
|
+
# noop
|
23
|
+
}.not_to enqueue(HelloWorker)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "doesn't enqueue job with options" do
|
27
|
+
expect {
|
28
|
+
HelloWorker.enqueue(b: 1)
|
29
|
+
}.not_to enqueue(HelloWorker).with(a: 1)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "schedules job" do
|
33
|
+
expect {
|
34
|
+
HelloWorker.enqueue(a: 1, run_at: date)
|
35
|
+
}.to schedule(HelloWorker).on(date).with(a: 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "schedules job without mentioning options" do
|
39
|
+
expect {
|
40
|
+
HelloWorker.enqueue(a: 1, run_at: date)
|
41
|
+
}.to schedule(HelloWorker).on(date)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "requires date on scheduled job" do
|
45
|
+
expect {
|
46
|
+
HelloWorker.enqueue(a: 1, run_at: date)
|
47
|
+
}.not_to schedule(HelloWorker).on(nil)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Qe::Testing do
|
4
|
+
let(:job) { double("job").as_null_object }
|
5
|
+
|
6
|
+
it "stores enqueued job" do
|
7
|
+
Qe::Testing.enqueue(HelloWorker, a: 1)
|
8
|
+
job = Qe.jobs.first
|
9
|
+
|
10
|
+
expect(job).to include(worker: HelloWorker)
|
11
|
+
expect(job).to include(options: {a: 1})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "schedules job" do
|
15
|
+
date = Time.now
|
16
|
+
Qe::Testing.schedule(HelloWorker, date, a: 1)
|
17
|
+
job = Qe.jobs.first
|
18
|
+
|
19
|
+
expect(job).to include(run_at: date)
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -230,9 +230,11 @@ files:
|
|
230
230
|
- spec/qe/enqueue_matcher_spec.rb
|
231
231
|
- spec/qe/immediate_spec.rb
|
232
232
|
- spec/qe/locale_spec.rb
|
233
|
+
- spec/qe/matchers_spec.rb
|
233
234
|
- spec/qe/qu_spec.rb
|
234
235
|
- spec/qe/resque_spec.rb
|
235
236
|
- spec/qe/sidekiq_spec.rb
|
237
|
+
- spec/qe/testing_spec.rb
|
236
238
|
- spec/qe/worker_spec.rb
|
237
239
|
- spec/spec_helper.rb
|
238
240
|
- spec/support/hello_worker.rb
|