acidic_job 1.0.0.pre4 → 1.0.0.pre5

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: d549814b3b04592d10c716f8715e67d15eb7383c3235ecb5d74319ab568b5507
4
- data.tar.gz: 5279750f02439d8fe453d6e5c430c3611513010bebbbdb18c2853d0d5b8d2764
3
+ metadata.gz: b8a9a11bcedbc8703e24c32db6474dfe963d8f97120c88c90dc4712026142d61
4
+ data.tar.gz: c558f6b90c1044c1320efc018fe4f9886f4af7ebab6a0c1fa8a991232e2b4065
5
5
  SHA512:
6
- metadata.gz: 7fa1a9fff8203a7a426738f8559d4f7afbcedc9e35832508a9550a113e348f158adc3c28ab58fb4f0ce6ca0fb3c9cc08c7f17d84cb2e574323e376d78188b18e
7
- data.tar.gz: 001dd65449fdc56b3ca2bd9b74be00bb0646b3875986844392b31ec4536a7135c23da66fa7b32e20b7a893ecfc255caaefd423a72bfdaa8d3b39a68fe469329f
6
+ metadata.gz: a9aef4b22eb6ee7860badda470c379d19395c60bc40072085ea3eae6ea140fd77103a07cf142a88310d90f67736300ceb3a755fe3f4283488caf36a7f872baf6
7
+ data.tar.gz: 8e1b7d428bc44f83274c3f64454d34c3467e7e701088aee862b71aec55c534a527d7d2e7e7a83fee4a94abe953284a092e8df24b55ae5c7fd195d8df968beb8f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (1.0.0.pre4)
4
+ acidic_job (1.0.0.pre5)
5
5
  activerecord (>= 6.1.0)
6
6
  activesupport
7
7
 
data/UPGRADE_GUIDE.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  result:
11
11
  ```
12
- Installing acidic_job 1.0.0.pre1 (was 0.7.7)
12
+ Installing acidic_job 1.0.0.pre4 (was 0.7.7)
13
13
  Bundle updated!
14
14
  ```
15
15
 
@@ -67,5 +67,15 @@ Once you have successfully migrated everything over and the new system has been
67
67
 
68
68
  ```bash
69
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
70
80
  rails db:migrate
71
81
  ```
@@ -3,113 +3,116 @@
3
3
  require "active_support/concern"
4
4
 
5
5
  module AcidicJob
