sucker_punch 3.0.1 → 3.2.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: 1d7065c0464318a0f91ea674f8ea6a0bb1591bdbbc78d0a1aceed831e90a287a
4
+ data.tar.gz: 6494c8eb952d5633d678f4a47e566bc6121138edcc68ca7857ffcdc872a1ab85
5
5
  SHA512:
6
- metadata.gz: e2bcf61e16203c7cd4c2eab46d35ae5f1da65e640564ad65beba14b2b9b4579023546432553c0d75b571265a0e60f0ff71a48bd4c3519f809e42628aec298791
7
- data.tar.gz: 8b660145d51fa187b63ad897a9342dc8955f1cf045b0b03e1138720f912762b35b624fe292d2c0adb9b3a6bf961ad9cae6e29f4044226b37d0c654e257f2353d
6
+ metadata.gz: 8d0f522105d3b3d038e34aa66aef6e25c03d6e3ef1618df5c8c595e418b1c8f01468cbab9e8437908338e1fc32ea7e86eba321525a9d984f74ba81053fe78497
7
+ data.tar.gz: 8de430d10421a3889088493e50266d5b18da1f6311e18847bb3d7d34829f188bce8d9590dfe50853cd814dcb51364028ae27b7fac5197fb16d08afcb20992205
@@ -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', '3.2', 'jruby', 'truffleruby', 'truffleruby-head']
23
23
 
24
24
  steps:
25
- - uses: actions/checkout@v2
25
+ - uses: actions/checkout@v3
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,11 @@
1
+ 3.2.0
2
+ -------
3
+ - Rename `singleton_class?` method to allow for usage with Ruby 3
4
+
5
+ 3.1.0
6
+ -------
7
+ - Add a blocking `SuckerPunch::Queue.wait` which waits for all queues to become idle.
8
+
1
9
  3.0.1
2
10
  -------
3
11
  - 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.)
@@ -18,7 +18,7 @@ rescue LoadError
18
18
  define_method(:#{name}) { val }
19
19
  end
20
20
 
21
- if singleton_class?
21
+ if sucker_punch_is_singleton_class?
22
22
  class_eval do
23
23
  def #{name}
24
24
  defined?(@#{name}) ? @#{name} : singleton_class.#{name}
@@ -42,7 +42,8 @@ rescue LoadError
42
42
  end
43
43
 
44
44
  private
45
- def singleton_class?
45
+
46
+ def sucker_punch_is_singleton_class?
46
47
  ancestors.first != self
47
48
  end
48
49
  end
@@ -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.2.0"
3
3
  end
data/sucker_punch.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
 
23
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "minitest"
25
25
  spec.add_development_dependency "pry"
26
26
 
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.2.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: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.0'
19
+ version: '13.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '10.0'
26
+ version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement