disc 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/examples/echoer.rb +1 -1
- data/examples/failer.rb +16 -0
- data/lib/disc/version.rb +1 -1
- data/lib/disc.rb +1 -2
- data/test/disc_test.rb +65 -8
- metadata +3 -3
- data/examples/fail_job.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf220b91a7f56d811b3926018f82fcf65e35956d
|
4
|
+
data.tar.gz: 64c8e523ed22e996a54b31da8f2b077c08b6ff7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6045fb0e6e7aaf39812feada1334c6dc288f4f6eef5d0e7f901e80d577a353c70e8b1b4e7a0df51faa5c52980b4a5dbcd7d5c415bdb2dbe56e137b9077de53ab
|
7
|
+
data.tar.gz: 0e4fe719be855badefeb2aa726d61240f5908b62b383afaf4586ab1df0cd5864f1aec02c081ba4319a1fff2b79ba5ae41c918142388fefe03fce69fac711314a
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ default.
|
|
111
111
|
|
112
112
|
## Rails and ActiveJob integration
|
113
113
|
|
114
|
-
Disc
|
114
|
+
You can use Disc easily in Rails without any more hassle, but if you'd like to use it via [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) you can use the adapter included in this gem.
|
115
115
|
|
116
116
|
```ruby
|
117
117
|
# Gemfile
|
@@ -142,7 +142,7 @@ CluJob.perform_later(a_bunch_of_arguments)
|
|
142
142
|
As always, make sure your `disc_init.rb` file requires the necessary jobs and you'll be good to go!
|
143
143
|
|
144
144
|
|
145
|
-
## A note on stability
|
145
|
+
## A note on stability
|
146
146
|
|
147
147
|
The version of Disque at the time of this writing is `0.0.1`. It is a wonderful project, I know of people running it in production, and I expect it will only get better and better with time, but please do not expect Disc to be more production ready than Disque is, Disque still gives me the occasional segfault when running Disc's test suite.
|
148
148
|
|
data/examples/echoer.rb
CHANGED
data/examples/failer.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'disc'
|
2
|
+
|
3
|
+
def Disc.on_error(exception, job)
|
4
|
+
$stdout.puts('<insert error reporting here>')
|
5
|
+
$stdout.puts(exception.message)
|
6
|
+
$stdout.puts(job)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Failer
|
10
|
+
include Disc::Job
|
11
|
+
disc queue: 'test'
|
12
|
+
|
13
|
+
def perform(string)
|
14
|
+
raise string
|
15
|
+
end
|
16
|
+
end
|
data/lib/disc/version.rb
CHANGED
data/lib/disc.rb
CHANGED
@@ -72,12 +72,11 @@ class Disc
|
|
72
72
|
Array(jobs).each do |queue, msgid, serialized_job|
|
73
73
|
begin
|
74
74
|
job = MessagePack.unpack(serialized_job)
|
75
|
-
job.update('id' => msgid, 'queue' => queue)
|
76
75
|
instance = Object.const_get(job['class']).new
|
77
76
|
instance.perform(*job['arguments'])
|
78
77
|
disque.call('ACKJOB', msgid)
|
79
78
|
rescue => err
|
80
|
-
Disc.on_error(err, job)
|
79
|
+
Disc.on_error(err, job.update('id' => msgid, 'queue' => queue))
|
81
80
|
end
|
82
81
|
end
|
83
82
|
end
|
data/test/disc_test.rb
CHANGED
@@ -6,13 +6,29 @@ require 'pty'
|
|
6
6
|
require_relative '../examples/echoer'
|
7
7
|
# class Echoer
|
8
8
|
# include Disc::Job
|
9
|
-
# disc queue: '
|
9
|
+
# disc queue: 'test'
|
10
10
|
#
|
11
11
|
# def perform(first, second, third)
|
12
12
|
# puts "First: #{ first }, Second: #{ second }, Third: #{ third }"
|
13
13
|
# end
|
14
14
|
# end
|
15
15
|
|
16
|
+
require_relative '../examples/failer'
|
17
|
+
# def Disc.on_error(exception, job)
|
18
|
+
# $stdout.puts('<insert error reporting here>')
|
19
|
+
# $stdout.puts(exception.message)
|
20
|
+
# $stdout.puts(job)
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# class Failer
|
24
|
+
# include Disc::Job
|
25
|
+
# disc queue: 'test'
|
26
|
+
#
|
27
|
+
# def perform(string)
|
28
|
+
# raise string
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
|
16
32
|
prepare do
|
17
33
|
Disc.disque.call('DEBUG', 'FLUSHALL')
|
18
34
|
end
|
@@ -21,7 +37,7 @@ scope do
|
|
21
37
|
test 'jobs are enqueued to the correct Disque queue with appropriate parameters and class' do
|
22
38
|
jobid = Echoer.enqueue('one argument', { random: 'data' }, 3)
|
23
39
|
|
24
|
-
jobs = Array(Disc.disque.fetch(from: ['
|
40
|
+
jobs = Array(Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1))
|
25
41
|
assert jobs.any?
|
26
42
|
assert_equal 1, jobs.count
|
27
43
|
|
@@ -46,20 +62,20 @@ scope do
|
|
46
62
|
in_3_seconds = (Time.now + 3).to_datetime
|
47
63
|
jobid = Echoer.enqueue_at(in_3_seconds, 'one argument', { random: 'data' }, 3)
|
48
64
|
|
49
|
-
jobs = Array(Disc.disque.fetch(from: ['
|
65
|
+
jobs = Array(Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1))
|
50
66
|
assert jobs.empty?
|
51
67
|
|
52
68
|
sleep 1
|
53
|
-
jobs = Array(Disc.disque.fetch(from: ['
|
69
|
+
jobs = Array(Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1))
|
54
70
|
assert jobs.empty?
|
55
71
|
|
56
72
|
sleep 2
|
57
|
-
jobs = Array(Disc.disque.fetch(from: ['
|
73
|
+
jobs = Array(Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1))
|
58
74
|
assert jobs.any?
|
59
75
|
assert_equal 1, jobs.size
|
60
76
|
|
61
77
|
jobs.first.tap do |queue, id, serialized_job|
|
62
|
-
assert_equal '
|
78
|
+
assert_equal 'test', queue
|
63
79
|
assert_equal jobid, id
|
64
80
|
job = MessagePack.unpack(serialized_job)
|
65
81
|
assert job.has_key?('class')
|
@@ -74,11 +90,11 @@ scope do
|
|
74
90
|
Echoer.enqueue('one argument', { random: 'data' }, 3)
|
75
91
|
|
76
92
|
cout, _, pid = PTY.spawn(
|
77
|
-
'QUEUES=
|
93
|
+
'QUEUES=test ruby -Ilib bin/disc -r ./examples/echoer'
|
78
94
|
)
|
79
95
|
sleep 0.5
|
80
96
|
|
81
|
-
jobs = Disc.disque.fetch(from: ['
|
97
|
+
jobs = Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1)
|
82
98
|
assert jobs.nil?
|
83
99
|
|
84
100
|
matched = false
|
@@ -94,4 +110,45 @@ scope do
|
|
94
110
|
Process.kill("KILL", pid)
|
95
111
|
end
|
96
112
|
end
|
113
|
+
|
114
|
+
test 'Disc.on_error will catch unhandled exceptions and keep disc alive' do
|
115
|
+
begin
|
116
|
+
Failer.enqueue('this can only end positively')
|
117
|
+
|
118
|
+
cout, _, pid = PTY.spawn(
|
119
|
+
'QUEUES=test ruby -Ilib bin/disc -r ./examples/failer'
|
120
|
+
)
|
121
|
+
sleep 0.5
|
122
|
+
|
123
|
+
jobs = Disc.disque.fetch(from: ['test'], timeout: Disc.disque_timeout, count: 1)
|
124
|
+
assert jobs.nil?
|
125
|
+
|
126
|
+
counter = 0
|
127
|
+
tasks = {
|
128
|
+
reported_error: false,
|
129
|
+
printed_message: false,
|
130
|
+
printed_job: false
|
131
|
+
}
|
132
|
+
|
133
|
+
while tasks.values.include?(false) && counter < 10
|
134
|
+
counter += 1
|
135
|
+
output = cout.gets
|
136
|
+
|
137
|
+
tasks[:reported_error] = true if output.match(/<insert error reporting here>/)
|
138
|
+
tasks[:printed_message] = true if output.match(/this can only end positively/)
|
139
|
+
tasks[:printed_job] = true if output.match(/Failer/)
|
140
|
+
end
|
141
|
+
|
142
|
+
assert !tasks.values.include?(false)
|
143
|
+
|
144
|
+
begin
|
145
|
+
Process.getpgid(pid)
|
146
|
+
assert true
|
147
|
+
rescue Errno::ESRCH
|
148
|
+
assert false
|
149
|
+
end
|
150
|
+
ensure
|
151
|
+
Process.kill("KILL", pid)
|
152
|
+
end
|
153
|
+
end
|
97
154
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pote
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: disque
|
@@ -71,7 +71,7 @@ files:
|
|
71
71
|
- disc.gemspec
|
72
72
|
- examples/disc_init.rb
|
73
73
|
- examples/echoer.rb
|
74
|
-
- examples/
|
74
|
+
- examples/failer.rb
|
75
75
|
- examples/greeter.rb
|
76
76
|
- lib/active_job/queue_adapters/disc_adapter.rb
|
77
77
|
- lib/disc.rb
|