postburner 1.0.0.pre.20 → 1.0.0.pre.21

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: a8b142c8e0e5a1f5ed9235d5514f262b2ca899900a359d4a0372a7dc484031cc
4
- data.tar.gz: dcaa400529791fef277deba18df58fb1bbf92f306d3b08c1b0ccc8f48f86e927
3
+ metadata.gz: 0cea7097e8d2f498dcf2c63fefa199fa1926399e93d773acb3b6527f4309d7a0
4
+ data.tar.gz: 98133fa630e92291a5c36c327693b7f1b0b1602e2d1ca1a62977f85b5e654ae3
5
5
  SHA512:
6
- metadata.gz: 3668f883407fb9671ab430c99a0d1dadda83e89c24bfa6ed336dd9e180ae3c4d32178f985c9d95ee244c380dc74d131990383e294af4ce5d5794a5fa180a5453
7
- data.tar.gz: 676d4fd685ddf5cdd7be6ab1693231eb1bf4311d7707dcd85fc968b756eeda0b448bc6c4e6899c7032c17f684d2f4678503113cf50a52173851864ecd0e187d8
6
+ metadata.gz: e170a612372e0687405a1e4bb61a5b71e159c256fe258b889a76d9b0d8b35adaef2e362666db70b51045becf1d125b3d115e0fb86cbf021f0e085a7a5f16e3b3
7
+ data.tar.gz: 7754802face80f7e39de89ffc5be7e44197376a53c5ac1bc78f890230ecd840ff0211fce3f489ff8ce9a4298e35084171064ae73882060025c40494371e4075d
data/README.md CHANGED
@@ -2079,7 +2079,20 @@ end
2079
2079
 
2080
2080
  ### Tube Statistics and Management
2081
2081
 
2082
- Postburner provides methods to inspect and manage Beanstalkd tubes:
2082
+ Postburner provides methods to inspect and manage Beanstalkd tubes.
2083
+
2084
+ **Note:** Beanstalkd tubes are created lazily - they only exist when jobs have been put into them. This means configured queues (e.g., `default`, `mailers`) won't appear in stats until at least one job has been enqueued to them. The scheduler tube appears immediately because the watchdog job is created on worker startup.
2085
+
2086
+ **Example worker startup output:**
2087
+
2088
+ ```
2089
+ [Postburner::Worker] Starting worker 'default'...
2090
+ [Postburner::Worker] Queues: default, mailers
2091
+ [Postburner::Worker] Startup stats: ready=1 delayed=0 buried=0 reserved=0 total=1
2092
+ postburner.development.scheduler: ready=1 delayed=0 buried=0 reserved=0 total=1
2093
+ ```
2094
+
2095
+ Note that `default` and `mailers` queues are configured but don't appear in stats yet - they'll appear once jobs are enqueued to them.
2083
2096
 
2084
2097
  **View tube statistics:**
2085
2098
 
@@ -2099,6 +2112,31 @@ stats = Postburner.stats(['postburner.production.critical'])
2099
2112
  # => { tubes: [...], totals: {...} }
