acidic_job 1.0.0.beta.10 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +12 -36
  3. data/.gitignore +0 -5
  4. data/.ruby_version +1 -0
  5. data/Gemfile +31 -0
  6. data/Gemfile.lock +130 -136
  7. data/README.md +58 -278
  8. data/acidic_job.gemspec +2 -15
  9. data/bin/console +2 -4
  10. data/lib/acidic_job/awaiting.rb +68 -0
  11. data/lib/acidic_job/errors.rb +19 -11
  12. data/lib/acidic_job/extensions/action_mailer.rb +11 -3
  13. data/lib/acidic_job/extensions/active_job.rb +39 -0
  14. data/lib/acidic_job/extensions/noticed.rb +11 -5
  15. data/lib/acidic_job/extensions/sidekiq.rb +101 -0
  16. data/lib/acidic_job/finished_point.rb +5 -3
  17. data/lib/acidic_job/idempotency_key.rb +15 -18
  18. data/lib/acidic_job/perform_wrapper.rb +36 -9
  19. data/lib/acidic_job/recovery_point.rb +3 -2
  20. data/lib/acidic_job/run.rb +42 -268
  21. data/lib/acidic_job/staging.rb +30 -0
  22. data/lib/acidic_job/step.rb +83 -0
  23. data/lib/acidic_job/version.rb +1 -1
  24. data/lib/acidic_job.rb +244 -20
  25. data/lib/generators/acidic_job_generator.rb +35 -0
  26. data/lib/generators/templates/create_acidic_job_runs_migration.rb.erb +19 -0
  27. metadata +15 -209
  28. data/.github/FUNDING.yml +0 -13
  29. data/.tool-versions +0 -1
  30. data/UPGRADE_GUIDE.md +0 -81
  31. data/combustion/log/test.log +0 -0
  32. data/gemfiles/rails_6.1_sidekiq_6.4.gemfile +0 -10
  33. data/gemfiles/rails_6.1_sidekiq_6.5.gemfile +0 -10
  34. data/gemfiles/rails_7.0_sidekiq_6.4.gemfile +0 -10
  35. data/gemfiles/rails_7.0_sidekiq_6.5.gemfile +0 -10
  36. data/gemfiles/rails_7.1_sidekiq_6.4.gemfile +0 -10
  37. data/gemfiles/rails_7.1_sidekiq_6.5.gemfile +0 -10
  38. data/lib/acidic_job/active_kiq.rb +0 -114
  39. data/lib/acidic_job/arguments.rb +0 -22
  40. data/lib/acidic_job/base.rb +0 -11
  41. data/lib/acidic_job/logger.rb +0 -31
  42. data/lib/acidic_job/mixin.rb +0 -250
  43. data/lib/acidic_job/processor.rb +0 -95
  44. data/lib/acidic_job/rails.rb +0 -40
  45. data/lib/acidic_job/serializer.rb +0 -24
  46. data/lib/acidic_job/serializers/exception_serializer.rb +0 -41
  47. data/lib/acidic_job/serializers/finished_point_serializer.rb +0 -24
  48. data/lib/acidic_job/serializers/job_serializer.rb +0 -27
  49. data/lib/acidic_job/serializers/range_serializer.rb +0 -28
  50. data/lib/acidic_job/serializers/recovery_point_serializer.rb +0 -25
  51. data/lib/acidic_job/serializers/worker_serializer.rb +0 -27
  52. data/lib/acidic_job/test_case.rb +0 -9
  53. data/lib/acidic_job/testing.rb +0 -73
  54. data/lib/acidic_job/workflow.rb +0 -70
  55. data/lib/acidic_job/workflow_builder.rb +0 -35
  56. data/lib/acidic_job/workflow_step.rb +0 -103
  57. data/lib/generators/acidic_job/drop_tables_generator.rb +0 -26
  58. data/lib/generators/acidic_job/install_generator.rb +0 -27
  59. data/lib/generators/acidic_job/templates/create_acidic_job_runs_migration.rb.erb +0 -19
  60. data/lib/generators/acidic_job/templates/drop_acidic_job_keys_migration.rb.erb +0 -27
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acidic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.10
4
+ version: 1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-13 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activejob
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activerecord
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: 6.1.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: 6.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: activesupport
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,174 +38,20 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: combustion
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: net-smtp
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: noticed
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
41
  - !ruby/object:Gem::Dependency
112
42
  name: railties
113
43
  requirement: !ruby/object:Gem::Requirement
114
44
  requirements:
115
45
  - - ">="
116
46
  - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rake
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: rubocop-minitest
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rubocop-rake
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
47
+ version: 6.1.0
174
48
  type: :development
175
49
  prerelease: false
176
50
  version_requirements: !ruby/object:Gem::Requirement
177
51
  requirements:
178
52
  - - ">="
179
53
  - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: sidekiq
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: simplecov
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: sqlite3
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
54
+ version: 6.1.0
223
55
  description: Idempotent operations for Rails apps, built on top of ActiveJob.
224
56
  email:
225
57
  - stephen.margheim@gmail.com
@@ -227,61 +59,36 @@ executables: []
227
59
  extensions: []
228
60
  extra_rdoc_files: []
229
61
  files:
230
- - ".github/FUNDING.yml"
231
62
  - ".github/workflows/main.yml"
232
63
  - ".gitignore"
233
64
  - ".rubocop.yml"
234
- - ".tool-versions"
65
+ - ".ruby_version"
235
66
  - Gemfile
236
67
  - Gemfile.lock
237
68
  - LICENSE
238
69
  - README.md
239
70
  - Rakefile
240
- - UPGRADE_GUIDE.md
241
71
  - acidic_job.gemspec
242
72
  - bin/console
243
73
  - bin/setup
244
74
  - blog_post.md
245
- - combustion/log/test.log
246
- - gemfiles/rails_6.1_sidekiq_6.4.gemfile
247
- - gemfiles/rails_6.1_sidekiq_6.5.gemfile
248
- - gemfiles/rails_7.0_sidekiq_6.4.gemfile
249
- - gemfiles/rails_7.0_sidekiq_6.5.gemfile
250
- - gemfiles/rails_7.1_sidekiq_6.4.gemfile
251
- - gemfiles/rails_7.1_sidekiq_6.5.gemfile
252
75
  - lib/acidic_job.rb
253
- - lib/acidic_job/active_kiq.rb
254
- - lib/acidic_job/arguments.rb
255
- - lib/acidic_job/base.rb
76
+ - lib/acidic_job/awaiting.rb
256
77
  - lib/acidic_job/errors.rb
257
78
  - lib/acidic_job/extensions/action_mailer.rb
79
+ - lib/acidic_job/extensions/active_job.rb
258
80
  - lib/acidic_job/extensions/noticed.rb
81
+ - lib/acidic_job/extensions/sidekiq.rb
259
82
  - lib/acidic_job/finished_point.rb
260
83
  - lib/acidic_job/idempotency_key.rb
261
- - lib/acidic_job/logger.rb
262
- - lib/acidic_job/mixin.rb
263
84
  - lib/acidic_job/perform_wrapper.rb
264
- - lib/acidic_job/processor.rb
265
- - lib/acidic_job/rails.rb
266
85
  - lib/acidic_job/recovery_point.rb
267
86
  - lib/acidic_job/run.rb
268
- - lib/acidic_job/serializer.rb
269
- - lib/acidic_job/serializers/exception_serializer.rb
270
- - lib/acidic_job/serializers/finished_point_serializer.rb
271
- - lib/acidic_job/serializers/job_serializer.rb
272
- - lib/acidic_job/serializers/range_serializer.rb
273
- - lib/acidic_job/serializers/recovery_point_serializer.rb
274
- - lib/acidic_job/serializers/worker_serializer.rb
275
- - lib/acidic_job/test_case.rb
276
- - lib/acidic_job/testing.rb
87
+ - lib/acidic_job/staging.rb
88
+ - lib/acidic_job/step.rb
277
89
  - lib/acidic_job/version.rb
278
- - lib/acidic_job/workflow.rb
279
- - lib/acidic_job/workflow_builder.rb
280
- - lib/acidic_job/workflow_step.rb
281
- - lib/generators/acidic_job/drop_tables_generator.rb
282
- - lib/generators/acidic_job/install_generator.rb
283
- - lib/generators/acidic_job/templates/create_acidic_job_runs_migration.rb.erb
284
- - lib/generators/acidic_job/templates/drop_acidic_job_keys_migration.rb.erb
90
+ - lib/generators/acidic_job_generator.rb
91
+ - lib/generators/templates/create_acidic_job_runs_migration.rb.erb
285
92
  homepage: https://github.com/fractaledmind/acidic_job
286
93
  licenses:
287
94
  - MIT
@@ -289,7 +96,6 @@ metadata:
289
96
  homepage_uri: https://github.com/fractaledmind/acidic_job
290
97
  source_code_uri: https://github.com/fractaledmind/acidic_job
291
98
  changelog_uri: https://github.com/fractaledmind/acidic_job/CHANGELOG.md
292
- rubygems_mfa_required: 'true'
293
99
  post_install_message:
294
100
  rdoc_options: []
295
101
  require_paths:
@@ -305,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
111
  - !ruby/object:Gem::Version
306
112
  version: 1.3.1
307
113
  requirements: []
308
- rubygems_version: 3.3.7
114
+ rubygems_version: 3.2.22
309
115
  signing_key:
310
116
  specification_version: 4
311
117
  summary: Idempotent operations for Rails apps, built on top of ActiveJob.
data/.github/FUNDING.yml DELETED
@@ -1,13 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: fractaledmind
4
- patreon: # Replace with a single Patreon username
5
- open_collective: # Replace with a single Open Collective username
6
- ko_fi: # Replace with a single Ko-fi username
7
- tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
- liberapay: # Replace with a single Liberapay username
10
- issuehunt: # Replace with a single IssueHunt username
11
- otechie: # Replace with a single Otechie username
12
- lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13
- custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.1.1
data/UPGRADE_GUIDE.md DELETED
@@ -1,81 +0,0 @@
1
- # AcidicJob Upgrade Guide
2
-
3
- ## 1. Update version requirements in `Gemfile`
4
-
5
- ```diff
6
- - gem "acidic_job"
7
- + gem "acidic_job", "~> 1.0.0.pre1"
8
- ```
9
-
10
- result:
11
- ```
12
- Installing acidic_job 1.0.0.pre4 (was 0.7.7)
13
- Bundle updated!
14
- ```
15
-
16
- ## 2. Generate migration for new `AcidicJob::Run` model
17
-
18
- ```bash
19
- rails generate acidic_job
20
- ```
21
-
22
- result:
23
- ```
24
- create db/migrate/#{yyyymmddhhmmss}_create_acidic_job_runs.rb
25
- ```
26
-
27
- ## 3. Delete any unneeded `AcidicJob::Key` records
28
-
29
- Typically, records that are already finished do not need to be retained. Sometimes, however, applications key finished records around for some amount of time for debugging or metrics aggregation. Whatever your application's logic is for whether or not an `AcidicJob::Key` record is still needed, for all unneeded records, delete them.
30
-
31
- For example, this would delete all finished `Key` records over 1 month old:
32
-
33
- ```ruby
34
- AcidicJob::Key.where(recovery_point: AcidicJob::Key::RECOVERY_POINT_FINISHED, last_run_at: ..1.month.ago).delete_all
35
- ```
36
-
37
- ## 4. Migrate `AcidicJob::Key` to `AcidicJob::Run`
38
-
39
- `AcidicJob` ships with an upgrade module that provides a script to migrate older `Key` records to the new `Run` model.
40
-
41
- ```ruby
42
- AcidicJob::UpgradeService.execute
43
- ```
44
-
45
- This script will prepare an `insert_all` command for `Run` records by mapping the older `Key` data to the new `Run` schema. It also creates the new `Run` records with the same `id` as their `Key` counterparts, and then deletes all `Key` records successfully mapped over. Any `Key` records that were failed to be mapped over will be reported, along with the exception, in the `errored_keys` portion of the resulting hash.
46
-
47
- result:
48
- ```
49
- {
50
- run_records: <Integer>,
51
- key_records: <Integer>,
52
- errored_keys: <Array>
53
- }
54
- ```
55
-
56
- ## 5. Triage remaining `AcidicJob::Key` records
57
-
58
- If there were any `AcidicJob::Key` records that failed to be mapped to the new `Run` model, you will need to manually triage whatever the exception was. In all likelihood, the exception would be relating to the translation of the `Key#job_args` field to the `Run#serialized_job` field, as all other fields have a fairly straight-forward mapping. If you can't resolve the issue, please open an Issue in GitHub.
59
-
60
- ## 6. Ensure all `AcidicJob::Staged` records are processed
61
-
62
- `AcidicJob` still ships with an upgrade module that provides the older `Key` and `Staged` records, so this functionality will still be present to handle any existing records in your database when you deploy the updated version.
63
-
64
- ## 7. Remove the old tables
65
-
66
- Once you have successfully migrated everything over and the new system has been running smoothly for some time, you should drop the old `acidic_job_keys` and `staged_acidic_jobs` tables. We provide a migration generator just for this purpose:
67
-
68
- ```bash
69
- rails generate acidic_job:drop_tables
70
- ```
71
-
72
- result:
73
- ```
74
- create db/migrate/#{yyyymmddhhmmss}_drop_old_acidic_job_tables.rb
75
- ```
76
-
77
- You can then run the migration to have those tables removed:
78
-
79
- ```bash
80
- rails db:migrate
81
- ```
File without changes
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 6.1.0"
6
- gem "railties", "~> 6.1.0"
7
-
8
- gem "sidekiq", "~> 6.4.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 6.1.0"
6
- gem "railties", "~> 6.1.0"
7
-
8
- gem "sidekiq", "~> 6.5.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 7.0.0"
6
- gem "railties", "~> 7.0.0"
7
-
8
- gem "sidekiq", "~> 6.4.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 7.0.0"
6
- gem "railties", "~> 7.0.0"
7
-
8
- gem "sidekiq", "~> 6.5.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 7.1.0"
6
- gem "railties", "~> 7.1.0"
7
-
8
- gem "sidekiq", "~> 6.4.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 7.1.0"
6
- gem "railties", "~> 7.1.0"
7
-
8
- gem "sidekiq", "~> 6.5.0"
9
-
10
- gemspec path: "../"
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sidekiq"
4
- require "active_support/callbacks"
5
- require "active_support/core_ext/module/concerning"
6
- require_relative "mixin"
7
-
8
- module AcidicJob
9
- class ActiveKiq
10
- include ::Sidekiq::Worker
11
- include ::Sidekiq::JobUtil
12
- include ::ActiveSupport::Callbacks
13
- define_callbacks :perform
14
- include Mixin
15
-
16
- concerning :Initializing do
17
- included do
18
- attr_accessor :arguments
19
- attr_accessor :job_id
20
- attr_accessor :queue_name
21
- attr_accessor :sidekiq_options
22
- end
23
- ##
24
- # Creates a new job instance.
25
- # +args+ are the arguments, if any, that will be passed to the perform method
26
- # +opts+ are any options to configure the job
27
- def initialize(*arguments)
28
- @arguments = arguments
29
- @job_id = ::SecureRandom.uuid
30
- @sidekiq_options = sidekiq_options_hash || ::Sidekiq.default_job_options
31
- @queue_name = @sidekiq_options["queue"]
32
- end
33
-
34
- # Sidekiq sets the `jid` when it is processing jobs off of the Redis queue.
35
- # We override the job identifier when staging jobs to encode the `Run` record global id.
36
- # We also override how "ActiveKiq" instance's expose the job identifier to match ActiveJob.
37
- # So, we need to ensure that when `jid=` is called, we set the `job_id` instead.
38
- def jid=(value)
39
- super
40
- @job_id = value
41
- end
42
- end
43
-
44
- concerning :Performing do
45
- class_methods do
46
- def perform_now(*args, **kwargs)
47
- new.perform(*args, **kwargs)
48
- end
49
- end
50
-
51
- def perform_now(*args, **kwargs)
52
- perform(*args, **kwargs)
53
- end
54
-
55
- def enqueue
56
- ::Sidekiq::Client.push(
57
- "class" => self.class,
58
- "args" => @arguments,
59
- "jid" => @job_id,
60
- "queue" => @queue_name
61
- )
62
- end
63
- end
64
-
65
- concerning :Serializing do
66
- class_methods do
67
- def deserialize(job_data)
68
- job = job_data["job_class"].constantize.new
69
- job.deserialize(job_data)
70
- job
71
- end
72
- end
73
-
74
- def serialize
75
- return @serialize if defined? @serialize
76
-
77
- item = @sidekiq_options.merge("class" => self.class.name, "args" => @arguments || [])
78
- worker_hash = normalize_item(item)
79
-
80
- @serialize = {
81
- "job_class" => worker_hash["class"],
82
- "job_id" => @job_id,
83
- "queue_name" => worker_hash["queue"],
84
- "arguments" => worker_hash["args"]
85
- }.merge(worker_hash.except("class", "jid", "queue", "args"))
86
- end
87
-
88
- def deserialize(job_data)
89
- self.job_id = job_data["job_id"]
90
- self.queue_name = job_data["queue_name"]
91
- self.arguments = job_data["arguments"]
92
- self
93
- end
94
- end
95
-
96
- # Following approach used by ActiveJob
97
- # https://github.com/rails/rails/blob/93c9534c9871d4adad4bc33b5edc355672b59c61/activejob/lib/active_job/callbacks.rb
98
- concerning :Callbacks do
99
- class_methods do
100
- def around_perform(*filters, &blk)
101
- set_callback(:perform, :around, *filters, &blk)
102
- end
103
-
104
- def before_perform(*filters, &blk)
105
- set_callback(:perform, :before, *filters, &blk)
106
- end
107
-
108
- def after_perform(*filters, &blk)
109
- set_callback(:perform, :after, *filters, &blk)
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_job/arguments"
4
-
5
- module AcidicJob
6
- module Arguments
7
- include ActiveJob::Arguments
8
- extend self # rubocop:disable Style/ModuleFunction
9
-
10
- # `ActiveJob` will throw an error if it tries to deserialize a GlobalID record.
11
- # However, this isn't the behavior that we want for our custom `ActiveRecord` serializer.
12
- # Since `ActiveRecord` does _not_ reset instance record state to its pre-transactional state
13
- # on a transaction ROLLBACK, we can have GlobalID entries in a serialized column that point to
14
- # non-persisted records. This is ok. We should simply return `nil` for that portion of the
15
- # serialized field.
16
- def deserialize_global_id(hash)
17
- GlobalID::Locator.locate hash[GLOBALID_KEY]
18
- rescue ActiveRecord::RecordNotFound
19
- nil
20
- end
21
- end
22
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_job/queue_adapters"
4
- require "active_job/base"
5
- require_relative "mixin"
6
-
7
- module AcidicJob
8
- class Base < ActiveJob::Base
9
- include Mixin
10
- end
11
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "logger"
4
- require "active_support/tagged_logging"
5
-
6
- module AcidicJob
7
- class Logger < ::Logger
8
- def log_run_event(msg, job = nil, run = nil)
9
- tags = [
10
- run&.idempotency_key,
11
- inspect_name(job)
12
- ].compact
13
-
14
- tagged(*tags) { debug(msg) }
15
- end
16
-
17
- def inspect_name(obj)
18
- return if obj.nil?
19
-
20
- obj.inspect.split.first.remove("#<")
21
- end
22
- end
23
-
24
- def self.logger
25
- @logger ||= ActiveSupport::TaggedLogging.new(AcidicJob::Logger.new($stdout, level: :debug))
26
- end
27
-
28
- def self.silence_logger!
29
- @logger = ActiveSupport::TaggedLogging.new(AcidicJob::Logger.new(IO::NULL, level: :debug))
30
- end
31
- end