qs 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -162,11 +162,11 @@ class Qs::Queue
162
162
 
163
163
  should "know its custom inspect" do
164
164
  reference = '0x0%x' % (subject.object_id << 1)
165
- expected = "#<#{subject.class}:#{reference} " \
166
- "@name=#{subject.name.inspect} " \
167
- "@job_handler_ns=#{subject.job_handler_ns.inspect} " \
168
- "@event_handler_ns=#{subject.event_handler_ns.inspect}>"
169
- assert_equal expected, subject.inspect
165
+ exp = "#<#{subject.class}:#{reference} " \
166
+ "@name=#{subject.name.inspect} " \
167
+ "@job_handler_ns=#{subject.job_handler_ns.inspect} " \
168
+ "@event_handler_ns=#{subject.event_handler_ns.inspect}>"
169
+ assert_equal exp, subject.inspect
170
170
  end
171
171
 
172
172
  should "require a name when initialized" do
@@ -25,7 +25,7 @@ class Qs::Runner
25
25
 
26
26
  should have_readers :handler_class, :handler
27
27
  should have_readers :logger, :message, :params
28
- should have_imeths :run
28
+ should have_imeths :run, :halt
29
29
 
30
30
  should "know its handler class and handler" do
31
31
  assert_equal @handler_class, subject.handler_class
@@ -56,6 +56,14 @@ class Qs::Runner
56
56
  assert_raises(NotImplementedError){ subject.run }
57
57
  end
58
58
 
59
+ should "halt execution with its halt method" do
60
+ something = nil
61
+ @runner_class.new(@handler_class).tap do |runner|
62
+ catch(:halt){ runner.halt; something = Factory.string }
63
+ end
64
+ assert_nil something
65
+ end
66
+
59
67
  end
60
68
 
61
69
  class TestJobHandler
@@ -39,7 +39,7 @@ class Qs::TestRunner
39
39
  end
40
40
  subject{ @runner }
41
41
 
42
- should have_imeths :run
42
+ should have_imeths :halted?, :run
43
43
 
44
44
  should "know its standard args" do
45
45
  assert_equal @args[:logger], subject.logger
@@ -71,6 +71,17 @@ class Qs::TestRunner
71
71
  assert_nil @handler.after_called
72
72
  end
73
73
 
74
+ should "not be halted by default" do
75
+ assert_false subject.halted?
76
+ end
77
+
78
+ should "not call `run` on its handler if halted when run" do
79
+ catch(:halt){ subject.halt }
80
+ assert_true subject.halted?
81
+ subject.run
82
+ assert_nil @handler.run_called
83
+ end
84
+
74
85
  should "stringify and encode the params passed to it" do
75
86
  key, value = Factory.string.to_sym, Factory.string
76
87
  params = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-04-05 00:00:00 Z
13
+ date: 2016-06-15 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 2.15.1
22
+ version: 2.16.1
23
23
  type: :development
24
24
  version_requirements: *id001
25
25
  - !ruby/object:Gem::Dependency
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 3.0.1
32
+ version: 3.0.2
33
33
  type: :development
34
34
  version_requirements: *id002
35
35
  - !ruby/object:Gem::Dependency
@@ -39,7 +39,7 @@ dependencies:
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- version: 0.6.0
42
+ version: 0.6.1
43
43
  type: :runtime
44
44
  version_requirements: *id003
45
45
  - !ruby/object:Gem::Dependency
@@ -49,7 +49,7 @@ dependencies:
49
49
  requirements:
50
50
  - - ~>
51
51
  - !ruby/object:Gem::Version
52
- version: 0.3.0
52
+ version: 0.3.1
53
53
  type: :runtime
54
54
  version_requirements: *id004
55
55
  - !ruby/object:Gem::Dependency
@@ -59,29 +59,19 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 0.1.0
62
+ version: 0.2.0
63
63
  type: :runtime
64
64
  version_requirements: *id005
65
65
  - !ruby/object:Gem::Dependency
66
- name: ns-options
66
+ name: much-timeout
67
67
  prerelease: false
68
68
  requirement: &id006 !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ~>
71
71
  - !ruby/object:Gem::Version
72
- version: 1.1.6
72
+ version: 0.1.0
73
73
  type: :runtime
74
74
  version_requirements: *id006
75
- - !ruby/object:Gem::Dependency
76
- name: SystemTimer
77
- prerelease: false
78
- requirement: &id007 !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: "1.2"
83
- type: :runtime
84
- version_requirements: *id007
85
75
  description: Define message queues. Process jobs and events. Profit.
86
76
  email:
87
77
  - kelly@kellyredding.com
@@ -137,7 +127,7 @@ files:
137
127
  - log/.gitkeep
138
128
  - qs.gemspec
139
129
  - test/helper.rb
140
- - test/support/app_daemon.rb
130
+ - test/support/app_queue.rb
141
131
  - test/support/client_spy.rb
142
132
  - test/support/config.qs
143
133
  - test/support/config_files/empty.qs
@@ -194,13 +184,13 @@ require_paths:
194
184
  - lib
195
185
  required_ruby_version: !ruby/object:Gem::Requirement
196
186
  requirements:
197
- - &id008
187
+ - &id007
198
188
  - ">="
199
189
  - !ruby/object:Gem::Version
200
190
  version: "0"
201
191
  required_rubygems_version: !ruby/object:Gem::Requirement
202
192
  requirements:
203
- - *id008
193
+ - *id007
204
194
  requirements: []
205
195
 
206
196
  rubyforge_project:
@@ -210,7 +200,7 @@ specification_version: 4
210
200
  summary: Define message queues. Process jobs and events. Profit.
211
201
  test_files:
212
202
  - test/helper.rb
213
- - test/support/app_daemon.rb
203
+ - test/support/app_queue.rb
214
204
  - test/support/client_spy.rb
215
205
  - test/support/config.qs
216
206
  - test/support/config_files/empty.qs
@@ -1,143 +0,0 @@
1
- require 'qs'
2
-
3
- LOGGER = Logger.new(ROOT_PATH.join('log/app_daemon.log').to_s)
4
- LOGGER.datetime_format = "" # turn off the datetime in the logs
5
-
6
- AppQueue = Qs::Queue.new do
7
- name 'qs-app-main'
8
-
9
- job_handler_ns 'AppHandlers'
10
-
11
- job 'basic', 'Basic'
12
- job 'error', 'Error'
13
- job 'timeout', 'Timeout'
14
- job 'slow', 'Slow'
15
-
16
- event_handler_ns 'AppHandlers'
17
-
18
- event 'qs-app', 'basic', 'BasicEvent'
19
- event 'qs-app', 'error', 'ErrorEvent'
20
- event 'qs-app', 'timeout', 'TimeoutEvent'
21
- event 'qs-app', 'slow', 'SlowEvent'
22
- end
23
-
24
- class AppDaemon
25
- include Qs::Daemon
26
-
27
- name 'qs-app'
28
-
29
- logger LOGGER
30
- verbose_logging true
31
-
32
- queue AppQueue
33
-
34
- error do |exception, context|
35
- return unless (message = context.message)
36
- payload_type = message.payload_type
37
- route_name = message.route_name
38
- case(route_name)
39
- when 'error', 'timeout', 'qs-app:error', 'qs-app:timeout'
40
- error = "#{exception.class}: #{exception.message}"
41
- Qs.redis.with{ |c| c.set("qs-app:last_#{payload_type}_error", error) }
42
- when 'slow', 'qs-app:slow'
43
- error = exception.class.to_s
44
- Qs.redis.with{ |c| c.set("qs-app:last_#{payload_type}_error", error) }
45
- end
46
- end
47
-
48
- end
49
-
50
- DISPATCH_LOGGER = Logger.new(ROOT_PATH.join('log/app_dispatcher_daemon.log').to_s)
51
- DISPATCH_LOGGER.datetime_format = "" # turn off the datetime in the logs
52
-
53
- class DispatcherDaemon
54
- include Qs::Daemon
55
-
56
- name 'qs-app-dispatcher'
57
-
58
- logger DISPATCH_LOGGER
59
- verbose_logging true
60
-
61
- # we build a "custom" dispatcher because we can't rely on Qs being initialized
62
- # when this is required
63
- queue Qs::DispatcherQueue.new({
64
- :queue_class => Qs.config.dispatcher_queue_class,
65
- :queue_name => 'qs-app-dispatcher',
66
- :job_name => Qs.config.dispatcher.job_name,
67
- :job_handler_class_name => Qs.config.dispatcher.job_handler_class_name
68
- })
69
- end
70
-
71
- module AppHandlers
72
-
73
- class Basic
74
- include Qs::JobHandler
75
-
76
- def run!
77
- Qs.redis.with{ |c| c.set("qs-app:#{params['key']}", params['value']) }
78
- end
79
- end
80
-
81
- class Error
82
- include Qs::JobHandler
83
-
84
- def run!
85
- raise params['error_message']
86
- end
87
- end
88
-
89
- class Timeout
90
- include Qs::JobHandler
91
-
92
- timeout 0.2
93
-
94
- def run!
95
- sleep 2
96
- end
97
- end
98
-
99
- class Slow
100
- include Qs::JobHandler
101
-
102
- def run!
103
- sleep 5
104
- Qs.redis.with{ |c| c.set('qs-app:slow', 'finished') }
105
- end
106
- end
107
-
108
- class BasicEvent
109
- include Qs::EventHandler
110
-
111
- def run!
112
- Qs.redis.with{ |c| c.set("qs-app:#{params['key']}", params['value']) }
113
- end
114
- end
115
-
116
- class ErrorEvent
117
- include Qs::EventHandler
118
-
119
- def run!
120
- raise params['error_message']
121
- end
122
- end
123
-
124
- class TimeoutEvent
125
- include Qs::EventHandler
126
-
127
- timeout 0.2
128
-
129
- def run!
130
- sleep 2
131
- end
132
- end
133
-
134
- class SlowEvent
135
- include Qs::EventHandler
136
-
137
- def run!
138
- sleep 5
139
- Qs.redis.with{ |c| c.set('qs-app:slow:event', 'finished') }
140
- end
141
- end
142
-
143
- end