2100
2113
  ```
2101
2114
 
2115
+ **Understanding lazy tube creation:**
2116
+
2117
+ ```ruby
2118
+ # Fresh Beanstalkd, no jobs queued yet - only scheduler tube exists
2119
+ stats = Postburner.stats
2120
+ # => {
2121
+ # tubes: [
2122
+ # { name: "postburner.development.scheduler", ready: 1, delayed: 0, ... }
2123
+ # ],
2124
+ # totals: { ready: 1, delayed: 0, buried: 0, reserved: 0, total: 1 }
2125
+ # }
2126
+ # Note: 'default' and 'mailers' tubes don't appear yet!
2127
+
2128
+ # After queueing a job to 'default':
2129
+ MyJob.perform_later(123)
2130
+ stats = Postburner.stats
2131
+ # => {
2132
+ # tubes: [
2133
+ # { name: "postburner.development.default", ready: 1, ... },
2134
+ # { name: "postburner.development.scheduler", ready: 1, ... }
2135
+ # ],
2136
+ # totals: { ready: 2, ... }
2137
+ # }
2138
+ ```
2139
+
2102
2140
  **Clear jobs from tubes:**
2103
2141
 
2104
2142
  For safety, `clear_jobs!` requires you to explicitly specify which tubes to clear. This prevents accidentally clearing tubes from other applications sharing the same Beanstalkd server.
@@ -61,6 +61,16 @@ module Postburner
61
61
  # @api private
62
62
  def load_configuration
63
63
  config_path = File.expand_path(options[:config], root_directory)
64
+
65
+ unless File.exist?(config_path)
66
+ logger.warn "[Postburner] Configuration missing: #{config_path}"
67
+ logger.debug "[Postburner] No configuration file found. (Use --config to specify a different path)"
68
+ config = Postburner::Configuration.new
69
+ Postburner.configuration = config
70
+ return config
71
+ end
72
+
73
+ logger.info "[Postburner] Configuration loaded: #{config_path}"
64
74
  config = Postburner::Configuration.load_yaml(config_path, options[:env], options[:worker])
65
75
  Postburner.configuration = config
66
76
  config
@@ -97,8 +107,6 @@ module Postburner
97
107
  # @return [void]
98
108
  # @api private
99
109
  def log_configuration(config)
100
- config_path = File.expand_path(options[:config], root_directory)
101
- config.logger.info "[Postburner] Configuration: #{config_path}"
102
110
  config.logger.info "[Postburner] Environment: #{options[:env]}"
103
111
  if options[:worker] || options[:queues].nil?
104
112
  worker_label = options[:worker] || "(auto-selected: #{config.worker_config[:name]})"
@@ -1,3 +1,3 @@
1
1
  module Postburner
2
- VERSION = '1.0.0.pre.20'
2
+ VERSION = '1.0.0.pre.21'
3
3
  end
@@ -140,13 +140,17 @@ module Postburner
140
140
 
141
141
  # Checks if this process has been orphaned (parent died).
142
142
  #
143
- # When the parent process dies, the kernel re-parents children to init (PID 1).
144
- # Detecting this allows forked children to exit gracefully instead of running
145
- # indefinitely as orphans.
143
+ # When the parent process dies, the kernel re-parents children to init (PID 1)
144
+ # or a subreaper. Detecting this allows forked children to exit gracefully
145
+ # instead of running indefinitely as orphans.
146
146
  #
147
- # @return [Boolean] true if parent PID is 1, false otherwise
147
+ # Compares current parent PID against the PID recorded at fork time
148
+ # (@parent_pid), which handles the case where the parent process itself
149
+ # is PID 1 (e.g., running as a container entrypoint).
150
+ #
151
+ # @return [Boolean] true if parent PID changed since fork, false otherwise
148
152
  def orphaned?
149
- Process.ppid == 1
153
+ @parent_pid && Process.ppid != @parent_pid
150
154
  end
151
155
 
152
156
  # Calculates exponential backoff sleep duration for reconnection attempts.
@@ -390,7 +394,11 @@ module Postburner
390
394
  # @return [void]
391
395
  # @api private
392
396
  def spawn_fork(fork_num)
393
- pid = fork { run_fork(fork_num) }
397
+ parent_pid = Process.pid
398
+ pid = fork do
399
+ @parent_pid = parent_pid
400
+ run_fork(fork_num)
401
+ end
394
402
  @children[pid] = fork_num
395
403
  logger.info "[Postburner::Worker] Spawned fork #{fork_num} (pid: #{pid})"
396
404
  end
@@ -880,6 +888,11 @@ module Postburner
880
888
  # Shows aggregate totals on first line, followed by per-tube breakdown.
881
889
  # Used at worker startup and shutdown to track job backlog.
882
890
  #
891
+ # @note Only tubes that exist in Beanstalkd are shown. Beanstalkd tubes are
892
+ # created lazily when jobs are first enqueued, so configured queues like
893
+ # 'default' or 'mailers' won't appear until jobs have been queued to them.
894
+ # The scheduler tube typically appears because the watchdog is created on startup.
895
+ #
883
896
  # @param label [String] Label for the stats (e.g., "Startup", "Shutdown")
884
897
  # @return [void]
885
898
  # @api private
data/lib/postburner.rb CHANGED
@@ -528,6 +528,11 @@ module Postburner
528
528
  # Collects job counts (ready, delayed, buried, reserved) for each tube
529
529
  # and provides aggregate totals across all tubes.
530
530
  #
531
+ # @note Beanstalkd tubes are created lazily - they only exist when jobs have been
532
+ # put into them. Tubes that don't exist yet are silently skipped and won't appear
533
+ # in the results. This means configured queues (e.g., 'default', 'mailers') won't
534
+ # appear in stats until at least one job has been enqueued to them.
535
+ #
531
536
  # @param tube_names [Array<String>, nil] Specific tube names to inspect, or nil for all tubes
532
537
  #
533
538
  # @return [Hash] Statistics hash with keys:
@@ -543,7 +548,17 @@ module Postburner
543
548
  #
544
549
  # @example Get stats for specific tubes
545
550
  # stats = Postburner.stats(Postburner.watched_tube_names)
546
- # stats[:tubes].size # => 3
551
+ # stats[:tubes].size # => 3 (only tubes that exist)
552
+ #
553
+ # @example Understanding lazy tube creation
554
+ # # Fresh Beanstalkd with no jobs queued yet:
555
+ # Postburner.stats(Postburner.watched_tube_names)
556
+ # # => { tubes: [], totals: { ready: 0, delayed: 0, ... } }
557
+ #
558
+ # # After queueing a job to 'default':
559
+ # MyJob.perform_later(123)
560
+ # Postburner.stats(Postburner.watched_tube_names)
561
+ # # => { tubes: [{ name: "postburner.development.default", ready: 1, ... }], ... }
547
562
  #
548
563
  def self.stats(tube_names = nil)
549
564
  connected do |conn|
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.20
4
+ version: 1.0.0.pre.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith