sucker_punch 2.1.2 → 3.0.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: 4b584388415071f977d554aa3d9e8128521c08a3b4299492e349bfbc5dc865f5
4
- data.tar.gz: c77e1a8b773e712f2ec67c311e3f00bfe16fbcd8c79afc028c44b879d93c943d
3
+ metadata.gz: e1edad787473a077f23f2fae95150cdb92e3834a12150fbd4d910fade5692516
4
+ data.tar.gz: 4ba7b7fa6cf3a1c99706a3bda43b0fd2fc291ae1825a23466b00a5b7a3354003
5
5
  SHA512:
6
- metadata.gz: 67bb1e1d9b05432f8e868451cfbd846ea29871887ee807fc398067e10e9db2305abdf891c44e9453e822063f7599bb2f7f45535b3440287ecbdf0e7e8e688b9a
7
- data.tar.gz: e6e86dccf04e992c61369369e78e6ff7a7ab1239e9713800c7fcda1f62ed7996e451ed0053bfe1b595e6d1dd268c7853cf6aa5da8efcd8e852e2319e4a36c57c
6
+ metadata.gz: a8184cafe29937ad818920951c3c760e8435b4e35a348e27629053bae1b56e2f44ab412154fb3769e6878034a9351ad5e60fb44d9385bf5bb4f2bf58cc91c71c
7
+ data.tar.gz: fde16057612312085f59a955e783007b6a0cf0b4ff7d08312963bc0c76b3be2e5d254e5eb1df1625db3c554403485e5df8a1c995ab50b71dda4e1358b00e8d23
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 3.0.0
2
+ -------
3
+ - 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/).
4
+
1
5
  2.1.1
2
6
  -------
3
7
  - Relax versioning constraint of `concurrent-ruby` to make way for 1.1 release
@@ -10,9 +10,8 @@ module SuckerPunch
10
10
  @job = job
11
11
  end
12
12
 
13
- def perform(*args)
14
- @job.class.perform_async(*args)
13
+ def perform(*args, **kwargs)
14
+ @job.class.perform_async(*args, **kwargs)
15
15
  end
16
16
  end
17
17
  end
18
-
@@ -32,17 +32,17 @@ module SuckerPunch
32
32
  end
33
33
 
34
34
  module ClassMethods
35
- def perform_async(*args)
35
+ def perform_async(*args, **kwargs)
36
36
  return unless SuckerPunch::RUNNING.true?
37
37
  queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
38
- queue.post(args) { |job_args| __run_perform(*job_args) }
38
+ queue.post { __run_perform(*args, **kwargs) }
39
39
  end
40
40
 
41
- def perform_in(interval, *args)
41
+ def perform_in(interval, *args, **kwargs)
42
42
  return unless SuckerPunch::RUNNING.true?
43
43
  queue = SuckerPunch::Queue.find_or_create(self.to_s, num_workers, num_jobs_max)
44
44
  job = Concurrent::ScheduledTask.execute(interval.to_f, args: args, executor: queue) do
45
- __run_perform(*args)
45
+ __run_perform(*args, **kwargs)
46
46
  end
47
47
  job.pending?
48
48
  end
@@ -55,14 +55,20 @@ module SuckerPunch
55
55
  self.num_jobs_max = num
56
56
  end
57
57
 
58
- def __run_perform(*args)
58
+ def __run_perform(*args, **kwargs)
59
59
  SuckerPunch::Counter::Busy.new(self.to_s).increment
60
- result = self.new.perform(*args)
60
+
61
+ result = if RUBY_VERSION >= '2.5'
62
+ self.new.perform(*args, **kwargs)
63
+ else
64
+ self.new.perform(*args, *(kwargs.any? ? [kwargs] : nil))
65
+ end
66
+
61
67
  SuckerPunch::Counter::Processed.new(self.to_s).increment
62
68
  result
63
69
  rescue => ex
64
70
  SuckerPunch::Counter::Failed.new(self.to_s).increment
65
- SuckerPunch.exception_handler.call(ex, self, args)
71
+ SuckerPunch.exception_handler.call(ex, self, [*args, **kwargs])
66
72
  ensure
67
73
  SuckerPunch::Counter::Busy.new(self.to_s).decrement
68
74
  end
@@ -24,7 +24,7 @@ module SuckerPunch
24
24
  max_threads: num_workers,
25
25
  max_queue: num_jobs_max || DEFAULT_MAX_QUEUE_SIZE
26
26
  )
27
- Concurrent::ThreadPoolExecutor.new(options)
27
+ Concurrent::ThreadPoolExecutor.new(**options)
28
28
  end
29
29
 
30
30
  new(name, pool)
@@ -165,10 +165,10 @@ module SuckerPunch
165
165
  SuckerPunch::Counter::Failed.new(name).value
166
166
  end
167
167
 
168
- def post(*args, &block)
168
+ def post(*args, **kwargs, &block)
169
169
  synchronize do
170
170
  if @running
171
- @pool.post(*args, &block)
171
+ @pool.post(*args, **kwargs, &block)
172
172
  else
173
173
  false
174
174
  end
@@ -191,4 +191,3 @@ module SuckerPunch
191
191
  end
192
192
  end
193
193
  end
194
-
@@ -30,7 +30,7 @@ module SuckerPunch
30
30
  end
31
31
 
32
32
  class Queue
33
- def self.find_or_create(name, number_workers = 2, num_jobs_max = nil)
33
+ def self.find_or_create(name, _number_workers = 2, _num_jobs_max = nil)
34
34
  QUEUES.fetch_or_store(name) do
35
35
  []
36
36
  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
@@ -25,12 +25,12 @@ require 'sucker_punch'
25
25
  module SuckerPunch
26
26
  module Job
27
27
  module ClassMethods
28
- def perform_async(*args)
29
- self.new.perform(*args)
28
+ def perform_async(*args, **kwargs)
29
+ self.new.perform(*args, **kwargs)
30
30
  end
31
31
 
32
- def perform_in(_, *args)
33
- self.new.perform(*args)
32
+ def perform_in(_, *args, **kwargs)
33
+ self.new.perform(*args, **kwargs)
34
34
  end
35
35
  end
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "2.1.2"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -182,4 +182,3 @@ module SuckerPunch
182
182
  end
183
183
  end
184
184
  end
185
-
@@ -136,9 +136,9 @@ module SuckerPunch
136
136
  @signals = []
137
137
  end
138
138
 
139
- def post(*args, &block)
139
+ def post(*args, **kwargs, &block)
140
140
  if block_given?
141
- block.call(args)
141
+ block.call(args, **kwargs)
142
142
  end
143
143
  end
144
144
 
@@ -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 = -> (ex, _, _) { raise "bad stuff" }
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: 2.1.2
4
+ version: 3.0.0
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: 2019-05-16 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.0.3
127
- signing_key:
126
+ rubygems_version: 3.1.2
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: Sucker Punch is a Ruby asynchronous processing using concurrent-ruby, heavily
130
130
  influenced by Sidekiq and girl_friday.