acidic_job 0.7.6 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +21 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +99 -3
- data/README.md +47 -14
- data/acidic_job.gemspec +2 -2
- data/bin/console +3 -2
- data/lib/acidic_job/awaiting.rb +68 -0
- data/lib/acidic_job/errors.rb +2 -0
- data/lib/acidic_job/extensions/action_mailer.rb +27 -0
- data/lib/acidic_job/extensions/active_job.rb +39 -0
- data/lib/acidic_job/extensions/noticed.rb +52 -0
- data/lib/acidic_job/extensions/sidekiq.rb +101 -0
- data/lib/acidic_job/{response.rb → finished_point.rb} +4 -4
- data/lib/acidic_job/idempotency_key.rb +24 -0
- data/lib/acidic_job/perform_wrapper.rb +34 -20
- data/lib/acidic_job/recovery_point.rb +3 -3
- data/lib/acidic_job/run.rb +77 -0
- data/lib/acidic_job/staging.rb +30 -0
- data/lib/acidic_job/step.rb +83 -0
- data/lib/acidic_job/version.rb +1 -1
- data/lib/acidic_job.rb +122 -207
- data/lib/generators/acidic_job_generator.rb +6 -15
- data/lib/generators/templates/create_acidic_job_runs_migration.rb.erb +19 -0
- metadata +19 -17
- data/lib/acidic_job/deliver_transactionally_extension.rb +0 -26
- data/lib/acidic_job/key.rb +0 -33
- data/lib/acidic_job/no_op.rb +0 -11
- data/lib/acidic_job/perform_transactionally_extension.rb +0 -33
- data/lib/acidic_job/sidekiq_callbacks.rb +0 -45
- data/lib/acidic_job/staged.rb +0 -50
- data/lib/generators/templates/create_acidic_job_keys_migration.rb.erb +0 -20
- data/lib/generators/templates/create_staged_acidic_jobs_migration.rb.erb +0 -10
data/lib/acidic_job/no_op.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support/concern"
|
4
|
-
|
5
|
-
module AcidicJob
|
6
|
-
module PerformTransactionallyExtension
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
class_methods do
|
10
|
-
# rubocop:disable Metrics/MethodLength
|
11
|
-
def perform_transactionally(*args)
|
12
|
-
attributes = if defined?(ActiveJob) && self < ActiveJob::Base
|
13
|
-
{
|
14
|
-
adapter: "activejob",
|
15
|
-
job_name: name,
|
16
|
-
job_args: job_or_instantiate(*args).serialize
|
17
|
-
}
|
18
|
-
elsif defined?(Sidekiq) && include?(Sidekiq::Worker)
|
19
|
-
{
|
20
|
-
adapter: "sidekiq",
|
21
|
-
job_name: name,
|
22
|
-
job_args: args
|
23
|
-
}
|
24
|
-
else
|
25
|
-
raise UnknownJobAdapter
|
26
|
-
end
|
27
|
-
|
28
|
-
AcidicJob::Staged.create!(attributes)
|
29
|
-
end
|
30
|
-
# rubocop:enable Metrics/MethodLength
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support/callbacks"
|
4
|
-
|
5
|
-
# Following approach used by ActiveJob
|
6
|
-
# https://github.com/rails/rails/blob/93c9534c9871d4adad4bc33b5edc355672b59c61/activejob/lib/active_job/callbacks.rb
|
7
|
-
module SidekiqCallbacks
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
def self.prepended(base)
|
11
|
-
base.include(ActiveSupport::Callbacks)
|
12
|
-
|
13
|
-
# Check to see if we already have any callbacks for :perform
|
14
|
-
# Prevents overwriting callbacks if we already included this module (and defined callbacks)
|
15
|
-
base.define_callbacks :perform unless base.respond_to?(:_perform_callbacks) && base._perform_callbacks.present?
|
16
|
-
|
17
|
-
class << base
|
18
|
-
prepend ClassMethods
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def perform(*args)
|
23
|
-
if respond_to?(:run_callbacks)
|
24
|
-
run_callbacks :perform do
|
25
|
-
super(*args)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
super(*args)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module ClassMethods
|
33
|
-
def around_perform(*filters, &blk)
|
34
|
-
set_callback(:perform, :around, *filters, &blk)
|
35
|
-
end
|
36
|
-
|
37
|
-
def before_perform(*filters, &blk)
|
38
|
-
set_callback(:perform, :before, *filters, &blk)
|
39
|
-
end
|
40
|
-
|
41
|
-
def after_perform(*filters, &blk)
|
42
|
-
set_callback(:perform, :after, *filters, &blk)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/acidic_job/staged.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_record"
|
4
|
-
require "global_id"
|
5
|
-
|
6
|
-
module AcidicJob
|
7
|
-
class Staged < ActiveRecord::Base
|
8
|
-
self.table_name = "staged_acidic_jobs"
|
9
|
-
|
10
|
-
include GlobalID::Identification
|
11
|
-
|
12
|
-
validates :adapter, presence: true
|
13
|
-
validates :job_name, presence: true
|
14
|
-
validates :job_args, presence: true
|
15
|
-
|
16
|
-
serialize :job_args
|
17
|
-
|
18
|
-
after_create_commit :enqueue_job
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
23
|
-
def enqueue_job
|
24
|
-
gid = { "staged_job_gid" => to_global_id.to_s }
|
25
|
-
|
26
|
-
if job_args.is_a?(Hash) && job_args.key?("arguments")
|
27
|
-
job_args["arguments"].concat([gid])
|
28
|
-
else
|
29
|
-
job_args.concat([gid])
|
30
|
-
end
|
31
|
-
|
32
|
-
case adapter
|
33
|
-
when "activejob"
|
34
|
-
job = ActiveJob::Base.deserialize(job_args)
|
35
|
-
job.enqueue
|
36
|
-
when "sidekiq"
|
37
|
-
Sidekiq::Client.push(
|
38
|
-
"class" => job_name,
|
39
|
-
"args" => job_args
|
40
|
-
)
|
41
|
-
else
|
42
|
-
raise UnknownJobAdapter.new(adapter: adapter)
|
43
|
-
end
|
44
|
-
|
45
|
-
# NOTE: record will be deleted after the job has successfully been performed
|
46
|
-
true
|
47
|
-
end
|
48
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
49
|
-
end
|
50
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class CreateAcidicJobKeys < <%= migration_class %>
|
2
|
-
def change
|
3
|
-
create_table :acidic_job_keys do |t|
|
4
|
-
t.string :idempotency_key, null: false
|
5
|
-
t.string :job_name, null: false
|
6
|
-
t.text :job_args, null: true
|
7
|
-
t.datetime :last_run_at, null: false, default: -> { "CURRENT_TIMESTAMP" }
|
8
|
-
t.datetime :locked_at, null: true
|
9
|
-
t.string :recovery_point, null: false
|
10
|
-
t.text :error_object
|
11
|
-
t.text :attr_accessors
|
12
|
-
t.text :workflow
|
13
|
-
t.timestamps
|
14
|
-
|
15
|
-
t.index %i[idempotency_key job_name job_args],
|
16
|
-
unique: true,
|
17
|
-
name: "idx_acidic_job_keys_on_idempotency_key_n_job_name_n_job_args"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|