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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0081b227e9f7794ea8651ef2966b223c72a0fe6b
4
- data.tar.gz: a448cd19e5f8a3b15c177cbd5a75159de298fecb
3
+ metadata.gz: bf220b91a7f56d811b3926018f82fcf65e35956d
4
+ data.tar.gz: 64c8e523ed22e996a54b31da8f2b077c08b6ff7d
5
5
  SHA512:
6
- metadata.gz: 3c77f98a2e0a805beeb9996c8b14e1d529ea99cec467c895df4409bfc111b976f4924d4248793ba64cba772557dc2e57a4b01df8a430e88e38e412d4fcaa0911
7
- data.tar.gz: dda30cd643665212bf5649a147d899a6ffcd9191b2a12e0ce8b219791205f340462b89220c8c1127737c28fb1c3571bdd7aea3f66337af0c77c049029147dbf0
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 has an [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) adapter, which you can use very easily:
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
@@ -2,7 +2,7 @@ require 'disc'
2
2
 
3
3
  class Echoer
4
4
  include Disc::Job
5
- disc queue: 'test_urgent'
5
+ disc queue: 'test'
6
6
 
7
7
  def perform(first, second, third)
8
8
  puts "First: #{ first }, Second: #{ second }, Third: #{ third }"
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Disc
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
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: 'test_urgent'
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: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
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: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
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: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
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: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
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 'test_urgent', queue
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=test_urgent ruby -Ilib bin/disc -r ./examples/echoer'
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: ['test_urgent'], timeout: Disc.disque_timeout, count: 1)
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.15
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-17 00:00:00.000000000 Z
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/fail_job.rb
74
+ - examples/failer.rb
75
75
  - examples/greeter.rb
76
76
  - lib/active_job/queue_adapters/disc_adapter.rb
77
77
  - lib/disc.rb
data/examples/fail_job.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'disc'
2
-
3
- class FailJob
4
- include Disc::Job
5
- disc queue: 'test_medium'
6
-
7
- def perform(string)
8
- raise string
9
- end
10
- end