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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8aa8aee9c23bc58be992813f139864afdb057442ee9c359263f3ff45029e3f28
4
- data.tar.gz: 9dbb8017fcbf91ce5cbcc5c96968e3b880340c1e1cc7a8c36cb11e744d6b405d
3
+ metadata.gz: 82e7abf5e57a4a6b68691e3c6c69ee8a6bbc2eabcedb69a3ef29e91ac0e99e8c
4
+ data.tar.gz: b73584561b8a558529b2e057e449896dedfff2c21ab859dacf82b070f75c7910
5
5
  SHA512:
6
- metadata.gz: 4bb2298f924a2aa2d5db31c7c05201188872333c36dd3e0bafb598ed087ec9a686695c27b1cdd2d33f067f2bbb47178c5bc700201406db856392997ef6605dbc
7
- data.tar.gz: f842586dc2d669196ce58bcbc279bc2b967fd0c8973d296323622c993e8d08422ce65f55b85cf96407aa4a668af15dea005fdf3f8917e520ca020c2851dd4bfa
6
+ metadata.gz: 6e42251e87faff4790ecfba572eca0dd70251fc58a4293b906560b526efa4bc14db00e01ee0e90c43a0d3f3dc355b36b8db3a4be5129529c071711f3a0b2506f
7
+ data.tar.gz: 167aa9f07dd033a5a3646edcff171a8dffea485d9cbb943c230526214c6d4eaa68761418321cc4e7795a0326361699181bd142377516ceadaa430d286628aea5
data/.rubocop.yml CHANGED
@@ -12,3 +12,6 @@ Style/StringLiteralsInInterpolation:
12
12
 
13
13
  Layout/LineLength:
14
14
  Max: 120
15
+
16
+ Style/Documentation:
17
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.3.1)
4
+ acidic_job (0.4.0)
5
5
  activerecord (>= 4.0.0)
6
6
  activesupport
7
7
 
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
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, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
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
- class Key < ActiveRecord::Base
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
- def succeeded?
39
- finished? && !failed?
40
- end
25
+ module ActiveJobExtension
26
+ extend ActiveSupport::Concern
41
27
 
42
- def failed?
43
- error_object.present?
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
- # discard_on MismatchedIdempotencyKeyAndJobArguments
53
- # discard_on UnknownRecoveryPoint
54
- # discard_on UnknownAtomicPhaseType
55
- # discard_on MissingRequiredAttribute
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
- def idempotently(with:) # &block
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
- end
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, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
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
- "db/migrate/create_acidic_job_keys.rb"
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.3.1
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-02 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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: '0'
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: activerecord
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.0
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: 4.0.0
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