postburner 1.0.0.pre.7 → 1.0.0.pre.9

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: 1d37676412b662bd876f2d2d09ac57e09876e5f0d8a7186c37f4f71f3d40ad89
4
- data.tar.gz: 7c9e1badc1628b5cab1edaa164e449d7a926e65198009773a702a3b6f49888cd
3
+ metadata.gz: f609643606243463d7e6ad371fe5afc8efe7e944359a58fcc9cbe1d92d6c68dd
4
+ data.tar.gz: 57691caf6ca731bdc731c376d724fc466b9690d07594632c607a85a34bb3a9d5
5
5
  SHA512:
6
- metadata.gz: b7bafbb9a871ce492a3f36537b237bbcb0a38e5291065384d2d2c2003bde2ebd078e9f2fd5455023bd9d81b38701a391b09d4dbeb336bfb7759e8c550497e5e9
7
- data.tar.gz: 9515f40b1fe1e1782dd4a9fc6fd0c5e78e6a30c6678f656d6534eb2344360ec2c03ca745a0aedf7e3e3ec676a1d9edd092d8ff0db5b50966d24ade078496d440
6
+ metadata.gz: 1190b558cfe4f4dda02dc94855ea5a7eb87196b5c91735b357c8322542d3e8b952fd8f137474ab582abeff6c9d43016f1fc6c12d50884f9bd958a15208d211cb
7
+ data.tar.gz: 60d6106b1f646ea98130bb19f0ac6c625ccbe99a0bd7aba96901e00ef54389da93d6bdcb24f617a5d1ca34db1ec543700c07201170de7d990d3fc7b951e8e2f8
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
- # tracked # Enables PostgreSQL tracking
47
+ # queue_as :critical # postburner.production.critical
28
48
  #
29
49
  # def perform(payment_id)
30
50
  # log "Processing payment..."
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'erb'
4
+
3
5
  module Postburner
4
6
  # Configuration system for Postburner workers and connections.
5
7
  #
@@ -54,7 +56,10 @@ module Postburner
54
56
  }
55
57
  end
56
58
 
57
- # Loads configuration from a YAML file.
59
+ # Loads configuration from a YAML file with ERB support.
60
+ #
61
+ # Supports ERB templating like Rails' database.yml, allowing environment
62
+ # variables and Ruby expressions in configuration.
58
63
  #
59
64
  # @param path [String] Path to YAML configuration file
60
65
  # @param env [String] Environment name (e.g., 'production', 'development')
@@ -73,10 +78,10 @@ module Postburner
73
78
  # @example Multiple workers (must specify)
74
79
  # config = Postburner::Configuration.load_yaml('config/postburner.yml', 'production', 'imports')
75
80
  #
76
- # @example config/postburner.yml example
81
+ # @example config/postburner.yml with ERB
77
82
  #
78
83
  # default: &default
79
- # beanstalk_url: beanstalk://localhost:11300
84
+ # beanstalk_url: <%= ENV.fetch('BEANSTALK_URL', 'beanstalk://localhost:11300') %>
80
85
  # default_priority: 131072 # change default priority from 65536 to 131072
81
86
  #
82
87
  # production: # <- environment config, i.e. defaults
@@ -97,7 +102,7 @@ module Postburner
97
102
  # - data_processing
98
103
  #
99
104
  def self.load_yaml(path, env = 'development', worker_name = nil)
100
- yaml = YAML.load_file(path, aliases: true)
105
+ yaml = YAML.load(ERB.new(File.read(path)).result, aliases: true)
101
106
  # env_config = top-level environment config (development:, production:, etc.)
102
107
  env_config = yaml[env.to_s] || yaml[env.to_sym]
103
108
 
@@ -184,10 +189,34 @@ module Postburner
184
189
  def expand_tube_name(queue_name = nil, env = nil)
185
190
  env ||= defined?(Rails) ? Rails.env : nil
186
191
  queue_name ||= @default_queue
192
+ [
193
+ tube_prefix(env),
194
+ queue_name,
195
+ ].compact.join('.')
196
+ end
197
+
198
+ # Returns the Beanstalkd tube name prefix for the given environment.
199
+ #
200
+ # Postburner automatically prefixes all queue names with this value.
201
+ # The ActiveJob adapter expands queue names using this prefix, so
202
+ # `queue_as :default` becomes `postburner.production.default` in production.
203
+ #
204
+ # @param env [String, Symbol, nil] Environment name (defaults to Rails.env or nil)
205
+ #
206
+ # @return [String] Tube prefix (e.g., "postburner.production")
207
+ #
208
+ # @example
209
+ # config.tube_prefix('production') # => "postburner.production"
210
+ # config.tube_prefix # => "postburner.test" (in test env)
211
+ #
212
+ # @note Do not set ActiveJob's `queue_name_prefix` - Postburner handles
213
+ # queue name expansion automatically via the adapter.
214
+ #
215
+ def tube_prefix(env = nil)
216
+ env ||= defined?(Rails) ? Rails.env : nil
187
217
  [
188
218
  'postburner',
189
219
  env,
190
- queue_name,
191
220
  ].compact.join('.')
192
221
  end
193
222
 
@@ -1,3 +1,3 @@
1
1
  module Postburner
2
- VERSION = '1.0.0.pre.7'
2
+ VERSION = '1.0.0.pre.9'
3
3
  end
@@ -189,21 +189,16 @@ module Postburner
189
189
  [2 ** retry_count, 3600].min
190
190
  end
191
191
 
192
- # Watches the configured queues in Beanstalkd.
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, queue_name = nil)
200
- if queue_name
201
- tube_name = config.expand_tube_name(queue_name)
202
- connection.beanstalk.tubes.watch!(tube_name)
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, *config.queue_names)
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, *config.queue_names)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postburner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.7
4
+ version: 1.0.0.pre.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith