acidic_job 0.9.0 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +4 -5
- data/.gitignore +1 -1
- data/.rubocop.yml +0 -10
- data/Gemfile.lock +117 -112
- data/README.md +123 -140
- data/acidic_job.gemspec +2 -0
- data/bin/sandbox +1958 -0
- data/gemfiles/{rails_6.1_sidekiq_6.4.gemfile → rails_6.1.gemfile} +0 -2
- data/gemfiles/{rails_7.0_sidekiq_6.4.gemfile → rails_7.0.gemfile} +0 -2
- data/lib/acidic_job/active_kiq.rb +15 -44
- data/lib/acidic_job/arguments.rb +0 -8
- data/lib/acidic_job/errors.rb +0 -1
- data/lib/acidic_job/mixin.rb +19 -30
- data/lib/acidic_job/perform_wrapper.rb +5 -5
- data/lib/acidic_job/processor.rb +9 -8
- data/lib/acidic_job/run.rb +6 -27
- data/lib/acidic_job/serializer.rb +2 -2
- data/lib/acidic_job/serializers/exception_serializer.rb +18 -23
- data/lib/acidic_job/serializers/job_serializer.rb +14 -6
- data/lib/acidic_job/serializers/worker_serializer.rb +6 -4
- data/lib/acidic_job/version.rb +1 -1
- data/lib/acidic_job/workflow.rb +8 -0
- data/lib/acidic_job.rb +10 -10
- metadata +35 -23
- data/.github/FUNDING.yml +0 -13
- data/gemfiles/rails_6.1_sidekiq_6.5.gemfile +0 -10
- data/gemfiles/rails_6.1_sidekiq_7.0.gemfile +0 -10
- data/gemfiles/rails_7.0_sidekiq_6.5.gemfile +0 -10
- data/gemfiles/rails_7.0_sidekiq_7.0.gemfile +0 -10
- data/gemfiles/rails_7.1_sidekiq_6.4.gemfile +0 -10
- data/gemfiles/rails_7.1_sidekiq_6.5.gemfile +0 -10
- data/gemfiles/rails_7.1_sidekiq_7.0.gemfile +0 -10
- data/lib/acidic_job/configured_job.rb +0 -11
- data/lib/acidic_job/extensions/action_mailer.rb +0 -19
- data/lib/acidic_job/extensions/noticed.rb +0 -46
- data/lib/acidic_job/perform_acidicly.rb +0 -23
- data/lib/acidic_job/railtie.rb +0 -44
- data/lib/acidic_job/serializers/active_kiq_serializer.rb +0 -25
- data/lib/acidic_job/serializers/new_record_serializer.rb +0 -25
- data/lib/acidic_job/test_case.rb +0 -9
- data/lib/acidic_job/testing.rb +0 -73
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.
|
4
|
+
version: 1.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fractaledmind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: psych
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: railties
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,6 +234,20 @@ dependencies:
|
|
220
234
|
- - ">="
|
221
235
|
- !ruby/object:Gem::Version
|
222
236
|
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: warning
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
223
251
|
description: Idempotent operations for Rails apps, built on top of ActiveJob.
|
224
252
|
email:
|
225
253
|
- stephen.margheim@gmail.com
|
@@ -227,7 +255,6 @@ executables: []
|
|
227
255
|
extensions: []
|
228
256
|
extra_rdoc_files: []
|
229
257
|
files:
|
230
|
-
- ".github/FUNDING.yml"
|
231
258
|
- ".github/workflows/main.yml"
|
232
259
|
- ".gitignore"
|
233
260
|
- ".rubocop.yml"
|
@@ -240,47 +267,32 @@ files:
|
|
240
267
|
- UPGRADE_GUIDE.md
|
241
268
|
- acidic_job.gemspec
|
242
269
|
- bin/console
|
270
|
+
- bin/sandbox
|
243
271
|
- bin/setup
|
244
272
|
- blog_post.md
|
245
273
|
- combustion/log/test.log
|
246
|
-
- gemfiles/rails_6.
|
247
|
-
- gemfiles/
|
248
|
-
- gemfiles/rails_6.1_sidekiq_7.0.gemfile
|
249
|
-
- gemfiles/rails_7.0_sidekiq_6.4.gemfile
|
250
|
-
- gemfiles/rails_7.0_sidekiq_6.5.gemfile
|
251
|
-
- gemfiles/rails_7.0_sidekiq_7.0.gemfile
|
252
|
-
- gemfiles/rails_7.1_sidekiq_6.4.gemfile
|
253
|
-
- gemfiles/rails_7.1_sidekiq_6.5.gemfile
|
254
|
-
- gemfiles/rails_7.1_sidekiq_7.0.gemfile
|
274
|
+
- gemfiles/rails_6.1.gemfile
|
275
|
+
- gemfiles/rails_7.0.gemfile
|
255
276
|
- lib/acidic_job.rb
|
256
277
|
- lib/acidic_job/active_kiq.rb
|
257
278
|
- lib/acidic_job/arguments.rb
|
258
279
|
- lib/acidic_job/base.rb
|
259
|
-
- lib/acidic_job/configured_job.rb
|
260
280
|
- lib/acidic_job/errors.rb
|
261
|
-
- lib/acidic_job/extensions/action_mailer.rb
|
262
|
-
- lib/acidic_job/extensions/noticed.rb
|
263
281
|
- lib/acidic_job/finished_point.rb
|
264
282
|
- lib/acidic_job/idempotency_key.rb
|
265
283
|
- lib/acidic_job/logger.rb
|
266
284
|
- lib/acidic_job/mixin.rb
|
267
|
-
- lib/acidic_job/perform_acidicly.rb
|
268
285
|
- lib/acidic_job/perform_wrapper.rb
|
269
286
|
- lib/acidic_job/processor.rb
|
270
|
-
- lib/acidic_job/railtie.rb
|
271
287
|
- lib/acidic_job/recovery_point.rb
|
272
288
|
- lib/acidic_job/run.rb
|
273
289
|
- lib/acidic_job/serializer.rb
|
274
|
-
- lib/acidic_job/serializers/active_kiq_serializer.rb
|
275
290
|
- lib/acidic_job/serializers/exception_serializer.rb
|
276
291
|
- lib/acidic_job/serializers/finished_point_serializer.rb
|
277
292
|
- lib/acidic_job/serializers/job_serializer.rb
|
278
|
-
- lib/acidic_job/serializers/new_record_serializer.rb
|
279
293
|
- lib/acidic_job/serializers/range_serializer.rb
|
280
294
|
- lib/acidic_job/serializers/recovery_point_serializer.rb
|
281
295
|
- lib/acidic_job/serializers/worker_serializer.rb
|
282
|
-
- lib/acidic_job/test_case.rb
|
283
|
-
- lib/acidic_job/testing.rb
|
284
296
|
- lib/acidic_job/version.rb
|
285
297
|
- lib/acidic_job/workflow.rb
|
286
298
|
- lib/acidic_job/workflow_builder.rb
|
@@ -308,9 +320,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
308
320
|
version: 2.7.0
|
309
321
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
310
322
|
requirements:
|
311
|
-
- - "
|
323
|
+
- - ">"
|
312
324
|
- !ruby/object:Gem::Version
|
313
|
-
version:
|
325
|
+
version: 1.3.1
|
314
326
|
requirements: []
|
315
327
|
rubygems_version: 3.3.7
|
316
328
|
signing_key:
|
data/.github/FUNDING.yml
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# These are supported funding model platforms
|
2
|
-
|
3
|
-
github: fractaledmind
|
4
|
-
patreon: # Replace with a single Patreon username
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
11
|
-
otechie: # Replace with a single Otechie username
|
12
|
-
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
13
|
-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support/concern"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
module Extensions
|
7
|
-
module ActionMailer
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
def deliver_acidicly(_options = {})
|
11
|
-
job_class = ::ActionMailer::MailDeliveryJob
|
12
|
-
job_args = [@mailer_class.name, @action.to_s, "deliver_now", @params, *@args]
|
13
|
-
job = job_class.new(job_args)
|
14
|
-
|
15
|
-
AcidicJob::Run.stage!(job)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AcidicJob
|
4
|
-
module Extensions
|
5
|
-
module Noticed
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
class_methods do
|
9
|
-
def deliver_acidicly(recipients)
|
10
|
-
new.deliver_acidicly(recipients)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# THIS IS A HACK THAT COPIES AND PASTES KEY PARTS OF THE `Noticed::Base` CODE
|
15
|
-
# IN ORDER TO ALLOW US TO TRANSACTIONALLY DELIVER NOTIFICATIONS
|
16
|
-
# THIS IS THUS LIABLE TO BREAK WHENEVER THAT GEM IS UPDATED
|
17
|
-
def deliver_acidicly(recipients)
|
18
|
-
delivery_methods = self.class.delivery_methods.dup
|
19
|
-
|
20
|
-
Array.wrap(recipients).uniq.each do |recipient|
|
21
|
-
if (index = delivery_methods.find_index { |m| m[:name] == :database })
|
22
|
-
database_delivery_method = delivery_methods.delete_at(index)
|
23
|
-
self.record = run_delivery_method(database_delivery_method,
|
24
|
-
recipient: recipient,
|
25
|
-
enqueue: false,
|
26
|
-
record: nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
delivery_methods.map do |delivery_method|
|
30
|
-
job_class = delivery_method_for(delivery_method[:name], delivery_method[:options])
|
31
|
-
args = {
|
32
|
-
notification_class: self.class.name,
|
33
|
-
options: delivery_method[:options],
|
34
|
-
params: params,
|
35
|
-
recipient: recipient,
|
36
|
-
record: record
|
37
|
-
}
|
38
|
-
job = job_class.new(args)
|
39
|
-
|
40
|
-
AcidicJob::Run.stage!(job)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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
|
data/lib/acidic_job/railtie.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/railtie"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
class Railtie < ::Rails::Railtie
|
7
|
-
initializer "acidic_job.action_mailer_extension" do
|
8
|
-
::ActiveSupport.on_load(:action_mailer) do
|
9
|
-
# Add `deliver_acidicly` to ActionMailer
|
10
|
-
::ActionMailer::Parameterized::MessageDelivery.include(Extensions::ActionMailer)
|
11
|
-
::ActionMailer::MessageDelivery.include(Extensions::ActionMailer)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
initializer "acidic_job.active_job_serializers" do
|
16
|
-
::ActiveSupport.on_load(:active_job) do
|
17
|
-
::ActiveJob::Serializers.add_serializers(
|
18
|
-
Serializers::ExceptionSerializer,
|
19
|
-
Serializers::NewRecordSerializer,
|
20
|
-
Serializers::FinishedPointSerializer,
|
21
|
-
Serializers::JobSerializer,
|
22
|
-
Serializers::RangeSerializer,
|
23
|
-
Serializers::RecoveryPointSerializer,
|
24
|
-
Serializers::WorkerSerializer,
|
25
|
-
Serializers::ActiveKiqSerializer
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# :nocov:
|
31
|
-
generators do
|
32
|
-
require "generators/acidic_job/install_generator"
|
33
|
-
end
|
34
|
-
# :nocov:
|
35
|
-
|
36
|
-
# This hook happens after all initializers are run, just before returning
|
37
|
-
config.after_initialize do
|
38
|
-
if defined?(::Noticed)
|
39
|
-
# Add `deliver_acidicly` to Noticed
|
40
|
-
::Noticed::Base.include(Extensions::Noticed)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_job/serializers/object_serializer"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
module Serializers
|
7
|
-
class ActiveKiqSerializer < ::ActiveJob::Serializers::ObjectSerializer
|
8
|
-
def serialize(worker)
|
9
|
-
super(
|
10
|
-
"job_class" => worker.class.name,
|
11
|
-
"arguments" => Arguments.serialize(worker.arguments),
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def deserialize(hash)
|
16
|
-
worker_class = hash["job_class"].constantize
|
17
|
-
worker_class.new(*hash["arguments"])
|
18
|
-
end
|
19
|
-
|
20
|
-
def serialize?(argument)
|
21
|
-
defined?(::AcidicJob::ActiveKiq) && argument.class < ::AcidicJob::ActiveKiq
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_job/serializers/object_serializer"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
module Serializers
|
7
|
-
class NewRecordSerializer < ::ActiveJob::Serializers::ObjectSerializer
|
8
|
-
def serialize(new_record)
|
9
|
-
super(
|
10
|
-
"class" => new_record.class.name,
|
11
|
-
"attributes" => new_record.attributes
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def deserialize(hash)
|
16
|
-
new_record_class = hash["class"].constantize
|
17
|
-
new_record_class.new(hash["attributes"])
|
18
|
-
end
|
19
|
-
|
20
|
-
def serialize?(argument)
|
21
|
-
defined?(::ActiveRecord) && argument.respond_to?(:new_record?) && argument.new_record?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/acidic_job/test_case.rb
DELETED
data/lib/acidic_job/testing.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "database_cleaner"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
module Testing
|
7
|
-
def self.included(mod)
|
8
|
-
mod.class_eval "self.use_transactional_tests = false if respond_to?(:use_transactional_tests)", __FILE__, __LINE__
|
9
|
-
end
|
10
|
-
|
11
|
-
def before_setup
|
12
|
-
@connection = ::ActiveRecord::Base.connection
|
13
|
-
@original_cleaners = ::DatabaseCleaner.cleaners
|
14
|
-
::DatabaseCleaner.cleaners = transaction_free_cleaners_for(@original_cleaners)
|
15
|
-
super
|
16
|
-
::DatabaseCleaner.start
|
17
|
-
end
|
18
|
-
|
19
|
-
def after_teardown
|
20
|
-
::DatabaseCleaner.clean
|
21
|
-
super
|
22
|
-
::DatabaseCleaner.cleaners = @original_cleaners
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
# Ensure that the system's original DatabaseCleaner configuration is maintained, options included,
|
28
|
-
# except that any `transaction` strategies for any ORMs are replaced with a `deletion` strategy.
|
29
|
-
def transaction_free_cleaners_for(original_cleaners)
|
30
|
-
non_transaction_cleaners = original_cleaners.dup.to_h do |(orm, opts), cleaner|
|
31
|
-
[[orm, opts], ensure_no_transaction_strategies_for(cleaner)]
|
32
|
-
end
|
33
|
-
::DatabaseCleaner::Cleaners.new(non_transaction_cleaners)
|
34
|
-
end
|
35
|
-
|
36
|
-
def ensure_no_transaction_strategies_for(cleaner)
|
37
|
-
return cleaner unless strategy_name_for(cleaner) == "transaction"
|
38
|
-
|
39
|
-
cleaner.strategy = deletion_strategy_for(cleaner)
|
40
|
-
cleaner
|
41
|
-
end
|
42
|
-
|
43
|
-
def strategy_name_for(cleaner)
|
44
|
-
cleaner # <DatabaseCleaner::Cleaner>
|
45
|
-
.strategy # <DatabaseCleaner::ActiveRecord::Truncation>
|
46
|
-
.class # DatabaseCleaner::ActiveRecord::Truncation
|
47
|
-
.name # "DatabaseCleaner::ActiveRecord::Truncation"
|
48
|
-
.rpartition("::") # ["DatabaseCleaner::ActiveRecord", "::", "Truncation"]
|
49
|
-
.last # "Truncation"
|
50
|
-
.downcase # "truncation"
|
51
|
-
end
|
52
|
-
|
53
|
-
def deletion_strategy_for(cleaner)
|
54
|
-
strategy = cleaner.strategy
|
55
|
-
strategy_namespace = strategy # <DatabaseCleaner::ActiveRecord::Truncation>
|
56
|
-
.class # DatabaseCleaner::ActiveRecord::Truncation
|
57
|
-
.name # "DatabaseCleaner::ActiveRecord::Truncation"
|
58
|
-
.rpartition("::") # ["DatabaseCleaner::ActiveRecord", "::", "Truncation"]
|
59
|
-
.first # "DatabaseCleaner::ActiveRecord"
|
60
|
-
deletion_strategy_class_name = [strategy_namespace, "::", "Deletion"].join
|
61
|
-
deletion_strategy_class = deletion_strategy_class_name.constantize
|
62
|
-
instance_variable_hash = strategy.instance_variables.to_h do |var|
|
63
|
-
[
|
64
|
-
var.to_s.remove("@"),
|
65
|
-
strategy.instance_variable_get(var)
|
66
|
-
]
|
67
|
-
end
|
68
|
-
options = instance_variable_hash.except("db", "connection_class")
|
69
|
-
|
70
|
-
deletion_strategy_class.new(**options)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|