acidic_job 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/acidic_job.gemspec +1 -1
- data/lib/acidic_job/key.rb +29 -0
- data/lib/acidic_job/staging.rb +19 -0
- data/lib/acidic_job/version.rb +1 -1
- data/lib/acidic_job.rb +22 -35
- data/lib/generators/acidic_job_generator.rb +4 -2
- data/lib/generators/templates/{migration.rb → migration.rb.erb} +3 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82e7abf5e57a4a6b68691e3c6c69ee8a6bbc2eabcedb69a3ef29e91ac0e99e8c
|
4
|
+
data.tar.gz: b73584561b8a558529b2e057e449896dedfff2c21ab859dacf82b070f75c7910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e42251e87faff4790ecfba572eca0dd70251fc58a4293b906560b526efa4bc14db00e01ee0e90c43a0d3f3dc355b36b8db3a4be5129529c071711f3a0b2506f
|
7
|
+
data.tar.gz: 167aa9f07dd033a5a3646edcff171a8dffea485d9cbb943c230526214c6d4eaa68761418321cc4e7795a0326361699181bd142377516ceadaa430d286628aea5
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/acidic_job.gemspec
CHANGED
@@ -27,8 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency "activesupport"
|
31
30
|
spec.add_dependency "activerecord", ">= 4.0.0"
|
31
|
+
spec.add_dependency "activesupport"
|
32
32
|
spec.add_development_dependency "railties", ">= 4.0"
|
33
33
|
|
34
34
|
# For more information and examples about making a new gem, checkout our
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AcidicJob
|
4
|
+
class Key < ActiveRecord::Base
|
5
|
+
RECOVERY_POINT_FINISHED = "FINISHED"
|
6
|
+
|
7
|
+
self.table_name = "acidic_job_keys"
|
8
|
+
|
9
|
+
serialize :error_object
|
10
|
+
serialize :job_args
|
11
|
+
|
12
|
+
validates :idempotency_key, presence: true, uniqueness: { scope: %i[job_name job_args] }
|
13
|
+
validates :job_name, presence: true
|
14
|
+
validates :last_run_at, presence: true
|
15
|
+
validates :recovery_point, presence: true
|
16
|
+
|
17
|
+
def finished?
|
18
|
+
recovery_point == RECOVERY_POINT_FINISHED
|
19
|
+
end
|
20
|
+
|
21
|
+
def succeeded?
|
22
|
+
finished? && !failed?
|
23
|
+
end
|
24
|
+
|
25
|
+
def failed?
|
26
|
+
error_object.present?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AcidicJob
|
4
|
+
class Staging < ActiveRecord::Base
|
5
|
+
self.table_name = "acidic_job_stagings"
|
6
|
+
|
7
|
+
validates :serialized_params, presence: true
|
8
|
+
|
9
|
+
serialize :serialized_params
|
10
|
+
|
11
|
+
after_create_commit :enqueue_job
|
12
|
+
|
13
|
+
def enqueue_job
|
14
|
+
job = ActiveJob::Base.deserialize(serialized_params)
|
15
|
+
job.enqueue
|
16
|
+
delete
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/acidic_job/version.rb
CHANGED
data/lib/acidic_job.rb
CHANGED
@@ -4,9 +4,11 @@ require_relative "acidic_job/version"
|
|
4
4
|
require_relative "acidic_job/no_op"
|
5
5
|
require_relative "acidic_job/recovery_point"
|
6
6
|
require_relative "acidic_job/response"
|
7
|
+
require_relative "acidic_job/key"
|
8
|
+
require_relative "acidic_job/staging"
|
7
9
|
require "active_support/concern"
|
8
10
|
|
9
|
-
# rubocop:disable Metrics/ModuleLength,
|
11
|
+
# rubocop:disable Metrics/ModuleLength, Metrics/AbcSize, Metrics/MethodLength
|
10
12
|
module AcidicJob
|
11
13
|
class MismatchedIdempotencyKeyAndJobArguments < StandardError; end
|
12
14
|
|
@@ -18,43 +20,27 @@ module AcidicJob
|
|
18
20
|
|
19
21
|
class SerializedTransactionConflict < StandardError; end
|
20
22
|
|
21
|
-
|
22
|
-
RECOVERY_POINT_FINISHED = "FINISHED"
|
23
|
-
|
24
|
-
self.table_name = "acidic_job_keys"
|
25
|
-
|
26
|
-
serialize :error_object
|
27
|
-
serialize :job_args
|
28
|
-
|
29
|
-
validates :idempotency_key, presence: true, uniqueness: {scope: [:job_name, :job_args]}
|
30
|
-
validates :job_name, presence: true
|
31
|
-
validates :last_run_at, presence: true
|
32
|
-
validates :recovery_point, presence: true
|
33
|
-
|
34
|
-
def finished?
|
35
|
-
recovery_point == RECOVERY_POINT_FINISHED
|
36
|
-
end
|
23
|
+
extend ActiveSupport::Concern
|
37
24
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
25
|
+
module ActiveJobExtension
|
26
|
+
extend ActiveSupport::Concern
|
41
27
|
|
42
|
-
|
43
|
-
|
28
|
+
class_methods do
|
29
|
+
def perform_transactionally(*args)
|
30
|
+
AcidicJob::Staging.create!(
|
31
|
+
serialized_params: job_or_instantiate(*args).serialize
|
32
|
+
)
|
33
|
+
end
|
44
34
|
end
|
45
35
|
end
|
46
36
|
|
47
|
-
extend ActiveSupport::Concern
|
48
|
-
|
49
37
|
included do
|
50
38
|
attr_reader :key
|
51
39
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# retry_on LockedIdempotencyKey
|
57
|
-
# retry_on ActiveRecord::SerializationFailure
|
40
|
+
# Extend ActiveJob only once it has been loaded
|
41
|
+
ActiveSupport.on_load(:active_job) do
|
42
|
+
send(:include, ActiveJobExtension)
|
43
|
+
end
|
58
44
|
end
|
59
45
|
|
60
46
|
# Number of seconds passed which we consider a held idempotency key lock to be
|
@@ -64,7 +50,8 @@ module AcidicJob
|
|
64
50
|
IDEMPOTENCY_KEY_LOCK_TIMEOUT = 90
|
65
51
|
|
66
52
|
# &block
|
67
|
-
|
53
|
+
# &block
|
54
|
+
def idempotently(with:)
|
68
55
|
# set accessors for each argument passed in to ensure they are available
|
69
56
|
# to the step methods the job will have written
|
70
57
|
define_accessors_for_passed_arguments(with)
|
@@ -126,7 +113,7 @@ module AcidicJob
|
|
126
113
|
|
127
114
|
phase_result.call(key: key)
|
128
115
|
end
|
129
|
-
rescue => e
|
116
|
+
rescue StandardError => e
|
130
117
|
error = e
|
131
118
|
raise e
|
132
119
|
ensure
|
@@ -134,7 +121,7 @@ module AcidicJob
|
|
134
121
|
# key right away so that another request can try again.
|
135
122
|
begin
|
136
123
|
key.update_columns(locked_at: nil, error_object: error) if error.present?
|
137
|
-
rescue => e
|
124
|
+
rescue StandardError => e
|
138
125
|
# We're already inside an error condition, so swallow any additional
|
139
126
|
# errors from here and just send them to logs.
|
140
127
|
puts "Failed to unlock key #{key.id} because of #{e}."
|
@@ -148,7 +135,7 @@ module AcidicJob
|
|
148
135
|
:read_uncommitted
|
149
136
|
else
|
150
137
|
:serializable
|
151
|
-
|
138
|
+
end
|
152
139
|
serialized_job_info = serialize
|
153
140
|
|
154
141
|
ActiveRecord::Base.transaction(isolation: isolation_level) do
|
@@ -207,4 +194,4 @@ module AcidicJob
|
|
207
194
|
end
|
208
195
|
end
|
209
196
|
end
|
210
|
-
# rubocop:enable Metrics/ModuleLength,
|
197
|
+
# rubocop:enable Metrics/ModuleLength, Metrics/AbcSize, Metrics/MethodLength
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails/generators"
|
2
4
|
require "rails/generators/active_record"
|
3
5
|
|
@@ -22,8 +24,8 @@ class AcidicJobGenerator < ActiveRecord::Generators::Base
|
|
22
24
|
|
23
25
|
# Copies the migration template to db/migrate.
|
24
26
|
def copy_files
|
25
|
-
migration_template "migration.rb",
|
26
|
-
|
27
|
+
migration_template "migration.rb.erb",
|
28
|
+
"db/migrate/create_acidic_job_keys.rb"
|
27
29
|
end
|
28
30
|
|
29
31
|
protected
|
@@ -13,6 +13,9 @@ class CreateAcidicJobKeys < <%= migration_class %>
|
|
13
13
|
t.index %i[idempotency_key job_name job_args],
|
14
14
|
unique: true,
|
15
15
|
name: "idx_acidic_job_keys_on_idempotency_key_n_job_name_n_job_args"
|
16
|
+
|
17
|
+
create_table :acidic_job_stagings do |t|
|
18
|
+
t.text :serialized_params, null: false
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acidic_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fractaledmind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: railties
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,12 +72,14 @@ files:
|
|
72
72
|
- bin/console
|
73
73
|
- bin/setup
|
74
74
|
- lib/acidic_job.rb
|
75
|
+
- lib/acidic_job/key.rb
|
75
76
|
- lib/acidic_job/no_op.rb
|
76
77
|
- lib/acidic_job/recovery_point.rb
|
77
78
|
- lib/acidic_job/response.rb
|
79
|
+
- lib/acidic_job/staging.rb
|
78
80
|
- lib/acidic_job/version.rb
|
79
81
|
- lib/generators/acidic_job_generator.rb
|
80
|
-
- lib/generators/templates/migration.rb
|
82
|
+
- lib/generators/templates/migration.rb.erb
|
81
83
|
homepage: https://github.com/fractaledmind/acidic_job
|
82
84
|
licenses:
|
83
85
|
- MIT
|