6
- # recreate the original `Key` model
7
- class Key < ::ActiveRecord::Base
8
- RECOVERY_POINT_FINISHED = "FINISHED"
9
-
10
- self.table_name = "acidic_job_keys"
11
-
12
- serialize :error_object
13
- serialize :job_args
14
- serialize :workflow
15
- store :attr_accessors
16
- end
17
-
18
- # recreate the original `Staged` model
19
- class Staged < ActiveRecord::Base
20
- self.table_name = "staged_acidic_jobs"
21
-
22
- serialize :job_args
23
-
24
- after_create_commit :enqueue_job
25
-
26
- private
27
-
28
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
29
- def enqueue_job
30
- gid = { "staged_job_gid" => to_global_id.to_s }
31
-
32
- if job_args.is_a?(Hash) && job_args.key?("arguments")
33
- job_args["arguments"].concat([gid])
34
- else
35
- job_args.concat([gid])
36
- end
37
-
38
- case adapter
39
- when "activejob"
40
- ::ActiveJob::Base.deserialize(job_args).enqueue
41
- when "sidekiq"
42
- job_name.constantize.perform_async(*job_args)
43
- else
44
- raise UnknownJobAdapter.new(adapter: adapter)
45
- end
46
-
47
- # NOTE: record will be deleted after the job has successfully been performed
48
- true
49
- end
50
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
51
- end
52
-
53
- module UpgradeService
54
- def self.execute()
55
- # prepare an array to hold the attribute hashes to be passed to `insert_all`
56
- run_attributes = []
57
- # prepare an array to hold any `Key` records that we couldn't successfully map to `Run` records
58
- errored_keys = []
59
-
60
- # iterate over all `AcidicJob::Key` records in batches, preparing a `Run` attribute hash to be passed to `insert_all`
61
- ::AcidicJob::Key.find_each do |key|
62
- # map all of the simple attributes directly
63
- attributes = {
64
- id: key.id,
65
- staged: false,
66
- idempotency_key: key.idempotency_key,
67
- job_class: key.job_name,
68
- last_run_at: key.last_run_at,
69
- locked_at: key.locked_at,
70
- recovery_point: key.recovery_point,
71
- error_object: key.error_object,
72
- attr_accessors: key.attr_accessors,
73
- workflow: key.workflow,
74
- created_at: key.created_at,
75
- updated_at: key.updated_at
76
- }
77
-
78
- # prepare the more complicated `job_args` -> `serialized_job` translation
79
- job_class = key.job_name.constantize
80
- if defined?(::Sidekiq) && job_class.include?(::Sidekiq::Worker)
81
- job_class.include(::AcidicJob::Extensions::Sidekiq) unless job_class.include?(::AcidicJob::Extensions::Sidekiq)
82
- job_instance = job_class.new
83
- serialized_job = job_instance.serialize_job(*key.job_args)
84
- elsif defined?(::ActiveJob) && job_class < ::ActiveJob::Base
85
- job_class.include(::AcidicJob::Extensions::ActiveJob) unless job_class.include?(::AcidicJob::Extensions::ActiveJob)
86
- job_args = begin
87
- ::ActiveJob::Arguments.deserialize(key.job_args)
88
- rescue ::ActiveJob::DeserializationError
89
- key.job_args
90
- end
91
- job_instance = job_class.new(*job_args)
92
- serialized_job = job_instance.serialize_job()
93
- end
94
-
95
- attributes[:serialized_job] = serialized_job
96
- run_attributes << attributes
97
- rescue StandardError => exception
98
- errored_keys << [exception, key]
99
- end
100
-
101
- # insert all of the `Run` records
102
- ::AcidicJob::Run.insert_all(run_attributes)
103
-
104
- # delete all successfully migrated `Key` record
105
- ::AcidicJob::Key.where(id: ::AcidicJob::Run.select(:id)).delete_all
106
-
107
- # return a report of the upgrade migration
108
- {
109
- run_records: ::AcidicJob::Run.count,
110
- key_records: ::AcidicJob::Key.count,
111
- errored_keys: errored_keys
112
- }
113
- end
114
- end
6
+ # recreate the original `Key` model
7
+ class Key < ::ActiveRecord::Base
8
+ RECOVERY_POINT_FINISHED = "FINISHED"
9
+
10
+ self.table_name = "acidic_job_keys"
11
+
12
+ serialize :error_object
13
+ serialize :job_args
14
+ serialize :workflow
15
+ store :attr_accessors
16
+ end
17
+
18
+ # recreate the original `Staged` model
19
+ class Staged < ActiveRecord::Base
20
+ self.table_name = "staged_acidic_jobs"
21
+
22
+ serialize :job_args
23
+
24
+ after_create_commit :enqueue_job
25
+
26
+ private
27
+
28
+ def enqueue_job
29
+ gid = { "staged_job_gid" => to_global_id.to_s }
30
+
31
+ if job_args.is_a?(Hash) && job_args.key?("arguments")
32
+ job_args["arguments"].concat([gid])
33
+ else
34
+ job_args.concat([gid])
35
+ end
36
+
37
+ case adapter
38
+ when "activejob"
39
+ ::ActiveJob::Base.deserialize(job_args).enqueue
40
+ when "sidekiq"
41
+ job_name.constantize.perform_async(*job_args)
42
+ else
43
+ raise UnknownJobAdapter.new(adapter: adapter)
44
+ end
45
+
46
+ # NOTE: record will be deleted after the job has successfully been performed
47
+ true
48
+ end
49
+ end
50
+
51
+ module UpgradeService
52
+ def self.execute
53
+ # prepare an array to hold the attribute hashes to be passed to `insert_all`
54
+ run_attributes = []
55
+ # prepare an array to hold any `Key` records that we couldn't successfully map to `Run` records
56
+ errored_keys = []
57
+
58
+ # iterate over all `AcidicJob::Key` records in batches,
59
+ # preparing a `Run` attribute hash to be passed to `insert_all`
60
+ ::AcidicJob::Key.find_each do |key|
61
+ # map all of the simple attributes directly
62
+ attributes = {
63
+ id: key.id,
64
+ staged: false,
65
+ idempotency_key: key.idempotency_key,
66
+ job_class: key.job_name,
67
+ last_run_at: key.last_run_at,
68
+ locked_at: key.locked_at,
69
+ recovery_point: key.recovery_point,
70
+ error_object: key.error_object,
71
+ attr_accessors: key.attr_accessors,
72
+ workflow: key.workflow,
73
+ created_at: key.created_at,
74
+ updated_at: key.updated_at
75
+ }
76
+
77
+ # prepare the more complicated `job_args` -> `serialized_job` translation
78
+ job_class = key.job_name.constantize
79
+ if defined?(::Sidekiq) && job_class.include?(::Sidekiq::Worker)
80
+ unless job_class.include?(::AcidicJob::Extensions::Sidekiq)
81
+ job_class.include(::AcidicJob::Extensions::Sidekiq)
82
+ end
83
+ job_instance = job_class.new
84
+ serialized_job = job_instance.serialize_job(*key.job_args)
85
+ elsif defined?(::ActiveJob) && job_class < ::ActiveJob::Base
86
+ unless job_class.include?(::AcidicJob::Extensions::ActiveJob)
87
+ job_class.include(::AcidicJob::Extensions::ActiveJob)
88
+ end
89
+ job_args = begin
90
+ ::ActiveJob::Arguments.deserialize(key.job_args)
91
+ rescue ::ActiveJob::DeserializationError
92
+ key.job_args
93
+ end
94
+ job_instance = job_class.new(*job_args)
95
+ serialized_job = job_instance.serialize_job
96
+ end
97
+
98
+ attributes[:serialized_job] = serialized_job
99
+ run_attributes << attributes
100
+ rescue StandardError => e
101
+ errored_keys << [e, key]
102
+ end
103
+
104
+ # insert all of the `Run` records
105
+ ::AcidicJob::Run.insert_all(run_attributes)
106
+
107
+ # delete all successfully migrated `Key` record
108
+ ::AcidicJob::Key.where(id: ::AcidicJob::Run.select(:id)).delete_all
109
+
110
+ # return a report of the upgrade migration
111
+ {
112
+ run_records: ::AcidicJob::Run.count,
113
+ key_records: ::AcidicJob::Key.count,
114
+ errored_keys: errored_keys
115
+ }
116
+ end
117
+ end
115
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "1.0.0.pre4"
4
+ VERSION = "1.0.0.pre5"
5
5
  end
@@ -3,24 +3,24 @@
3
3
  require "rails/generators/active_record"
4
4
 
5
5
  module AcidicJob
6
- module Generators
7
- class DropTablesGenerator < ::Rails::Generators::Base
8
- include ActiveRecord::Generators::Migration
9
- source_root File.expand_path("templates", __dir__)
6
+ module Generators
7
+ class DropTablesGenerator < ::Rails::Generators::Base
8
+ include ActiveRecord::Generators::Migration
9
+ source_root File.expand_path("templates", __dir__)
10
10
 
11
- desc "Drops the pre-1.0 tables for the AcidicJob::Key and AcidicJob::Staged models."
11
+ desc "Drops the pre-1.0 tables for the AcidicJob::Key and AcidicJob::Staged models."
12
12
 
13
- def copy_migration
14
- migration_template "drop_acidic_job_keys_migration.rb.erb",
15
- "db/migrate/drop_old_acidic_job_tables.rb",
16
- migration_version: migration_version
17
- end
18
-
19
- protected
20
-
21
- def migration_version
22
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
23
- end
24
- end
25
- end
26
- end
13
+ def copy_migration
14
+ migration_template "drop_acidic_job_keys_migration.rb.erb",
15
+ "db/migrate/drop_old_acidic_job_tables.rb",
16
+ migration_version: migration_version
17
+ end
18
+
19
+ protected
20
+
21
+ def migration_version
22
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -7,21 +7,21 @@ module AcidicJob
7
7
  class InstallGenerator < ::Rails::Generators::Base
8
8
  include ActiveRecord::Generators::Migration
9
9
  source_root File.expand_path("templates", __dir__)
10
-
10
+
11
11
  desc "Generates a migration for the AcidicJob::Run table."
12
-
12
+
13
13
  # Copies the migration template to db/migrate.
14
14
  def copy_acidic_job_runs_migration_files
15
15
  migration_template "create_acidic_job_runs_migration.rb.erb",
16
16
  "db/migrate/create_acidic_job_runs.rb",
17
17
  migration_version: migration_version
18
18
  end
19
-
19
+
20
20
  protected
21
-
21
+
22
22
  def migration_version
23
23
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
24
24
  end
25
25
  end
26
26
  end
27
- end
27
+ end
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: 1.0.0.pre4
4
+ version: 1.0.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind