acidic_job 0.8.5 → 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 +2 -3
- data/.gitignore +1 -1
- data/Gemfile.lock +10 -4
- data/README.md +122 -122
- 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.5.gemfile → rails_7.0.gemfile} +0 -2
- data/lib/acidic_job/active_kiq.rb +9 -38
- 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 +2 -6
- data/lib/acidic_job/serializer.rb +2 -2
- data/lib/acidic_job/serializers/exception_serializer.rb +1 -1
- 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 -9
- metadata +35 -19
- data/.github/FUNDING.yml +0 -13
- data/gemfiles/rails_6.1_sidekiq_6.5.gemfile +0 -10
- data/gemfiles/rails_7.0_sidekiq_6.4.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/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/rails.rb +0 -43
- data/lib/acidic_job/serializers/active_kiq_serializer.rb +0 -25
- data/lib/acidic_job/test_case.rb +0 -9
- data/lib/acidic_job/testing.rb +0 -73
@@ -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/rails.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/railtie"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
class Rails < ::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::FinishedPointSerializer,
|
20
|
-
Serializers::JobSerializer,
|
21
|
-
Serializers::RangeSerializer,
|
22
|
-
Serializers::RecoveryPointSerializer,
|
23
|
-
Serializers::WorkerSerializer,
|
24
|
-
Serializers::ActiveKiqSerializer
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# :nocov:
|
30
|
-
generators do
|
31
|
-
require "generators/acidic_job/install_generator"
|
32
|
-
end
|
33
|
-
# :nocov:
|
34
|
-
|
35
|
-
# This hook happens after all initializers are run, just before returning
|
36
|
-
config.after_initialize do
|
37
|
-
if defined?(::Noticed)
|
38
|
-
# Add `deliver_acidicly` to Noticed
|
39
|
-
::Noticed::Base.include(Extensions::Noticed)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
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
|
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
|