qe 0.1.3 → 0.2.0

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.
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qe (0.1.3)
4
+ qe (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- activemodel (3.2.8)
10
- activesupport (= 3.2.8)
9
+ activemodel (3.2.9)
10
+ activesupport (= 3.2.9)
11
11
  builder (~> 3.0.0)
12
- activerecord (3.2.8)
13
- activemodel (= 3.2.8)
14
- activesupport (= 3.2.8)
12
+ activerecord (3.2.9)
13
+ activemodel (= 3.2.9)
14
+ activesupport (= 3.2.9)
15
15
  arel (~> 3.0.2)
16
16
  tzinfo (~> 0.3.29)
17
- activesupport (3.2.8)
17
+ activesupport (3.2.9)
18
18
  i18n (~> 0.6)
19
19
  multi_json (~> 1.0)
20
20
  arel (3.0.2)
21
21
  awesome_print (1.1.0)
22
- backburner (0.2.5)
23
- beaneater (~> 0.1.2)
22
+ backburner (0.3.0)
23
+ beaneater (~> 0.2.0)
24
24
  dante (~> 0.1.5)
25
- beaneater (0.1.2)
25
+ beaneater (0.2.0)
26
26
  builder (3.0.4)
27
27
  celluloid (0.12.3)
28
28
  facter (>= 1.6.12)
@@ -30,7 +30,7 @@ GEM
30
30
  coderay (1.0.8)
31
31
  connection_pool (0.9.2)
32
32
  dante (0.1.5)
33
- delayed_job (3.0.3)
33
+ delayed_job (3.0.4)
34
34
  activesupport (~> 3.0)
35
35
  delayed_job_active_record (0.3.3)
36
36
  activerecord (>= 2.1.0, < 4)
@@ -57,15 +57,15 @@ GEM
57
57
  redis-namespace (~> 1.0)
58
58
  sinatra (>= 0.9.2)
59
59
  vegas (~> 0.1.2)
60
- rspec (2.11.0)
61
- rspec-core (~> 2.11.0)
62
- rspec-expectations (~> 2.11.0)
63
- rspec-mocks (~> 2.11.0)
64
- rspec-core (2.11.1)
65
- rspec-expectations (2.11.3)
60
+ rspec (2.12.0)
61
+ rspec-core (~> 2.12.0)
62
+ rspec-expectations (~> 2.12.0)
63
+ rspec-mocks (~> 2.12.0)
64
+ rspec-core (2.12.0)
65
+ rspec-expectations (2.12.0)
66
66
  diff-lcs (~> 1.1.3)
67
- rspec-mocks (2.11.3)
68
- sidekiq (2.5.2)
67
+ rspec-mocks (2.12.0)
68
+ sidekiq (2.5.3)
69
69
  celluloid (~> 0.12.0)
70
70
  connection_pool (~> 0.9.2)
71
71
  multi_json (~> 1)
data/README.md CHANGED
@@ -75,7 +75,41 @@ MailerWorker.enqueue({
75
75
  })
76
76
  ```
77
77
 
78
- ## Development support
78
+ ### Defining actions
79
+
80
+ 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
81
+ just add the `Qe::Action` module.
82
+
83
+ ``` ruby
84
+ class NotificationWorker
85
+ include Qe::Worker
86
+ include Qe::Action
87
+
88
+ def shutdown
89
+ puts options[:message]
90
+ end
91
+
92
+ def startup
93
+ puts options[:message]
94
+ end
95
+
96
+ def default
97
+ puts options[:message]
98
+ end
99
+ end
100
+ ```
101
+
102
+ Now, you can just enqueue jobs by defining the `:action` option. If no action is defined, then the default is executed.
103
+
104
+ ``` ruby
105
+ NotificationWorker.enqueue(:action => :shutdown, :message => "shutting down")
106
+ NotificationWorker.enqueue(:action => :startup, :message => "starting up")
107
+ NotificationWorker.enqueue(:message => "wat?")
108
+ ```
109
+
110
+ The action must be a existing public method. If not defined, `Qe::Action::MissingActionError` exception is raised.
111
+
112
+ ### Development support
79
113
 
80
114
  Qe comes with development support. Instead of starting up workers on development environment, you can use the `Qe::Immediate` adapter, which executes your worker right away!
81
115
 
@@ -85,7 +119,7 @@ Qe.adapter = Qe::Immediate
85
119
 
86
120
  If you're using Rails, you can add the line above to your `config/environments/development.rb` file.
87
121
 
88
- ## Testing support
122
+ ### Testing support
89
123
 
90
124
  Qe also comes with testing support. Just require the `qe/testing.rb` file
91
125
  and a fake queuing adapter will be used. All enqueued jobs will be stored
@@ -114,13 +148,11 @@ end
114
148
  ```
115
149
 
116
150
 
117
- Maintainer
118
- ----------
151
+ ## Maintainer
119
152
 
120
153
  * Nando Vieira (<http://nandovieira.com.br>)
121
154
 
122
- License:
123
- --------
155
+ ## License:
124
156
 
125
157
  (The MIT License)
126
158
 
data/lib/qe.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "qe/action"
1
2
  require "qe/immediate"
2
3
  require "qe/version"
3
4
  require "qe/worker"
@@ -0,0 +1,14 @@
1
+ module Qe
2
+ module Action
3
+ MissingActionError = Class.new(StandardError)
4
+
5
+ def perform
6
+ action = options.fetch(:action, :default)
7
+
8
+ raise MissingActionError,
9
+ "the action #{action.inspect} is not defined" unless respond_to?(action)
10
+
11
+ public_send(action)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Qe
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe Qe::Action do
4
+ NotificationWorker = Class.new do
5
+ include Qe::Worker
6
+ include Qe::Action
7
+
8
+ def shutdown; end
9
+ def default; end
10
+ end
11
+
12
+ let(:job) { NotificationWorker.new({}) }
13
+
14
+ it "responds to perform" do
15
+ expect(job).to respond_to(:perform)
16
+ end
17
+
18
+ it "performs specified action" do
19
+ job.should_receive(:hello)
20
+ job.options[:action] = :hello
21
+
22
+ job.perform
23
+ end
24
+
25
+ it "executes default action when have no action" do
26
+ job.should_receive(:default)
27
+ job.perform
28
+ end
29
+
30
+ it "raises exception when action method doesn't exist" do
31
+ job.options[:action] = :invalid
32
+
33
+ expect {
34
+ job.perform
35
+ }.to raise_error(Qe::Action::MissingActionError, "the action :invalid is not defined")
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -199,6 +199,7 @@ files:
199
199
  - examples/sidekiq.ru
200
200
  - examples/workers.rb
201
201
  - lib/qe.rb
202
+ - lib/qe/action.rb
202
203
  - lib/qe/beanstalk.rb
203
204
  - lib/qe/delayed_job.rb
204
205
  - lib/qe/immediate.rb
@@ -210,6 +211,7 @@ files:
210
211
  - lib/qe/version.rb
211
212
  - lib/qe/worker.rb
212
213
  - qe.gemspec
214
+ - spec/qe/action_spec.rb
213
215
  - spec/qe/beanstalk_spec.rb
214
216
  - spec/qe/delayed_job_spec.rb
215
217
  - spec/qe/enqueue_matcher_spec.rb
@@ -239,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
241
  version: '0'
240
242
  requirements: []
241
243
  rubyforge_project:
242
- rubygems_version: 1.8.23
244
+ rubygems_version: 1.8.24
243
245
  signing_key:
244
246
  specification_version: 3
245
247
  summary: A simple interface over several background job libraries like Resque, Sidekiq