active_job-performs 0.3.2 → 0.3.3

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: 566acd14649609a2e16b658a93fe276f80609866c61fb37c11e720b581bc0f76
4
- data.tar.gz: 5174b18e562c53966639bb16e3d729885d99f1ebe01163175a1513dded11cbff
3
+ metadata.gz: 360213ab324cae80fefcf276ecb9803ed8e4ec62166dc9eded626b67f8329b97
4
+ data.tar.gz: 92fa0c284711569f812da53e7acca9cbe15cea03aec0ccb9c2512465a7b93f39
5
5
  SHA512:
6
- metadata.gz: f2fd767c6bd1c66d26a046e84dea4cd2ea0bfdb0ec50452699151e90fba9856b14875ab1a98371cf2727423a31871db4af432a965784a9cf61d92b58917ce0d2
7
- data.tar.gz: cd9628dce5378c14ecae35da1fc83ae4487ea0ece02a5e4a78226572778ca7d370c5975e99ff880fa9bf030f026c244d1d3cf2abac838fb7d1bec373f7327cbf
6
+ metadata.gz: 16fd7671e6eaeba29bac333597170661ca5333c3e14e3142ba910579316641dc2e2ba31f3fdd49508e5e0263a3fc67b34032e4ef61bb1b1a8dc3679a6a9ec26b
7
+ data.tar.gz: 353e3cf1bc646e32883352a2f4ebb80121987e415872ce9d0e32256fcbed7f559e66576a1ee15b71e2fec3930d54f362a5b8905cd502cac7daf4df7b618191e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_job-performs (0.3.2)
4
+ active_job-performs (0.3.3)
5
5
  activejob (>= 6.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -13,7 +13,7 @@ class Post < ApplicationRecord
13
13
  end
14
14
  ```
15
15
 
16
- Then we build a job for the instance method and define a `post.publish_later` instance method, and more:
16
+ Here's what `performs` generates under the hood:
17
17
 
18
18
  ```ruby
19
19
  class Post < ApplicationRecord
@@ -25,12 +25,12 @@ class Post < ApplicationRecord
25
25
  def perform(post, *, **) = post.publish(*, **)
26
26
  end
27
27
 
28
- # On Rails 7.1, where `ActiveJob.perform_all_later` exists, we also generate
28
+ # On Rails 7.1+, where `ActiveJob.perform_all_later` exists, we also generate
29
29
  # a bulk method to enqueue many jobs at once. So you can do this:
30
30
  #
31
31
  # Post.unpublished.in_batches.each(&:publish_later_bulk)
32
- def self.publish_later_bulk
33
- ActiveJob.perform_all_later all.map { PublishJob.new(_1) }
32
+ def self.publish_later_bulk(set = all)
33
+ ActiveJob.perform_all_later set.map { PublishJob.new(_1) }
34
34
  end
35
35
 
36
36
  # We generate `publish_later` to wrap the job execution forwarding arguments and options.
@@ -55,7 +55,12 @@ end
55
55
  > [!TIP]
56
56
  > On that last point, `performs` does put more logic back within your Active Records, so if you need further encapsulation to prevent them growing too large, consider checking out [active_record-associated_object](https://github.com/kaspth/active_record-associated_object).
57
57
 
58
- ### Praise from people
58
+ ### Used in production & praise from people
59
+
60
+ The https://www.rubyevents.org team uses `ActiveJob::Performs` quite a bit:
61
+
62
+ - [See `performs` calls in RubyEvents](https://github.com/search?q=repo%3Arubyevents%2Frubyevents+performs+language%3ARuby&type=code&l=Ruby)
63
+
59
64
 
60
65
  Here's what [@claudiob](https://github.com/claudiob) had to say after using `ActiveJob::Performs`:
61
66
 
@@ -85,7 +90,7 @@ class Post < ActiveRecord::Base
85
90
  extend ActiveJob::Performs # We technically auto-extend ActiveRecord::Base, but other object hierarchies need this.
86
91
 
87
92
  # `performs` builds a `Post::PublishJob` and routes configs over to it.
88
- performs :publish, queue_as: :important, discard_on: SomeError do
93
+ performs :publish, queue_adapter: :sidekiq, queue_as: :important, discard_on: SomeError do
89
94
  retry_on TimeoutError, wait: :polynomially_longer
90
95
  end
91
96
 
@@ -104,6 +109,7 @@ class Post < ActiveRecord::Base
104
109
 
105
110
  # Individual method jobs inherit from the `Post::Job` defined above.
106
111
  class PublishJob < Job
112
+ self.queue_adapter = :sidekiq
107
113
  queue_as :important
108
114
  discard_on SomeError
109
115
  retry_on TimeoutError, wait: :polynomially_longer
@@ -122,8 +128,8 @@ class Post < ActiveRecord::Base
122
128
  # Or pass in a subset of posts as an argument:
123
129
  #
124
130
  # Post.publish_later_bulk Post.unpublished
125
- def self.publish_later_bulk
126
- ActiveJob.perform_all_later all.map { PublishJob.new(_1) }
131
+ def self.publish_later_bulk(set = all)
132
+ ActiveJob.perform_all_later set.map { PublishJob.new(_1) }
127
133
  end
128
134
 
129
135
  # We generate `publish_later` to wrap the job execution.
@@ -137,6 +143,9 @@ class Post < ActiveRecord::Base
137
143
  end
138
144
  ```
139
145
 
146
+ > [!NOTE]
147
+ > We prefer & call `{name}=` setter methods, but fall back to getters. That's how we support `self.queue_adapter=`, but also `queue_as` which is not configured via `queue_as=`.
148
+
140
149
  We generate the `Post::Job` class above to share configuration between method level jobs. E.g. if you had a `retract` method that was setup very similar, you could do:
141
150
 
142
151
  ```ruby
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module Performs
5
- VERSION = "0.3.2"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
@@ -5,18 +5,14 @@ require_relative "performs/version"
5
5
  module ActiveJob; end
6
6
  module ActiveJob::Performs
7
7
  module Waiting
8
- def Proc(value)
9
- value.respond_to?(:call) ? value : proc { value }
10
- end unless Kernel.respond_to?(:Proc) # Optimistically assume Ruby gets this and it'll work fine.
8
+ attr_reader :wait, :wait_until
11
9
 
12
- def wait(value = nil)
13
- @wait = Proc(value) if value
14
- @wait
10
+ def wait=(value)
11
+ @wait = value.respond_to?(:call) ? value : proc { value }
15
12
  end
16
13
 
17
- def wait_until(value = nil)
18
- @wait_until = Proc(value) if value
19
- @wait_until
14
+ def wait_until=(value)
15
+ @wait_until = value.respond_to?(:call) ? value : proc { value }
20
16
  end
21
17
 
22
18
  def scoped_by_wait(record)
@@ -69,9 +65,13 @@ module ActiveJob::Performs
69
65
  name.safe_constantize || const_set(name, Class.new(yield))
70
66
  end
71
67
 
72
- def apply_performs_to(job_class, **configs, &block)
73
- configs.each { job_class.public_send(_1, _2) }
74
- job_class.class_exec(&block) if block_given?
68
+ def apply_performs_to(job, **configs, &block)
69
+ job.class_exec(&block) if block_given?
70
+
71
+ configs.each do |name, value|
72
+ name = "#{name}=".then.find { job.respond_to? _1 } || name
73
+ job.public_send name, value
74
+ end
75
75
  end
76
76
 
77
77
  def performs_later_methods
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_job-performs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activejob
@@ -24,7 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '6.1'
27
- description:
28
26
  email:
29
27
  - hey@kaspth.com
30
28
  executables: []
@@ -47,7 +45,6 @@ metadata:
47
45
  homepage_uri: https://github.com/kaspth/active_job-performs
48
46
  source_code_uri: https://github.com/kaspth/active_job-performs
49
47
  changelog_uri: https://github.com/kaspth/active_job-performs/blob/main/CHANGELOG.md
50
- post_install_message:
51
48
  rdoc_options: []
52
49
  require_paths:
53
50
  - lib
@@ -62,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
59
  - !ruby/object:Gem::Version
63
60
  version: '0'
64
61
  requirements: []
65
- rubygems_version: 3.5.18
66
- signing_key:
62
+ rubygems_version: 3.6.9
67
63
  specification_version: 4
68
64
  summary: ActiveJob::Performs adds the `performs` macro to set up jobs by convention.
69
65
  test_files: []