anway 0.6.0 → 0.7.1
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.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/anway/version.rb +2 -2
- data/lib/anway/worker/dsl.rb +51 -0
- data/lib/anway/worker.rb +18 -5
- data/lib/anway.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ab23c82fb21cc810adb08fe15e176a425c72c897acb84e3511cefa06b5d967a
|
|
4
|
+
data.tar.gz: 7020f517ad4b17ce408c78e7a46f313422d756aac5dfe089aeaba9ea0aeed17c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97658b684eea689f56dc1a9526ef053a6d124a9a118574aec6433d5640b1b82b3bba461ea6712d32e4e694b238c9975e18ce95eca6d95cafee03f326dad5b6c7
|
|
7
|
+
data.tar.gz: f93a36c28d785f6781282491e2a939ee492d54512393eed311a29645fd72a667a500eb462018325d4de5193a1104ccae810509da4d91520ce83c68b24431d46c
|
data/README.md
CHANGED
|
@@ -150,6 +150,32 @@ When a class has more than one option set, the sets merge in call order:
|
|
|
150
150
|
|
|
151
151
|
`set` merges with the options of the class by the same rules. `WelcomeJob.anway_options`, with no keys, returns the merged options.
|
|
152
152
|
|
|
153
|
+
### One method for each option
|
|
154
|
+
|
|
155
|
+
`Anway::Worker` also gives one class method for each key of `anway_options`. You can use this style, `anway_options`, or the two together.
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
class ReceiveJob
|
|
159
|
+
include Anway::Worker
|
|
160
|
+
|
|
161
|
+
event 'mail.receive'
|
|
162
|
+
queue :default
|
|
163
|
+
recover 16
|
|
164
|
+
topics 'mail.in', 'mail.bounce'
|
|
165
|
+
|
|
166
|
+
def perform(mail_id)
|
|
167
|
+
Mail.find_by(id: mail_id)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- `retry` is a reserved word in Ruby. Use `recover`, `retries`, or `attempts`: the three names set `retry`.
|
|
173
|
+
- The other methods have the name of the key: `event`, `queue`, `reserve_for`, `backtrace`, `unique_for`, `unique_until`, `expires_in`, `expires_at`, `track`, `on_dead`, `custom`, `topics`, and `cron`.
|
|
174
|
+
- `topics` and `cron` take one or more values.
|
|
175
|
+
- A method always wins over `anway_options`, in any call order. Two method calls merge by the merge rules.
|
|
176
|
+
- A method with no value returns the option of the class: `ReceiveJob.queue # => :default`.
|
|
177
|
+
|
|
178
|
+
|
|
153
179
|
To send a job that a worker in any language runs, give the event and the same push keys:
|
|
154
180
|
|
|
155
181
|
```ruby
|
data/lib/anway/version.rb
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anway
|
|
4
|
+
module Worker
|
|
5
|
+
# One class method for each key of anway_options. Anway::Worker adds
|
|
6
|
+
# them to each job class:
|
|
7
|
+
#
|
|
8
|
+
# class ReceiveJob
|
|
9
|
+
# include Anway::Worker
|
|
10
|
+
#
|
|
11
|
+
# event 'mail.receive'
|
|
12
|
+
# queue :default
|
|
13
|
+
# recover 16
|
|
14
|
+
#
|
|
15
|
+
# def perform(mail_id); end
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# retry is a reserved word in Ruby, so its methods are recover, retries,
|
|
19
|
+
# and attempts: three names for the same key. The other methods have the
|
|
20
|
+
# name of the key. Each call adds one option set, with the merge rules of
|
|
21
|
+
# anway_options. The DSL sets always win over the anway_options sets, in
|
|
22
|
+
# any call order. Without a value, a method returns the option of the
|
|
23
|
+
# class.
|
|
24
|
+
module DSL
|
|
25
|
+
NAMES = (Options::DECLARATION - [:retry]).to_h { |key| [key, key] }.merge(recover: :retry, retries: :retry, attempts: :retry).freeze
|
|
26
|
+
|
|
27
|
+
# topics and cron take one or more values.
|
|
28
|
+
LISTS = %i[topics cron].freeze
|
|
29
|
+
|
|
30
|
+
NONE = Object.new.freeze
|
|
31
|
+
|
|
32
|
+
module ClassMethods
|
|
33
|
+
NAMES.each do |name, key|
|
|
34
|
+
if LISTS.include?(key)
|
|
35
|
+
define_method(name) do |*values|
|
|
36
|
+
return anway_options[key] if values.empty?
|
|
37
|
+
|
|
38
|
+
add_option_set({ key => values.flatten }, dsl: true)
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
define_method(name) do |value = NONE|
|
|
42
|
+
return anway_options[key] if value.equal?(NONE)
|
|
43
|
+
|
|
44
|
+
add_option_set({ key => value }, dsl: true)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/anway/worker.rb
CHANGED
|
@@ -37,6 +37,7 @@ module Anway
|
|
|
37
37
|
class << self
|
|
38
38
|
def included(base)
|
|
39
39
|
base.extend(ClassMethods)
|
|
40
|
+
base.extend(DSL::ClassMethods)
|
|
40
41
|
|
|
41
42
|
register(base) if base.name
|
|
42
43
|
end
|
|
@@ -111,9 +112,18 @@ module Anway
|
|
|
111
112
|
# Without keys, returns the options of the class: the options of the
|
|
112
113
|
# parent class without event, topics, and cron, then each set in call
|
|
113
114
|
# order. event, topics, and cron are always in the result.
|
|
115
|
+
#
|
|
116
|
+
# The sets of Anway::Worker::DSL always win over the sets of
|
|
117
|
+
# anway_options, in any call order.
|
|
114
118
|
def anway_options(**options)
|
|
115
119
|
return declared_options if options.empty?
|
|
116
120
|
|
|
121
|
+
add_option_set(options, dsl: false)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Adds one option set. dsl: true puts it in the sets of
|
|
125
|
+
# Anway::Worker::DSL, which merge after the anway_options sets.
|
|
126
|
+
def add_option_set(options, dsl:)
|
|
117
127
|
Options.check!(options, Options::DECLARATION)
|
|
118
128
|
|
|
119
129
|
# Translates the set now, so that a bad value, such as an on_dead
|
|
@@ -123,9 +133,10 @@ module Anway
|
|
|
123
133
|
options = options.merge(event: event_name(options[:event])) if options.key?(:event)
|
|
124
134
|
old_event = declared_options[:event]
|
|
125
135
|
|
|
126
|
-
(@
|
|
136
|
+
sets = dsl ? (@anway_dsl_sets ||= []) : (@anway_option_sets ||= [])
|
|
137
|
+
sets << options.freeze
|
|
127
138
|
|
|
128
|
-
register_event(old_event) if options.key?(:event)
|
|
139
|
+
register_event(old_event, sets) if options.key?(:event)
|
|
129
140
|
|
|
130
141
|
declared_options
|
|
131
142
|
end
|
|
@@ -213,6 +224,8 @@ module Anway
|
|
|
213
224
|
Anway.push_bulk(jobs)
|
|
214
225
|
end
|
|
215
226
|
|
|
227
|
+
private :add_option_set
|
|
228
|
+
|
|
216
229
|
private
|
|
217
230
|
|
|
218
231
|
# The event, and the push keys: the options of the class, then the
|
|
@@ -228,16 +241,16 @@ module Anway
|
|
|
228
241
|
def declared_options
|
|
229
242
|
parent = superclass.respond_to?(:anway_options) ? superclass.anway_options.except(*OWN_KEYS) : {}
|
|
230
243
|
|
|
231
|
-
Options.merge({ event: name, topics: [], cron: [] }, parent, *@anway_option_sets).freeze
|
|
244
|
+
Options.merge({ event: name, topics: [], cron: [] }, parent, *@anway_option_sets, *@anway_dsl_sets).freeze
|
|
232
245
|
end
|
|
233
246
|
|
|
234
247
|
# A set with an event that another class has does not stay.
|
|
235
|
-
def register_event(old_event)
|
|
248
|
+
def register_event(old_event, sets)
|
|
236
249
|
return unless name
|
|
237
250
|
|
|
238
251
|
Worker.register(self, old_event: old_event)
|
|
239
252
|
rescue ArgumentError
|
|
240
|
-
|
|
253
|
+
sets.pop
|
|
241
254
|
|
|
242
255
|
raise
|
|
243
256
|
end
|
data/lib/anway.rb
CHANGED
|
@@ -10,6 +10,7 @@ require_relative 'anway/connection'
|
|
|
10
10
|
require_relative 'anway/pool'
|
|
11
11
|
require_relative 'anway/client'
|
|
12
12
|
require_relative 'anway/worker'
|
|
13
|
+
require_relative 'anway/worker/dsl'
|
|
13
14
|
require_relative 'anway/executor'
|
|
14
15
|
require_relative 'anway/queues'
|
|
15
16
|
require_relative 'anway/runner'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: anway
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thadeu
|
|
@@ -59,6 +59,7 @@ files:
|
|
|
59
59
|
- lib/anway/version.rb
|
|
60
60
|
- lib/anway/web.rb
|
|
61
61
|
- lib/anway/worker.rb
|
|
62
|
+
- lib/anway/worker/dsl.rb
|
|
62
63
|
- lib/generators/anway/install/install_generator.rb
|
|
63
64
|
- lib/generators/anway/install/templates/anway
|
|
64
65
|
- lib/generators/anway/install/templates/anway.yml
|