sucker_punch 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dfa20a18d1c51b637e21b3b7aa657979a73036964ed8e6542e2b759ebd5adce
4
- data.tar.gz: 95aea0e08f0a4a3e9048836c820cd4bde237ac067aa3ad71c2de728fd3ffb8cf
3
+ metadata.gz: 0d35871de54ea5289b5ab0fe2fe36765ca86832dd94d5d698e210978f5d67523
4
+ data.tar.gz: 1ada244fd85ae889316949e711762a9f95fce4518c903f710ec1d7170a900409
5
5
  SHA512:
6
- metadata.gz: e2bcf61e16203c7cd4c2eab46d35ae5f1da65e640564ad65beba14b2b9b4579023546432553c0d75b571265a0e60f0ff71a48bd4c3519f809e42628aec298791
7
- data.tar.gz: 8b660145d51fa187b63ad897a9342dc8955f1cf045b0b03e1138720f912762b35b624fe292d2c0adb9b3a6bf961ad9cae6e29f4044226b37d0c654e257f2353d
6
+ metadata.gz: 8354e67033ac6730b2ea8a3ee7d3f4a0de96787a422707c7ab1ddfff5d04808eae96bb6d220d79cfa9a1c315350cead21cb677a1c34f65034aa6d4a89b8a3d79
7
+ data.tar.gz: cc05894c3e572180f115d8100ab7c4a6992dc399400ee9a47ebbc66c79ddc987ddc81bd74ae7ff81063fa020ed5f940f08d31939ebc36e14376ccdbb7de8334d
@@ -19,16 +19,13 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', 'head', 'jruby', 'truffleruby', 'truffleruby-head']
22
+ ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', 'jruby', 'truffleruby', 'truffleruby-head']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
26
26
 
27
27
  - name: Set up Ruby ${{ matrix.ruby-version }}
28
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
30
- # uses: ruby/setup-ruby@v1
31
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
28
+ uses: ruby/setup-ruby@v1
32
29
  with:
33
30
  ruby-version: ${{ matrix.ruby-version }}
34
31
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 3.1.0
2
+ -------
3
+ - Add a blocking `SuckerPunch::Queue.wait` which waits for all queues to become idle.
4
+
1
5
  3.0.1
2
6
  -------
3
7
  - Opt for keyword parsing using `ruby2_keywords` for compatibility.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sucker Punch
2
2
 
3
- [![Build Status](https://travis-ci.org/brandonhilkert/sucker_punch.svg?branch=master)](https://travis-ci.org/brandonhilkert/sucker_punch)
3
+ [![Build](https://github.com/brandonhilkert/sucker_punch/actions/workflows/build.yml/badge.svg)](https://github.com/brandonhilkert/sucker_punch/actions/workflows/build.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/brandonhilkert/sucker_punch.svg)](https://codeclimate.com/github/brandonhilkert/sucker_punch)
5
5
 
6
6
  Sucker Punch is a single-process Ruby asynchronous processing library.
@@ -28,19 +28,25 @@ etc.).
28
28
 
29
29
  Add this line to your application's Gemfile:
30
30
 
31
- gem 'sucker_punch', '~> 2.0'
31
+ gem 'sucker_punch', '~> 3.0'
32
32
 
33
33
  And then execute:
34
34
 
35
35
  $ bundle
36
36
 
37
+ You can also run (same as two steps above):
38
+
39
+ bundle add sucker_punch
40
+
37
41
  Or install it yourself as:
38
42
 
39
43
  $ gem install sucker_punch
40
44
 
41
45
  ## Backwards Compatibility
42
46
 
43
- In version `~> 2.0.0`, the syntax to enqueue an asynchronous background job has changed from:
47
+ No breaking changes were introduced in version 3.x.
48
+
49
+ In version `~> 2.0.0`, the syntax to enqueue an asynchronous background job was changed from:
44
50
 
45
51
  ```ruby
46
52
  LogJob.new.async.perform(...)
@@ -237,6 +243,15 @@ To configure something other than the default 8 sec.:
237
243
  SuckerPunch.shutdown_timeout = 15 # # of sec. to wait before killing threads
238
244
  ```
239
245
 
246
+ #### Queue Class Methods
247
+
248
+ Sucker Punch leverages concurrent-friendly queues per-process. These class methods operating on all queues might be helpful in some edge cases.
249
+
250
+ - `SuckerPunch::Queue.stats` - Returns a hash keyed by each queue's name with total, busy, and timeout statistics for each queue's `workers` and `jobs`.
251
+ - `SuckerPunch::Queue.clear` - Calls `clear` for each queue. Susceptible to race conditions. Only use in testing.
252
+ - `SuckerPunch::Queue.shutdown_all` - Used with SuckerPunch's `at_exit` hook. Waits for all queues to be idle using the [shutdown timeout](#shutdown-timeout) configuration above.
253
+ - `SuckerPunch::Queue.wait` - Waits for all queues to become idle with no timeout.
254
+
240
255
  #### Timeouts
241
256
 
242
257
  Using `Timeout` causes persistent connections to
@@ -315,6 +330,13 @@ to include the backwards compatibility module in an initializer:
315
330
  require 'sucker_punch/async_syntax'
316
331
  ```
317
332
 
333
+ ## FAQ
334
+
335
+ **What is the difference between `sucker_punch` and `ActiveJob::QueueAdapters::AsyncAdapter`?**
336
+
337
+ Not much at this point. SuckerPunch existed before ActiveJob, but ultimately uses similar code under the covers. I'd recommend using `AsyncAdapter` if you're using Rails.
338
+
339
+
318
340
  ## Troubleshooting
319
341
 
320
342
  ### Initializers for forking servers (Unicorn, Passenger, etc.)
@@ -108,6 +108,19 @@ module SuckerPunch
108
108
  queues.each { |queue| queue.kill }
109
109
  end
110
110
  end
111
+
112
+ def self.wait
113
+ queues = all
114
+
115
+ # return if every queue is empty and workers in every queue are idle
116
+ return if queues.all? { |queue| queue.idle? }
117
+
118
+ SuckerPunch.logger.info("Pausing to allow workers to finish...")
119
+
120
+ while queues.any? { |queue| !queue.idle? }
121
+ sleep PAUSE_TIME
122
+ end
123
+ end
111
124
 
112
125
  attr_reader :name
113
126
 
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "3.0.1"
2
+ VERSION = "3.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hilkert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-17 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake