sucker_punch 2.0.4 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +37 -0
- data/CHANGES.md +35 -0
- data/README.md +32 -3
- data/lib/sucker_punch/async_syntax.rb +1 -1
- data/lib/sucker_punch/job.rb +16 -5
- data/lib/sucker_punch/queue.rb +12 -8
- data/lib/sucker_punch/testing.rb +44 -0
- data/lib/sucker_punch/testing/inline.rb +3 -1
- data/lib/sucker_punch/version.rb +1 -1
- data/sucker_punch.gemspec +24 -18
- data/test/sucker_punch/async_syntax_test.rb +17 -0
- data/test/sucker_punch/job_test.rb +29 -1
- data/test/sucker_punch/queue_test.rb +13 -1
- data/test/sucker_punch_test.rb +1 -1
- metadata +15 -14
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5dfa20a18d1c51b637e21b3b7aa657979a73036964ed8e6542e2b759ebd5adce
|
4
|
+
data.tar.gz: 95aea0e08f0a4a3e9048836c820cd4bde237ac067aa3ad71c2de728fd3ffb8cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2bcf61e16203c7cd4c2eab46d35ae5f1da65e640564ad65beba14b2b9b4579023546432553c0d75b571265a0e60f0ff71a48bd4c3519f809e42628aec298791
|
7
|
+
data.tar.gz: 8b660145d51fa187b63ad897a9342dc8955f1cf045b0b03e1138720f912762b35b624fe292d2c0adb9b3a6bf961ad9cae6e29f4044226b37d0c654e257f2353d
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Build
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
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']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
|
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
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby-version }}
|
34
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
35
|
+
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
3.0.1
|
2
|
+
-------
|
3
|
+
- Opt for keyword parsing using `ruby2_keywords` for compatibility.
|
4
|
+
|
5
|
+
3.0.0
|
6
|
+
-------
|
7
|
+
- Add support for keyword arguments in ruby `>= 3.0`. More details in [release notes](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/).
|
8
|
+
|
9
|
+
2.1.1
|
10
|
+
-------
|
11
|
+
- Relax versioning constraint of `concurrent-ruby` to make way for 1.1 release
|
12
|
+
|
13
|
+
2.1.0
|
14
|
+
-------
|
15
|
+
- Add `max_jobs` configuration option to set the maximum number of tasks that
|
16
|
+
may be waiting in the work queue
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class JobWithLimit
|
20
|
+
include SuckerPunch::Job
|
21
|
+
max_jobs 2
|
22
|
+
|
23
|
+
def perform(data)
|
24
|
+
# work...
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
10.times do
|
29
|
+
begin
|
30
|
+
JobWithLimit.perform_async('work') }
|
31
|
+
rescue Concurrent::RejectedExecutionError => e
|
32
|
+
# Queue maxed out, this job didn't get queued
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
1
36
|
2.0.4
|
2
37
|
-------
|
3
38
|
- Better initialization of variables and names to remove warnings
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Sucker Punch
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/brandonhilkert/sucker_punch.
|
4
|
-
[![Code Climate](https://codeclimate.com/github/brandonhilkert/sucker_punch.
|
3
|
+
[![Build Status](https://travis-ci.org/brandonhilkert/sucker_punch.svg?branch=master)](https://travis-ci.org/brandonhilkert/sucker_punch)
|
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.
|
7
7
|
This reduces costs
|
@@ -114,6 +114,22 @@ class LogJob
|
|
114
114
|
end
|
115
115
|
```
|
116
116
|
|
117
|
+
#### Configure the Queue Size
|
118
|
+
|
119
|
+
The default number of jobs that can be queued is unlimited. If you wish to restrict this you can set
|
120
|
+
max\_jobs as follows:
|
121
|
+
|
122
|
+
```Ruby
|
123
|
+
class LogJob
|
124
|
+
include SuckerPunch::Job
|
125
|
+
max_jobs 10
|
126
|
+
|
127
|
+
def perform(event)
|
128
|
+
Log.new(event).track
|
129
|
+
end
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
117
133
|
#### Executing Jobs in the Future
|
118
134
|
|
119
135
|
Many background processing libraries have methods to perform operations after a
|
@@ -131,7 +147,7 @@ class DataJob
|
|
131
147
|
end
|
132
148
|
|
133
149
|
DataJob.perform_async("asdf") # immediately perform asynchronously
|
134
|
-
DataJob.perform_in(60, "asdf") # `perform` will be
|
150
|
+
DataJob.perform_in(60, "asdf") # `perform` will be executed 60 sec. later
|
135
151
|
```
|
136
152
|
|
137
153
|
#### `ActiveRecord` Connection Pool Connections
|
@@ -254,6 +270,19 @@ $ rails g sucker_punch:job logger
|
|
254
270
|
would create the file `app/jobs/logger_job.rb` with a unimplemented `#perform`
|
255
271
|
method.
|
256
272
|
|
273
|
+
## Sinatra
|
274
|
+
|
275
|
+
If you're using Sucker Punch with Sinatra, you must require Sucker Punch before Sinatra:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
# app.rb
|
279
|
+
|
280
|
+
require 'sucker_punch'
|
281
|
+
require 'sinatra'
|
282
|
+
```
|
283
|
+
|
284
|
+
This will ensure Sucker Punch's `at_exit()` handler to clean up and shutdown queues does not happen **before** Sinatra *starts up* via its own `at_exit()` handler.
|
285
|
+
|
257
286
|
## Active Job
|
258
287
|
|
259
288
|
Sucker Punch has been added as an Active Job adapter in Rails 4.2.
|
data/lib/sucker_punch/job.rb
CHANGED
@@ -14,15 +14,17 @@ module SuckerPunch
|
|
14
14
|
# To trigger asynchronous job:
|
15
15
|
#
|
16
16
|
# LogJob.perform_async(1, 2, 3)
|
17
|
-
# LogJob.perform_in(60, 1, 2, 3) # `perform` will be
|
17
|
+
# LogJob.perform_in(60, 1, 2, 3) # `perform` will be executed 60 sec. later
|
18
18
|
#
|
19
19
|
# Note that perform_async is a class method, perform is an instance method.
|
20
20
|
module Job
|
21
21
|
def self.included(base)
|
22
22
|
base.extend(ClassMethods)
|
23
23
|
base.class_attribute :num_workers
|
24
|
+
base.class_attribute :num_jobs_max
|
24
25
|
|
25
26
|
base.num_workers = 2
|
27
|
+
base.num_jobs_max = nil
|
26
28
|
end
|
27
29
|
|
28
30
|
def logger
|
@@ -32,34 +34,43 @@ module SuckerPunch
|
|
32
34
|
module ClassMethods
|
33
35
|
def perform_async(*args)
|
34
36
|
return unless SuckerPunch::RUNNING.true?
|
35
|
-
queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers)
|
36
|
-
queue.post
|
37
|
+
queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
|
38
|
+
queue.post { __run_perform(*args) }
|
37
39
|
end
|
40
|
+
ruby2_keywords(:perform_async) if respond_to?(:ruby2_keywords, true)
|
38
41
|
|
39
42
|
def perform_in(interval, *args)
|
40
43
|
return unless SuckerPunch::RUNNING.true?
|
41
|
-
queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers)
|
44
|
+
queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
|
42
45
|
job = Concurrent::ScheduledTask.execute(interval.to_f, args: args, executor: queue) do
|
43
46
|
__run_perform(*args)
|
44
47
|
end
|
45
48
|
job.pending?
|
46
49
|
end
|
50
|
+
ruby2_keywords(:perform_in) if respond_to?(:ruby2_keywords, true)
|
47
51
|
|
48
52
|
def workers(num)
|
49
53
|
self.num_workers = num
|
50
54
|
end
|
51
55
|
|
56
|
+
def max_jobs(num)
|
57
|
+
self.num_jobs_max = num
|
58
|
+
end
|
59
|
+
|
52
60
|
def __run_perform(*args)
|
53
61
|
SuckerPunch::Counter::Busy.new(self.to_s).increment
|
62
|
+
|
54
63
|
result = self.new.perform(*args)
|
64
|
+
|
55
65
|
SuckerPunch::Counter::Processed.new(self.to_s).increment
|
56
66
|
result
|
57
67
|
rescue => ex
|
58
68
|
SuckerPunch::Counter::Failed.new(self.to_s).increment
|
59
|
-
SuckerPunch.exception_handler.call(ex, self, args)
|
69
|
+
SuckerPunch.exception_handler.call(ex, self, [*args])
|
60
70
|
ensure
|
61
71
|
SuckerPunch::Counter::Busy.new(self.to_s).decrement
|
62
72
|
end
|
73
|
+
ruby2_keywords(:__run_perform) if respond_to?(:ruby2_keywords, true)
|
63
74
|
end
|
64
75
|
end
|
65
76
|
end
|
data/lib/sucker_punch/queue.rb
CHANGED
@@ -5,23 +5,26 @@ module SuckerPunch
|
|
5
5
|
extend Forwardable
|
6
6
|
include Concurrent::ExecutorService
|
7
7
|
|
8
|
+
DEFAULT_MAX_QUEUE_SIZE = 0 # Unlimited
|
9
|
+
|
8
10
|
DEFAULT_EXECUTOR_OPTIONS = {
|
9
11
|
min_threads: 2,
|
10
12
|
max_threads: 2,
|
11
13
|
idletime: 60, # 1 minute
|
12
|
-
max_queue: 0, # unlimited
|
13
14
|
auto_terminate: false # Let shutdown modes handle thread termination
|
14
15
|
}.freeze
|
15
16
|
|
16
17
|
QUEUES = Concurrent::Map.new
|
17
18
|
|
18
|
-
def self.find_or_create(name, num_workers = 2)
|
19
|
+
def self.find_or_create(name, num_workers = 2, num_jobs_max = nil)
|
19
20
|
pool = QUEUES.fetch_or_store(name) do
|
20
|
-
options = DEFAULT_EXECUTOR_OPTIONS
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
options = DEFAULT_EXECUTOR_OPTIONS
|
22
|
+
.merge(
|
23
|
+
min_threads: num_workers,
|
24
|
+
max_threads: num_workers,
|
25
|
+
max_queue: num_jobs_max || DEFAULT_MAX_QUEUE_SIZE
|
26
|
+
)
|
27
|
+
Concurrent::ThreadPoolExecutor.new(**options)
|
25
28
|
end
|
26
29
|
|
27
30
|
new(name, pool)
|
@@ -111,6 +114,7 @@ module SuckerPunch
|
|
111
114
|
def_delegators :@pool,
|
112
115
|
:max_length,
|
113
116
|
:min_length,
|
117
|
+
:max_queue,
|
114
118
|
:length,
|
115
119
|
:queue_length,
|
116
120
|
:wait_for_termination#,
|
@@ -170,6 +174,7 @@ module SuckerPunch
|
|
170
174
|
end
|
171
175
|
end
|
172
176
|
end
|
177
|
+
ruby2_keywords(:post) if respond_to?(:ruby2_keywords, true)
|
173
178
|
|
174
179
|
def kill
|
175
180
|
@pool.kill
|
@@ -187,4 +192,3 @@ module SuckerPunch
|
|
187
192
|
end
|
188
193
|
end
|
189
194
|
end
|
190
|
-
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sucker_punch'
|
2
|
+
|
3
|
+
# Include this in your tests to simulate
|
4
|
+
# a fake job queue. Jobs won't be executed
|
5
|
+
# as they normal would be the thread pool.
|
6
|
+
# They'll instead be pushed to a fake queue
|
7
|
+
# to be checked in a test environment.
|
8
|
+
#
|
9
|
+
# Include in your test_helper.rb:
|
10
|
+
#
|
11
|
+
# require 'sucker_punch/testing'
|
12
|
+
#
|
13
|
+
# In your application code:
|
14
|
+
#
|
15
|
+
# LogJob.perform_async(1, 2, 3)
|
16
|
+
#
|
17
|
+
# In your tests:
|
18
|
+
#
|
19
|
+
# LogJob.jobs => [{ "args" => [1, 2, 3]]
|
20
|
+
|
21
|
+
module SuckerPunch
|
22
|
+
module Job
|
23
|
+
def self.jobs
|
24
|
+
SuckerPunch::Queue.find_or_create(self.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.clear_all
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Queue
|
33
|
+
def self.find_or_create(name, _number_workers = 2, _num_jobs_max = nil)
|
34
|
+
QUEUES.fetch_or_store(name) do
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def kill
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -17,7 +17,7 @@ require 'sucker_punch'
|
|
17
17
|
#
|
18
18
|
# Include inline testing lib:
|
19
19
|
#
|
20
|
-
# require 'sucker_punch/testing/inline
|
20
|
+
# require 'sucker_punch/testing/inline'
|
21
21
|
#
|
22
22
|
# LogJob.perform_async(1, 2, 3) is now synchronous
|
23
23
|
# LogJob.perform_in(1, 2, 3) is now synchronous
|
@@ -28,10 +28,12 @@ module SuckerPunch
|
|
28
28
|
def perform_async(*args)
|
29
29
|
self.new.perform(*args)
|
30
30
|
end
|
31
|
+
ruby2_keywords(:perform_async) if respond_to?(:ruby2_keywords, true)
|
31
32
|
|
32
33
|
def perform_in(_, *args)
|
33
34
|
self.new.perform(*args)
|
34
35
|
end
|
36
|
+
ruby2_keywords(:perform_in) if respond_to?(:ruby2_keywords, true)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/sucker_punch/version.rb
CHANGED
data/sucker_punch.gemspec
CHANGED
@@ -3,26 +3,32 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'sucker_punch/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sucker_punch"
|
8
|
+
spec.version = SuckerPunch::VERSION
|
9
|
+
spec.authors = ["Brandon Hilkert"]
|
10
|
+
spec.email = ["brandonhilkert@gmail.com"]
|
11
|
+
spec.description = %q{Asynchronous processing library for Ruby}
|
12
|
+
spec.summary = %q{Sucker Punch is a Ruby asynchronous processing using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.}
|
13
|
+
spec.homepage = "https://github.com/brandonhilkert/sucker_punch"
|
14
|
+
spec.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "pry"
|
26
26
|
|
27
|
-
|
27
|
+
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
28
|
+
|
29
|
+
if spec.respond_to?(:metadata)
|
30
|
+
spec.metadata['changelog_uri'] = 'https://github.com/brandonhilkert/sucker_punch/blob/master/CHANGES.md'
|
31
|
+
spec.metadata['source_code_uri'] = 'https://github.com/brandonhilkert/sucker_punch'
|
32
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/brandonhilkert/sucker_punch/issues'
|
33
|
+
end
|
28
34
|
end
|
@@ -19,6 +19,14 @@ module SuckerPunch
|
|
19
19
|
assert_equal 1, arr.size
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_perform_async_works_with_keywords
|
23
|
+
arr = Concurrent::Array.new
|
24
|
+
latch = Concurrent::CountDownLatch.new
|
25
|
+
FakeKeywordLatchJob.new.async.perform(arr: arr, latch: latch)
|
26
|
+
latch.wait(0.2)
|
27
|
+
assert_equal 1, arr.size
|
28
|
+
end
|
29
|
+
|
22
30
|
private
|
23
31
|
|
24
32
|
class FakeLatchJob
|
@@ -29,5 +37,14 @@ module SuckerPunch
|
|
29
37
|
latch.count_down
|
30
38
|
end
|
31
39
|
end
|
40
|
+
|
41
|
+
class FakeKeywordLatchJob
|
42
|
+
include SuckerPunch::Job
|
43
|
+
|
44
|
+
def perform(arr: Concurrent::Array.new, latch: Concurrent::CountDownLatch.new)
|
45
|
+
arr.push true
|
46
|
+
latch.count_down
|
47
|
+
end
|
48
|
+
end
|
32
49
|
end
|
33
50
|
end
|
@@ -55,6 +55,11 @@ module SuckerPunch
|
|
55
55
|
FakeLogJob.workers(2)
|
56
56
|
end
|
57
57
|
|
58
|
+
def test_can_set_max_jobs
|
59
|
+
FakeLogJob.max_jobs(10)
|
60
|
+
assert_equal 10, FakeLogJob.num_jobs_max
|
61
|
+
end
|
62
|
+
|
58
63
|
def test_logger_is_accessible_from_instance
|
59
64
|
SuckerPunch.logger = SuckerPunch.default_logger
|
60
65
|
assert_equal SuckerPunch.logger, FakeLogJob.new.logger
|
@@ -117,6 +122,22 @@ module SuckerPunch
|
|
117
122
|
assert SuckerPunch::Counter::Processed.new(job_class.to_s).value == 1
|
118
123
|
end
|
119
124
|
|
125
|
+
def test_perform_async_handles_keyword_arguments
|
126
|
+
arr = Concurrent::Array.new
|
127
|
+
latch = Concurrent::CountDownLatch.new
|
128
|
+
FakeKeywordLatchJob.perform_async(arr: arr, latch: latch)
|
129
|
+
latch.wait(1)
|
130
|
+
assert_equal 1, arr.size
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_perform_in_handles_keyword_arguments
|
134
|
+
arr = Concurrent::Array.new
|
135
|
+
latch = Concurrent::CountDownLatch.new
|
136
|
+
FakeKeywordLatchJob.perform_in(0.1, arr: arr, latch: latch)
|
137
|
+
latch.wait(1)
|
138
|
+
assert_equal 1, arr.size
|
139
|
+
end
|
140
|
+
|
120
141
|
def test_failed_jobs_is_incremented_when_job_raises
|
121
142
|
job_class = Class.new(FakeErrorJob)
|
122
143
|
jobs = 3
|
@@ -137,6 +158,14 @@ module SuckerPunch
|
|
137
158
|
end
|
138
159
|
end
|
139
160
|
|
161
|
+
class FakeKeywordLatchJob
|
162
|
+
include SuckerPunch::Job
|
163
|
+
def perform(arr: Concurrent::Array.new, latch: Concurrent::CountDownLatch.new)
|
164
|
+
arr.push true
|
165
|
+
latch.count_down
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
140
169
|
class FakeBusyJob
|
141
170
|
include SuckerPunch::Job
|
142
171
|
def perform(latch1, latch2)
|
@@ -177,4 +206,3 @@ module SuckerPunch
|
|
177
206
|
end
|
178
207
|
end
|
179
208
|
end
|
180
|
-
|
@@ -29,6 +29,11 @@ module SuckerPunch
|
|
29
29
|
assert_equal 4, queue.min_length
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_queue_max_queue_can_be_set
|
33
|
+
queue = SuckerPunch::Queue.find_or_create(@queue, 4, 10)
|
34
|
+
assert_equal(10, queue.max_queue)
|
35
|
+
end
|
36
|
+
|
32
37
|
def test_same_queue_is_returned_on_subsequent_queries
|
33
38
|
queue = SuckerPunch::Queue.find_or_create(@queue)
|
34
39
|
assert_equal queue, SuckerPunch::Queue.find_or_create(@queue)
|
@@ -65,7 +70,6 @@ module SuckerPunch
|
|
65
70
|
all_stats = SuckerPunch::Queue.stats
|
66
71
|
stats = all_stats[FakeLatchJob.to_s]
|
67
72
|
assert stats["workers"]["total"] > 0
|
68
|
-
assert stats["workers"]["busy"] == 0
|
69
73
|
assert stats["workers"]["idle"] > 0
|
70
74
|
assert stats["jobs"]["processed"] > 0
|
71
75
|
assert stats["jobs"]["failed"] == 0
|
@@ -95,6 +99,14 @@ module SuckerPunch
|
|
95
99
|
assert_equal [1, 2], arr.first
|
96
100
|
end
|
97
101
|
|
102
|
+
def test_jobs_can_be_posted_to_pool_with_keyword_args
|
103
|
+
arr = []
|
104
|
+
fake_pool = FakePool.new
|
105
|
+
queue = SuckerPunch::Queue.new "fake", fake_pool
|
106
|
+
queue.post(a: 1, b: 2) { |args| arr.push args }
|
107
|
+
assert_equal [{a: 1, b: 2}], arr.first
|
108
|
+
end
|
109
|
+
|
98
110
|
def test_kill_sends_kill_to_pool
|
99
111
|
fake_pool = FakePool.new
|
100
112
|
queue = SuckerPunch::Queue.new "fake", fake_pool
|
data/test/sucker_punch_test.rb
CHANGED
@@ -41,7 +41,7 @@ class SuckerPunchTest < Minitest::Test
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_exception_handler_can_be_set
|
44
|
-
SuckerPunch.exception_handler = -> (
|
44
|
+
SuckerPunch.exception_handler = -> (_ex, _, _) { raise "bad stuff" }
|
45
45
|
assert_raises(::RuntimeError) { SuckerPunch.exception_handler.call(StandardError.new("bad"), nil, nil) }
|
46
46
|
end
|
47
47
|
|
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:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Hilkert
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0
|
68
|
+
version: '1.0'
|
69
69
|
description: Asynchronous processing library for Ruby
|
70
70
|
email:
|
71
71
|
- brandonhilkert@gmail.com
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".github/workflows/build.yml"
|
76
77
|
- ".gitignore"
|
77
|
-
- ".travis.yml"
|
78
78
|
- CHANGES.md
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE.txt
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/sucker_punch/job.rb
|
90
90
|
- lib/sucker_punch/queue.rb
|
91
91
|
- lib/sucker_punch/railtie.rb
|
92
|
+
- lib/sucker_punch/testing.rb
|
92
93
|
- lib/sucker_punch/testing/inline.rb
|
93
94
|
- lib/sucker_punch/version.rb
|
94
95
|
- sucker_punch.gemspec
|
@@ -101,10 +102,11 @@ files:
|
|
101
102
|
homepage: https://github.com/brandonhilkert/sucker_punch
|
102
103
|
licenses:
|
103
104
|
- MIT
|
104
|
-
metadata:
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
metadata:
|
106
|
+
changelog_uri: https://github.com/brandonhilkert/sucker_punch/blob/master/CHANGES.md
|
107
|
+
source_code_uri: https://github.com/brandonhilkert/sucker_punch
|
108
|
+
bug_tracker_uri: https://github.com/brandonhilkert/sucker_punch/issues
|
109
|
+
post_install_message:
|
108
110
|
rdoc_options: []
|
109
111
|
require_paths:
|
110
112
|
- lib
|
@@ -112,16 +114,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
114
|
requirements:
|
113
115
|
- - ">="
|
114
116
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
117
|
+
version: 2.0.0
|
116
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
119
|
requirements:
|
118
120
|
- - ">="
|
119
121
|
- !ruby/object:Gem::Version
|
120
122
|
version: '0'
|
121
123
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
124
|
+
rubygems_version: 3.1.2
|
125
|
+
signing_key:
|
125
126
|
specification_version: 4
|
126
127
|
summary: Sucker Punch is a Ruby asynchronous processing using concurrent-ruby, heavily
|
127
128
|
influenced by Sidekiq and girl_friday.
|