postburner 1.0.0.pre.10 → 1.0.0.pre.11

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: 5d70db5c9a39d758ab94b917a9bddd996ccaa5de1520180ab07d0e228ea1ed24
4
- data.tar.gz: a2df7d54ebf98e399d212d98f3aa7c3589f68ae7912b38b31bf060bbe1350928
3
+ metadata.gz: 9b5f90445398301e11e085449c666e936228297490c7b301bc84f7c41a1d1e38
4
+ data.tar.gz: f8cf070edea1a1c568d737ac04190b13ec23de982b5885c037bb2c6814b42903
5
5
  SHA512:
6
- metadata.gz: 1346d6ad7b6edb4abaff3eaba39c0bb5572bb9042cec8c6e31876c8b202da6b841d995f567b990545d74adc5d45c5040752077af5acd785bdf1a9fcce4336299
7
- data.tar.gz: a00d649a8f2dbf7e0c5ed0ab589b6d365cd3decc9dadf33bd8a1c73865ca5e5e390823ff98d707b620c714abf41ccd648729d283a8a950dfe6dd1313c759f2aa
6
+ metadata.gz: 043701c81dc62b4e4eb548dcd16df2d697c484f73bf7bc7bb9c22970d549770aa3469629f9902550d13e4f9fd8592d6a7a5d71cbda2c7b8e1401ea8297a25f76
7
+ data.tar.gz: 6ab252caef040ac51fb52b380f4e04460632a6dc61dbf20a31db951a9df378d08cea8b744287876a2d09e3a5c646ff6063266514aea993bb5e7f34e5583ff6fa
data/README.md CHANGED
@@ -1383,8 +1383,8 @@ Postburner uses [Beaneater](https://github.com/beanstalkd/beaneater) as the Ruby
1383
1383
  ```ruby
1384
1384
  # Get a cached Beaneater connection (returns Beaneater instance)
1385
1385
  conn = Postburner.connection
1386
- conn.tubes.to_a # List all tubes
1387
- conn.stats # Server statistics
1386
+ conn.tubes.to_a # List all tubes
1387
+ conn.beanstalk.stats # Server statistics
1388
1388
 
1389
1389
  # Block form - yields connection, recommended for one-off operations
1390
1390
  Postburner.connected do |conn|
@@ -125,7 +125,7 @@ module ActiveJob
125
125
  )
126
126
 
127
127
  # Calculate delay for Beanstalkd
128
- delay = timestamp ? [(timestamp.to_f - Time.now.to_f).to_i, 0].max : 0
128
+ delay = timestamp ? [(timestamp.to_f - Time.zone.now.to_f).to_i, 0].max : 0
129
129
 
130
130
  # Queue to Beanstalkd with minimal payload
131
131
  Postburner.connected do |conn|
@@ -160,7 +160,7 @@ module ActiveJob
160
160
  # @return [void]
161
161
  #
162
162
  def enqueue_default(job, timestamp)
163
- delay = timestamp ? [(timestamp.to_f - Time.now.to_f).to_i, 0].max : 0
163
+ delay = timestamp ? [(timestamp.to_f - Time.zone.now.to_f).to_i, 0].max : 0
164
164
 
165
165
  Postburner.connected do |conn|
166
166
  tube_name = expand_tube_name(job.queue_name)
@@ -0,0 +1,53 @@
1
+ module Postburner
2
+ class Tube
3
+ def initialize(tube)
4
+ @tube = tube
5
+ end
6
+
7
+ # Get all tubes as Postburner::Tube instances.
8
+ #
9
+ def self.all
10
+ Postburner.connection.tubes.all.map { |tube| self.new(tube) }
11
+ end
12
+
13
+ # Get all peeked ids across all known tubes.
14
+ #
15
+ def self.peek_ids
16
+ self.all.map(&:peek_ids).flatten.sort
17
+ end
18
+
19
+ # Get all peeked ids.
20
+ #
21
+ def peek_ids
22
+ [ :buried, :ready, :delayed ].map { |type| @tube.peek(type) }.
23
+ reject(&:nil?).map(&:id).map(&:to_i)
24
+ end
25
+
26
+ # Get paginated array of jobs.
27
+ #
28
+ # Attempts to do this efficiently as possible, by peeking at known
29
+ # ids and exiting when count has been fulfilled.
30
+ #
31
+ # Just pass the last known id to after for the next batch.
32
+ #
33
+ def jobs(count=20, limit: 1000, after: nil)
34
+ stats = @tube.stats
35
+ jobs = Array.new
36
+
37
+ min_known = (
38
+ peek_ids.any? ? self.peek_ids.min : self.class.peek_ids.min
39
+ ).to_i
40
+ min = after ? after.to_i + 1 : min_known
41
+ max = min + limit
42
+
43
+ for i in min..max
44
+ job = @tube.client.jobs.find(i)
45
+ jobs << job if job && stats[:name] == job.stats[:tube]
46
+ break if jobs.length >= count
47
+ end
48
+
49
+ return jobs
50
+ end
51
+
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Postburner
2
- VERSION = '1.0.0.pre.10'
2
+ VERSION = '1.0.0.pre.11'
3
3
  end
@@ -374,8 +374,8 @@ module Postburner
374
374
  end
375
375
 
376
376
  # Wait up to 30 seconds for children to exit
377
- timeout = Time.now + 30
378
- until @children.empty? || Time.now > timeout
377
+ timeout = Time.zone.now + 30
378
+ until @children.empty? || Time.zone.now > timeout
379
379
  pid, status = Process.wait2(-1, Process::WNOHANG)
380
380
  @children.delete(pid) if pid
381
381
  sleep 0.5
data/lib/postburner.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "postburner/version"
2
2
  require "postburner/configuration"
3
3
  require "postburner/connection"
4
+ require "postburner/tube"
4
5
  require "postburner/beanstalkd"
5
6
  require "postburner/tracked"
6
7
  require "postburner/active_job/payload"
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.10
4
+ version: 1.0.0.pre.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith
@@ -154,6 +154,7 @@ files:
154
154
  - lib/postburner/strategies/test_queue.rb
155
155
  - lib/postburner/time_helpers.rb
156
156
  - lib/postburner/tracked.rb
157
+ - lib/postburner/tube.rb
157
158
  - lib/postburner/version.rb
158
159
  - lib/postburner/workers/base.rb
159
160
  - lib/postburner/workers/worker.rb