postburner 1.0.0.pre.7 → 1.0.0.pre.8
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 +43 -0
- data/lib/postburner/active_job/adapter.rb +21 -1
- data/lib/postburner/configuration.rb +25 -1
- data/lib/postburner/version.rb +1 -1
- data/lib/postburner/workers/base.rb +5 -10
- data/lib/postburner/workers/worker.rb +2 -2
- data/lib/postburner.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38a691a9f1e5d99c0d6f19cbe7c4c605bd1e570787d1cb7c8b5ee862b3efa84c
|
|
4
|
+
data.tar.gz: 962f60d03662ee7dc119503f190d5f6376cd7be35a14b52c140d75141a837b0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4a3bdd33be9342b9e521ef806baff7e27375891f73487daba929aefc9abf1ac888dd037bf764b46c839b8f904e9b766558f1705d2eebbab612a9b27d1562577
|
|
7
|
+
data.tar.gz: 69e36547fbc73cab99f8d9991a62825019f4d201e041fdf7cfb508fd885c0ce3dc6b6801f6e1897fe4037877b0649718b7089566b42a68d5e622302797a4c3ac
|
data/README.md
CHANGED
|
@@ -127,6 +127,13 @@ beanstalkd -l 127.0.0.1 -p 11300 # Start beanstalkd
|
|
|
127
127
|
bundle exec rails generate postburner:install
|
|
128
128
|
bundle exec rails db:migrate
|
|
129
129
|
|
|
130
|
+
# application.rb
|
|
131
|
+
config.active_job.queue_adapter = :postburner
|
|
132
|
+
# Note: Postburner auto-prefixes queue names with "postburner.{env}." similar to:
|
|
133
|
+
#config.active_job.queue_name_prefix = Postburner.tube_prefix(Rails.env) # i.e. "postburner.#{Rails.env}"
|
|
134
|
+
config.action_mailer.deliver_later_queue_name = 'mailers' # gets prefixed by config.active_job.queue_name_prefix
|
|
135
|
+
|
|
136
|
+
|
|
130
137
|
bundle exec postburner # start with bin/postburner
|
|
131
138
|
bundle exec rake postburner:work # or with rake task
|
|
132
139
|
```
|
|
@@ -1084,6 +1091,42 @@ production: # <- environment config, i.e. defaults
|
|
|
1084
1091
|
- mailers
|
|
1085
1092
|
```
|
|
1086
1093
|
|
|
1094
|
+
### Queue Names
|
|
1095
|
+
|
|
1096
|
+
Postburner automatically prefixes all queue names with `postburner.{env}.` to create Beanstalkd tube names. This namespacing prevents collisions when multiple applications share the same Beanstalkd server.
|
|
1097
|
+
|
|
1098
|
+
**The same base queue name is used everywhere:**
|
|
1099
|
+
|
|
1100
|
+
| Context | Syntax | Beanstalkd Tube |
|
|
1101
|
+
|---------|--------|-----------------|
|
|
1102
|
+
| ActiveJob | `queue_as :mailers` | `postburner.production.mailers` |
|
|
1103
|
+
| Postburner::Job | `queue 'mailers'` | `postburner.production.mailers` |
|
|
1104
|
+
| postburner.yml | `queues: [mailers]` | `postburner.production.mailers` |
|
|
1105
|
+
|
|
1106
|
+
**Example:**
|
|
1107
|
+
|
|
1108
|
+
```ruby
|
|
1109
|
+
# app/jobs/welcome_email_job.rb
|
|
1110
|
+
class WelcomeEmailJob < ApplicationJob
|
|
1111
|
+
queue_as :mailers # Uses base name 'mailers'
|
|
1112
|
+
end
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
```yaml
|
|
1116
|
+
# config/postburner.yml
|
|
1117
|
+
production:
|
|
1118
|
+
workers:
|
|
1119
|
+
email_worker:
|
|
1120
|
+
queues:
|
|
1121
|
+
- mailers # Same base name 'mailers'
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
Both refer to the Beanstalkd tube `postburner.production.mailers`.
|
|
1125
|
+
|
|
1126
|
+
**Naming convention:** Use underscores for multi-word queue names (e.g., `background_jobs`, `high_priority`). Avoid hyphens as they can cause issues with some Beanstalkd client libraries.
|
|
1127
|
+
|
|
1128
|
+
**Important:** No need to set `config.active_job.queue_name_prefix` - Postburner handles prefixing automatically, when jobs are enqueued with postburner.
|
|
1129
|
+
|
|
1087
1130
|
### Queue Configuration Methods
|
|
1088
1131
|
|
|
1089
1132
|
For `Postburner::Job` subclasses (and backwards compatibility):
|
|
@@ -8,6 +8,24 @@ module ActiveJob
|
|
|
8
8
|
# - **Default mode**: Fast execution via Beanstalkd only
|
|
9
9
|
# - **Tracked mode** (opt-in): Full PostgreSQL audit trail
|
|
10
10
|
#
|
|
11
|
+
# ## Queue Name Prefixing
|
|
12
|
+
#
|
|
13
|
+
# Postburner automatically prefixes all queue names with `postburner.{env}.`
|
|
14
|
+
# to create Beanstalkd tube names. This means:
|
|
15
|
+
#
|
|
16
|
+
# - `queue_as :default` → tube `postburner.production.default`
|
|
17
|
+
# - `queue_as :mailers` → tube `postburner.production.mailers`
|
|
18
|
+
#
|
|
19
|
+
# The same base queue names are used across:
|
|
20
|
+
# - ActiveJob: `queue_as :default`
|
|
21
|
+
# - Postburner::Job: `queue 'default'`
|
|
22
|
+
# - config/postburner.yml: `queues: [default]`
|
|
23
|
+
#
|
|
24
|
+
# All refer to the same Beanstalkd tube after prefixing.
|
|
25
|
+
#
|
|
26
|
+
# @note Do NOT set `config.active_job.queue_name_prefix` - Postburner
|
|
27
|
+
# handles prefixing automatically via {#expand_tube_name}.
|
|
28
|
+
#
|
|
11
29
|
# ## Usage
|
|
12
30
|
#
|
|
13
31
|
# @example Configure in Rails
|
|
@@ -16,6 +34,8 @@ module ActiveJob
|
|
|
16
34
|
#
|
|
17
35
|
# @example Default job (fast)
|
|
18
36
|
# class SendEmail < ApplicationJob
|
|
37
|
+
# queue_as :mailers # → postburner.production.mailers
|
|
38
|
+
#
|
|
19
39
|
# def perform(user_id)
|
|
20
40
|
# # No PostgreSQL overhead, executes quickly
|
|
21
41
|
# end
|
|
@@ -24,7 +44,7 @@ module ActiveJob
|
|
|
24
44
|
# @example Tracked job (opt-in for audit trail)
|
|
25
45
|
# class ProcessPayment < ApplicationJob
|
|
26
46
|
# include Postburner::Tracked
|
|
27
|
-
#
|
|
47
|
+
# queue_as :critical # → postburner.production.critical
|
|
28
48
|
#
|
|
29
49
|
# def perform(payment_id)
|
|
30
50
|
# log "Processing payment..."
|
|
@@ -184,10 +184,34 @@ module Postburner
|
|
|
184
184
|
def expand_tube_name(queue_name = nil, env = nil)
|
|
185
185
|
env ||= defined?(Rails) ? Rails.env : nil
|
|
186
186
|
queue_name ||= @default_queue
|
|
187
|
+
[
|
|
188
|
+
tube_prefix(env),
|
|
189
|
+
queue_name,
|
|
190
|
+
].compact.join('.')
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Returns the Beanstalkd tube name prefix for the given environment.
|
|
194
|
+
#
|
|
195
|
+
# Postburner automatically prefixes all queue names with this value.
|
|
196
|
+
# The ActiveJob adapter expands queue names using this prefix, so
|
|
197
|
+
# `queue_as :default` becomes `postburner.production.default` in production.
|
|
198
|
+
#
|
|
199
|
+
# @param env [String, Symbol, nil] Environment name (defaults to Rails.env or nil)
|
|
200
|
+
#
|
|
201
|
+
# @return [String] Tube prefix (e.g., "postburner.production")
|
|
202
|
+
#
|
|
203
|
+
# @example
|
|
204
|
+
# config.tube_prefix('production') # => "postburner.production"
|
|
205
|
+
# config.tube_prefix # => "postburner.test" (in test env)
|
|
206
|
+
#
|
|
207
|
+
# @note Do not set ActiveJob's `queue_name_prefix` - Postburner handles
|
|
208
|
+
# queue name expansion automatically via the adapter.
|
|
209
|
+
#
|
|
210
|
+
def tube_prefix(env = nil)
|
|
211
|
+
env ||= defined?(Rails) ? Rails.env : nil
|
|
187
212
|
[
|
|
188
213
|
'postburner',
|
|
189
214
|
env,
|
|
190
|
-
queue_name,
|
|
191
215
|
].compact.join('.')
|
|
192
216
|
end
|
|
193
217
|
|
data/lib/postburner/version.rb
CHANGED
|
@@ -189,21 +189,16 @@ module Postburner
|
|
|
189
189
|
[2 ** retry_count, 3600].min
|
|
190
190
|
end
|
|
191
191
|
|
|
192
|
-
# Watches
|
|
192
|
+
# Watches all configured queues in Beanstalkd.
|
|
193
193
|
#
|
|
194
194
|
# @param connection [Postburner::Connection] Beanstalkd connection
|
|
195
|
-
# @param queue_name [String, nil] Optional specific queue name to watch (watches all if nil)
|
|
196
195
|
#
|
|
197
196
|
# @return [void]
|
|
198
197
|
#
|
|
199
|
-
def watch_queues(connection,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
else
|
|
204
|
-
tube_names = config.expanded_tube_names
|
|
205
|
-
connection.beanstalk.tubes.watch!(*tube_names)
|
|
206
|
-
end
|
|
198
|
+
def watch_queues(connection, queue_names=nil)
|
|
199
|
+
tube_names = queue_names.map { |q| config.expand_tube_name(q) }
|
|
200
|
+
tube_names = config.expanded_tube_names if tube_names.empty?
|
|
201
|
+
connection.beanstalk.tubes.watch!(*tube_names)
|
|
207
202
|
end
|
|
208
203
|
end
|
|
209
204
|
end
|
|
@@ -165,7 +165,7 @@ module Postburner
|
|
|
165
165
|
timeout = worker_config[:timeout]
|
|
166
166
|
|
|
167
167
|
# Watch all configured queues
|
|
168
|
-
watch_queues(connection,
|
|
168
|
+
watch_queues(connection, config.queue_names)
|
|
169
169
|
|
|
170
170
|
until shutdown? || (@gc_limit && @jobs_processed.value >= @gc_limit)
|
|
171
171
|
begin
|
|
@@ -329,7 +329,7 @@ module Postburner
|
|
|
329
329
|
timeout = worker_config[:timeout]
|
|
330
330
|
|
|
331
331
|
# Watch all configured queues
|
|
332
|
-
watch_queues(connection,
|
|
332
|
+
watch_queues(connection, config.queue_names)
|
|
333
333
|
|
|
334
334
|
until shutdown? || (gc_limit && jobs_processed.value >= gc_limit)
|
|
335
335
|
begin
|
data/lib/postburner.rb
CHANGED
|
@@ -448,6 +448,25 @@ module Postburner
|
|
|
448
448
|
@__watched_tubes ||= watched_tube_names.map { |tube_name| connection.tubes[tube_name] }
|
|
449
449
|
end
|
|
450
450
|
|
|
451
|
+
# Returns the Beanstalkd tube name prefix for the given environment.
|
|
452
|
+
#
|
|
453
|
+
# Delegates to {Configuration#tube_prefix}. Postburner automatically
|
|
454
|
+
# prefixes all queue names with this value.
|
|
455
|
+
#
|
|
456
|
+
# @param env [String, Symbol, nil] Environment name (defaults to Rails.env or nil)
|
|
457
|
+
#
|
|
458
|
+
# @return [String] Tube prefix (e.g., "postburner.production")
|
|
459
|
+
#
|
|
460
|
+
# @example
|
|
461
|
+
# Postburner.tube_prefix('production') # => "postburner.production"
|
|
462
|
+
# Postburner.tube_prefix # => "postburner.test" (in test env)
|
|
463
|
+
#
|
|
464
|
+
# @see Configuration#tube_prefix
|
|
465
|
+
#
|
|
466
|
+
def self.tube_prefix(env = nil)
|
|
467
|
+
configuration.tube_prefix(env)
|
|
468
|
+
end
|
|
469
|
+
|
|
451
470
|
# Returns detailed statistics about Beanstalkd tubes.
|
|
452
471
|
#
|
|
453
472
|
# Collects job counts (ready, delayed, buried, reserved) for each tube
|