acidic_job 0.2.0 → 0.2.1

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: bcdd5a6f2496a5764d0d0b07f1263653a299d2dd2594ac051393278466f59bd2
4
- data.tar.gz: 25de84d0345eb47d2c1866b0f7e6824278214aeac1e212adad3504d9682c70a8
3
+ metadata.gz: ed6991438cd55a757d0c3606591dd3e39cf470a2fca7486afea1d9efbb948aa6
4
+ data.tar.gz: d5f078c2111b538ebc7b16df70b2986fa7e1c958716806ad4778c81817b9d3f4
5
5
  SHA512:
6
- metadata.gz: 64ddc179ec70f82ebce87438daad5d50a199daee773fd453f7dff27b21c26af5f7a35fe96f7167405b5a24eb275af6e9519cbe53018194ad9388ae0e2c276412
7
- data.tar.gz: a960d42269f80fedcd3c913ce7398a8c456759c07c58710533476f3648e38acde98921bdc93a4d26be8fa4405852d20ffbd0685802c114d87e5b9a6650941f59
6
+ metadata.gz: 24aa6c22959133bd68f3947bd15a742b6b314e7fb174b45fede5b598a85a63f04c2ba95a96e53ad3167fbfa1b9c9dcb981c7d59786be87d36520bab825255605
7
+ data.tar.gz: 02fad1948a7a17b81c2a6be0e48c271563fc7ce84a8de5ec5b84d3e1bb2ca65dbe6e838c4f4eb3c05eb2497424fe33fb5ea0e2c8e1001861ec75cb0c835a153a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.2.0)
4
+ acidic_job (0.2.1)
5
5
  activerecord (>= 4.0.0)
6
6
  activesupport
7
7
 
data/README.md CHANGED
@@ -33,9 +33,9 @@ And then execute:
33
33
 
34
34
  $ bundle install
35
35
 
36
- Or install it yourself as:
36
+ Or simply execute to install the gem yourself:
37
37
 
38
- $ gem install acidic_job
38
+ $ bundle add acidic_job
39
39
 
40
40
  Then, use the following command to copy over the AcidicJobKey migration.
41
41
 
data/lib/acidic_job.rb CHANGED
@@ -18,6 +18,33 @@ module AcidicJob
18
18
 
19
19
  class SerializedTransactionConflict < StandardError; end
20
20
 
21
+ class Key < ActiveRecord::Base
22
+ RECOVERY_POINT_FINISHED = "FINISHED"
23
+
24
+ self.table_name = "acidic_job_keys"
25
+
26
+ serialize :job_args, Hash
27
+ serialize :error_object
28
+
29
+ validates :job_name, presence: true
30
+ validates :job_args, presence: true
31
+ validates :idempotency_key, presence: true
32
+ validates :last_run_at, presence: true
33
+ validates :recovery_point, presence: true
34
+
35
+ def finished?
36
+ recovery_point == RECOVERY_POINT_FINISHED
37
+ end
38
+
39
+ def succeeded?
40
+ finished? && !failed?
41
+ end
42
+
43
+ def failed?
44
+ error_object.present?
45
+ end
46
+ end
47
+
21
48
  extend ActiveSupport::Concern
22
49
 
23
50
  included do
@@ -51,7 +78,7 @@ module AcidicJob
51
78
  phases = define_atomic_phases(defined_steps)
52
79
  # { create_ride_and_audit_record: <#Method >, ... }
53
80
 
54
- # find or create an AcidicJobKey record (our idempotency key) to store all information about this job
81
+ # find or create an Key record (our idempotency key) to store all information about this job
55
82
  # side-effect: will set the @key instance variable
56
83
  #
57
84
  # A key concept here is that if two requests try to insert or update within
@@ -69,7 +96,7 @@ module AcidicJob
69
96
  recovery_point = @key.recovery_point.to_sym
70
97
 
71
98
  case recovery_point
72
- when AcidicJobKey::RECOVERY_POINT_FINISHED.to_sym
99
+ when Key::RECOVERY_POINT_FINISHED.to_sym
73
100
  break
74
101
  else
75
102
  raise UnknownRecoveryPoint unless phases.key? recovery_point
@@ -125,7 +152,7 @@ module AcidicJob
125
152
  end
126
153
 
127
154
  ActiveRecord::Base.transaction(isolation: isolation_level) do
128
- @key = AcidicJobKey.find_by(idempotency_key: key_val)
155
+ @key = Key.find_by(idempotency_key: key_val)
129
156
 
130
157
  if @key
131
158
  # Programs enqueuing multiple jobs with different parameters but the
@@ -139,7 +166,7 @@ module AcidicJob
139
166
  # Lock the key and update latest run unless the job is already finished.
140
167
  @key.update!(last_run_at: Time.current, locked_at: Time.current) unless @key.finished?
141
168
  else
142
- @key = AcidicJobKey.create!(
169
+ @key = Key.create!(
143
170
  idempotency_key: key_val,
144
171
  locked_at: Time.current,
145
172
  last_run_at: Time.current,
@@ -163,14 +190,14 @@ module AcidicJob
163
190
  end
164
191
 
165
192
  def define_atomic_phases(defined_steps)
166
- defined_steps << AcidicJobKey::RECOVERY_POINT_FINISHED
193
+ defined_steps << Key::RECOVERY_POINT_FINISHED
167
194
 
168
195
  {}.tap do |phases|
169
196
  defined_steps.each_cons(2).map do |enter_method, exit_method|
170
197
  phases[enter_method] = lambda do
171
198
  method(enter_method).call
172
199
 
173
- if exit_method.to_s == AcidicJobKey::RECOVERY_POINT_FINISHED
200
+ if exit_method.to_s == Key::RECOVERY_POINT_FINISHED
174
201
  Response.new
175
202
  else
176
203
  RecoveryPoint.new(exit_method)
@@ -8,7 +8,7 @@ module AcidicJob
8
8
  def call(key:)
9
9
  key.update!(
10
10
  locked_at: nil,
11
- recovery_point: AcidicJobKey::RECOVERY_POINT_FINISHED
11
+ recovery_point: Key::RECOVERY_POINT_FINISHED
12
12
  )
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -23,7 +23,7 @@ class AcidicJobGenerator < ActiveRecord::Generators::Base
23
23
  # Copies the migration template to db/migrate.
24
24
  def copy_files
25
25
  migration_template "migration.rb",
26
- "db/migrate/create_acidid_job_keys.rb"
26
+ "db/migrate/create_acidic_job_keys.rb"
27
27
  end
28
28
 
29
29
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acidic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind