acidic_job 0.8.4 → 0.8.5

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: 041e2488af3dc4780e6112b92195dc805063ebc4c631bd3d7012017efe4e1583
4
- data.tar.gz: d035a4d739e3cc7b6f6a2f223aefa7d600ab67dae537814363f16a478dd8c00c
3
+ metadata.gz: 54586a38aa48a14ef168657659a81b0db14446d011bd76085641dd4fb21f7838
4
+ data.tar.gz: 849af5f8e34684cd22d454f85ac816e749c3a4dd91ba58dba34ce67931916d3c
5
5
  SHA512:
6
- metadata.gz: 96792f3e03f71aa19a83773a3eded77de541e6ea72c9aa2ca421f5298aa5e0e234b0705b0a27f417ebdb02b8e0b621ab935571b5ffc728a729c22bff7f97d809
7
- data.tar.gz: 7dc53950ebf1d1c425f02f2c12a065cefa71c8c57173a4aa27478d9fcab7ffc0cdc822034da9179d59da9a0c544bd8b7c81108ef4da99a941de4b1d9ec63eb28
6
+ metadata.gz: fe54d708708a8316020979400dda7afd73480d34597f9416b30218b7307d8e4ce3cfbf65e14e05681810de88e21d131f06f4a3f72549a7dedef62be209b3137d
7
+ data.tar.gz: 58ba97af8e30c9bff0df8cf4015a3920ce722a5242048469b2224a4d9ca32c67971f03792862c2548515adc33b8407309c386ab1ff1dd509735f420029c11085
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.8.4)
4
+ acidic_job (0.8.5)
5
5
  activejob
6
6
  activerecord
7
7
  activesupport
@@ -13,11 +13,29 @@ module AcidicJob
13
13
  define_callbacks :perform
14
14
  include Mixin
15
15
 
16
+ concerning :Configuring do
17
+ # Configures the job with the given options.
18
+ def set(options = {}) # :nodoc:
19
+ self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
20
+ self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
21
+ self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
22
+
23
+ self
24
+ end
25
+ end
26
+
16
27
  concerning :Initializing do
28
+ class_methods do
29
+ def job_or_instantiate(*args)
30
+ args.first.is_a?(self) ? args.first : new(*args)
31
+ end
32
+ end
33
+
17
34
  included do
18
35
  attr_accessor :arguments
19
36
  attr_accessor :job_id
20
37
  attr_accessor :queue_name
38
+ attr_accessor :scheduled_at
21
39
  attr_accessor :sidekiq_options
22
40
  end
23
41
  ##
@@ -25,8 +43,8 @@ module AcidicJob
25
43
  # +args+ are the arguments, if any, that will be passed to the perform method
26
44
  # +opts+ are any options to configure the job
27
45
  def initialize(*arguments)
28
- @arguments = arguments
29
- @job_id = ::SecureRandom.uuid
46
+ @arguments = arguments
47
+ @job_id = ::SecureRandom.uuid
30
48
  @sidekiq_options = sidekiq_options_hash || ::Sidekiq.default_job_options
31
49
  @queue_name = @sidekiq_options["queue"]
32
50
  end
@@ -43,22 +61,33 @@ module AcidicJob
43
61
 
44
62
  concerning :Performing do
45
63
  class_methods do
46
- def perform_now(*args, **kwargs)
47
- new.perform(*args, **kwargs)
64
+ def perform_later(*args)
65
+ perform_async(*args)
66
+ end
67
+
68
+ def perform_now(*args)
69
+ perform_inline(*args)
48
70
  end
49
71
  end
50
72
 
51
- def perform_now(*args, **kwargs)
52
- perform(*args, **kwargs)
73
+ def perform_later(*args)
74
+ Setter.new(self.class, {}).perform_async(*args)
75
+ end
76
+
77
+ def perform_now(*args)
78
+ Setter.new(self.class, {}).perform_inline(*args)
53
79
  end
54
80
 
55
81
  def enqueue
56
- ::Sidekiq::Client.push(
82
+ item = {
57
83
  "class" => self.class,
58
84
  "args" => @arguments,
59
85
  "jid" => @job_id,
60
86
  "queue" => @queue_name
61
- )
87
+ }
88
+ item["at"] = @scheduled_at if @scheduled_at
89
+
90
+ ::Sidekiq::Client.push(item)
62
91
  end
63
92
  end
64
93
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_job/configured_job"
4
+
5
+ module AcidicJob
6
+ class ConfiguredJob < ::ActiveJob::ConfiguredJob
7
+ def perform_acidicly(...)
8
+ @job_class.new(...).set(@options).perform_acidicly
9
+ end
10
+ end
11
+ end
@@ -10,6 +10,8 @@ module AcidicJob
10
10
  # Ensure our `perform` method always runs first to gather parameters
11
11
  # and run perform callbacks for Sidekiq workers
12
12
  other.prepend PerformWrapper
13
+ # Ensure both configured and base jobs can be performed acidicly
14
+ other.include PerformAcidicly
13
15
 
14
16
  # By default, we unique job runs by the `job_id`
15
17
  other.instance_variable_set(:@acidic_identifier, :job_id)
@@ -40,19 +42,6 @@ module AcidicJob
40
42
  super
41
43
  end
42
44
 
43
- # `perform_now` runs a job synchronously and immediately
44
- # `perform_later` runs a job asynchronously and queues it immediately
45
- # `perform_acidicly` run a job asynchronously and queues it after a successful database commit
46
- def perform_acidicly(*args, **kwargs)
47
- job = if kwargs.empty?
48
- new(*args)
49
- else
50
- new(*args, **kwargs)
51
- end
52
-
53
- Run.stage!(job)
54
- end
55
-
56
45
  # Instantiate an instance of a job ready for serialization
57
46
  def with(...)
58
47
  # New delegation syntax (...) was introduced in Ruby 2.7.
@@ -62,12 +51,26 @@ module AcidicJob
62
51
  job.queue_name
63
52
  job
64
53
  end
54
+
55
+ def set(options = {})
56
+ ::AcidicJob::ConfiguredJob.new(self, options)
57
+ end
65
58
  end
66
59
 
67
60
  def idempotency_key
68
61
  IdempotencyKey.new(self).value(acidic_by: acidic_identifier)
69
62
  end
70
63
 
64
+ # Configures the job with the given options.
65
+ def set(options = {}) # :nodoc:
66
+ self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
67
+ self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
68
+ self.queue_name = self.class.queue_name_from_part(options[:queue]) if options[:queue]
69
+ self.priority = options[:priority].to_i if options[:priority]
70
+
71
+ self
72
+ end
73
+
71
74
  protected
72
75
 
73
76
  # Short circuits execution by sending execution right to 'finished'.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module AcidicJob
6
+ module PerformAcidicly
7
+ extend ActiveSupport::Concern
8
+
9
+ # `perform_now` runs a job synchronously and immediately
10
+ # `perform_later` runs a job asynchronously and queues it immediately
11
+ # `perform_acidicly` run a job asynchronously and queues it after a successful database commit
12
+
13
+ class_methods do
14
+ def perform_acidicly(...)
15
+ job_or_instantiate(...).perform_acidicly
16
+ end
17
+ end
18
+
19
+ def perform_acidicly
20
+ Run.stage!(self)
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.8.4"
4
+ VERSION = "0.8.5"
5
5
  end
data/lib/acidic_job.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "acidic_job/errors"
5
5
  require_relative "acidic_job/logger"
6
6
  require_relative "acidic_job/arguments"
7
7
  require_relative "acidic_job/serializer"
8
+ require_relative "acidic_job/configured_job"
8
9
  require_relative "acidic_job/workflow_builder"
9
10
  require_relative "acidic_job/idempotency_key"
10
11
  require_relative "acidic_job/recovery_point"
@@ -14,6 +15,7 @@ require_relative "acidic_job/workflow_step"
14
15
  require_relative "acidic_job/workflow"
15
16
  require_relative "acidic_job/processor"
16
17
  require_relative "acidic_job/perform_wrapper"
18
+ require_relative "acidic_job/perform_acidicly"
17
19
  require_relative "acidic_job/extensions/action_mailer"
18
20
  require_relative "acidic_job/extensions/noticed"
19
21
  require_relative "acidic_job/mixin"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acidic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -253,6 +253,7 @@ files:
253
253
  - lib/acidic_job/active_kiq.rb
254
254
  - lib/acidic_job/arguments.rb
255
255
  - lib/acidic_job/base.rb
256
+ - lib/acidic_job/configured_job.rb
256
257
  - lib/acidic_job/errors.rb
257
258
  - lib/acidic_job/extensions/action_mailer.rb
258
259
  - lib/acidic_job/extensions/noticed.rb
@@ -260,6 +261,7 @@ files:
260
261
  - lib/acidic_job/idempotency_key.rb
261
262
  - lib/acidic_job/logger.rb
262
263
  - lib/acidic_job/mixin.rb
264
+ - lib/acidic_job/perform_acidicly.rb
263
265
  - lib/acidic_job/perform_wrapper.rb
264
266
  - lib/acidic_job/processor.rb
265
267
  - lib/acidic_job/rails.rb