anway 0.6.0-x86_64-linux-gnu → 0.7.1-x86_64-linux-gnu

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2b3873a30b7e93e068e421393640af582073e4b84fe9c031c66f53d54be81d5
4
- data.tar.gz: 68f71d306315096d7d3fd9f7ac0e4ad9ccdffc411e0f68964b73dd004a8f9e2c
3
+ metadata.gz: 72d09f70f3a0c71f8767eba09c749335dde48985aabd448a47939b425da24189
4
+ data.tar.gz: e59a8f50439aba5d7cc65969f5484ad199baddee3c27752ecb0705137a68704e
5
5
  SHA512:
6
- metadata.gz: bf9411c58a85bb62bfeb31fd2c53d33305a528e2f54d4acc44ec1a32d0450d654ba6caf113a69ea47633777295e66eb068f5209136104650563759d7dae54fe2
7
- data.tar.gz: 6bee99094535a940bfef8d137bd63da7fe22df610c092ef754be9d7da6ce8f90468a53ccec44cbac54f2fad53d82f881f830b0941616437d0053273b7246839a
6
+ metadata.gz: aeeef8ba6b987826170f71ecae47a902c7d4cc35c72723c36b93fac4b78d228b1c64c7acd257bd26a6fab10930ef5a05f23986ab72a8f2c60efb06e65c686b77
7
+ data.tar.gz: 27678d379511d0cdf5f23c632535e69eb40cee94ec9ac8655d8a7ec988c2b67ef58b9d924b2385707de44be45d3cf44f3c1fe1e809c2ad914eea708753500f3c
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
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anway
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.1'
5
5
 
6
6
  # The anway server that the platform gems carry, and that CI tests against.
7
- SERVER_VERSION = '0.6.0'
7
+ SERVER_VERSION = '0.7.0'
8
8
  end
@@ -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
- (@anway_option_sets ||= []) << options.freeze
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
- @anway_option_sets.pop
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'
data/libexec/anway-server CHANGED
Binary file
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.6.0
4
+ version: 0.7.1
5
5
  platform: x86_64-linux-gnu
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