delayed_job_json 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5df5eb2a641bfd511bc8ff10c9103373588917f851376dfcb883db4adfeac66b
4
+ data.tar.gz: c89630ae7e529ee4447d207deeb24ef230b500d378f5eb55e869edae6aefb0c6
5
+ SHA512:
6
+ metadata.gz: '038a824b83c46ca64bb9b892d19a64b686d7d3189de6552f7d4e8a79cc3d4126ad08947a1aabeaf2c1f5321ead205a242f6e34f35e657f6da1f408059846c21c'
7
+ data.tar.gz: 937d89f1592fd6a78ef43bb2a953f813e1951d5679b6084958be148733a0e78d279b01ced8bb76a316ae00c92c6daba780e20f311e9a1d661dd84f7f30912f51
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-20.04
8
+ services:
9
+ postgres:
10
+ image: postgres:9.5
11
+ env:
12
+ POSTGRES_USER: postgres
13
+ POSTGRES_PASSWORD: postgres
14
+ ports:
15
+ - 5432:5432
16
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
17
+ mysql:
18
+ image: mysql:5.7
19
+ env:
20
+ MYSQL_ALLOW_EMPTY_PASSWORD: yes
21
+ ports:
22
+ - 3306:3306
23
+ options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10
24
+ strategy:
25
+ fail-fast: false
26
+ matrix:
27
+ ruby: [2.7, '3.0', 3.1, 3.2]
28
+ gemfile: ['rails60', 'rails61', 'rails70']
29
+ database: ['postgresql', 'mysql', 'sqlite']
30
+
31
+ name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}, ${{ matrix.database }}
32
+
33
+ env:
34
+ POSTGRES_USER: postgres
35
+ POSTGRES_PASSWORD: postgres
36
+ DATABASE: ${{ matrix.database }}
37
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
38
+
39
+ steps:
40
+ - uses: actions/checkout@v3
41
+ - uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: ${{ matrix.ruby }}
44
+ bundler-cache: true
45
+ - name: Prepare test
46
+ run: |
47
+ cd spec/dummy
48
+ BUNDLE_GEMFILE=../../${{ env.BUNDLE_GEMFILE }} RAILS_ENV=test bundle exec rake db:create db:migrate
49
+ cd ../..
50
+ - name: Run test
51
+ run: |
52
+ bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /gemfiles/*gemfile.lock
4
+ /coverage/
5
+ /pkg/
6
+ /spec/reports/
7
+ /spec/**/db/*.sqlite3
8
+ /spec/**/log/*.log
9
+ /spec/**/tmp/*
10
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --require rails_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0
4
+
5
+ * First release.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Yoshikazu Kaneta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # DelayedJobJson
2
+
3
+ Migrate handler of text column to json column for delayed_job.
4
+
5
+ ## Dependencies
6
+
7
+ * ruby 2.7+
8
+ * activerecord 6.0+
9
+ * delayed_job 4.1
10
+ * delayed_job_active_record 4.1
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'delayed_job_json'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ ## Usage
25
+
26
+ Generate migration files:
27
+
28
+ $ rails generate delayed_job_json:migration
29
+
30
+ Edit generated files and leave codes only for your database. An example of generated file is shown as follows:
31
+
32
+ ```ruby
33
+ class AddPayloadToDelayedJobs < ActiveRecord::Migration[7.0]
34
+ def up
35
+ case ENV['DATABASE']
36
+ when 'postgresql'
37
+ add_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
38
+ add_index :delayed_jobs, :payload, using: :gin
39
+ when 'mysql'
40
+ add_column :delayed_jobs, :payload, :json
41
+ else
42
+ add_column :delayed_jobs, :payload, :json, null: false, default: {}
43
+ end
44
+ end
45
+
46
+ def down
47
+ case ENV['DATABASE']
48
+ when 'postgresql'
49
+ remove_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
50
+ when 'mysql'
51
+ remove_column :delayed_jobs, :payload, :json
52
+ else
53
+ remove_column :delayed_jobs, :payload, :json, null: false, default: {}
54
+ end
55
+ end
56
+ end
57
+ ```
58
+
59
+ Then run migration:
60
+
61
+ $ rake db:migrate
62
+
63
+ This migration adds `payload` column to delayed_jobs table, and YAML data in `handler` column is migrated to `payload` as json data.
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kanety/delayed_job_json.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delayed/backend/json/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "delayed_job_json"
8
+ spec.version = Delayed::Backend::Json::VERSION
9
+ spec.authors = ["Yoshikazu Kaneta"]
10
+ spec.email = ["kaneta@sitebridge.co.jp"]
11
+ spec.summary = %q{Migrate handler of text column to json column for delayed_job}
12
+ spec.description = %q{Migrate handler of text column to json column for delayed_job}
13
+ spec.homepage = "https://github.com/kanety/delayed_job_json"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.7'
22
+
23
+ spec.add_dependency "delayed_job", ">= 4.1"
24
+ spec.add_dependency "delayed_job_active_record", ">= 4.1"
25
+ spec.add_dependency "activesupport", ">= 6.0"
26
+ spec.add_dependency "activerecord", ">= 6.0"
27
+
28
+ spec.add_development_dependency "rails"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec-rails"
31
+ spec.add_development_dependency "simplecov"
32
+ spec.add_development_dependency "pg"
33
+ spec.add_development_dependency "mysql2"
34
+ spec.add_development_dependency "sqlite3"
35
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 6.0.0"
4
+ gem "psych", "~> 3.3.0"
5
+
6
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 6.1.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 7.0.1"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,23 @@
1
+ module Delayed
2
+ module Backend
3
+ module Json
4
+ module Patch
5
+ def payload_object=(object)
6
+ @payload_object = object
7
+ self.handler = '{}'
8
+ self.payload = object.job_data
9
+ end
10
+
11
+ def payload_object
12
+ if payload.present?
13
+ @payload_object ||= ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(payload)
14
+ else
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ Delayed::Job.prepend Delayed::Backend::Json::Patch
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Delayed
4
+ module Backend
5
+ module Json
6
+ VERSION = "1.0.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'json/patch'
@@ -0,0 +1,4 @@
1
+ require 'active_support'
2
+ require 'delayed_job_active_record'
3
+
4
+ require_relative 'delayed/backend/json'
@@ -0,0 +1,25 @@
1
+ require 'rails/generators'
2
+
3
+ module DelayedJobJson
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ source_root File.join(File.dirname(__FILE__), 'templates')
8
+
9
+ def create_migration_file
10
+ migration_template "migration1.rb", "db/migrate/add_payload_to_delayed_jobs.rb", migration_version: migration_version
11
+ migration_template "migration2.rb", "db/migrate/migrate_handler_to_payload_on_delayed_jobs.rb", migration_version: migration_version
12
+ end
13
+
14
+ private
15
+
16
+ def migration_version
17
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
18
+ end
19
+
20
+ def self.next_migration_number(dirname)
21
+ next_migration_number = current_migration_number(dirname) + 1
22
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ class AddPayloadToDelayedJobs < ActiveRecord::Migration<%= migration_version %>
2
+ def up
3
+ case ENV['DATABASE']
4
+ when 'postgresql'
5
+ add_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
6
+ add_index :delayed_jobs, :payload, using: :gin
7
+ when 'mysql'
8
+ add_column :delayed_jobs, :payload, :json
9
+ else
10
+ add_column :delayed_jobs, :payload, :json, null: false, default: {}
11
+ end
12
+ end
13
+
14
+ def down
15
+ case ENV['DATABASE']
16
+ when 'postgresql'
17
+ remove_column :delayed_jobs, :payload, :jsonb, null: false, default: {}
18
+ when 'mysql'
19
+ remove_column :delayed_jobs, :payload, :json
20
+ else
21
+ remove_column :delayed_jobs, :payload, :json, null: false, default: {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ class MigrateHandlerToPayloadOnDelayedJobs < ActiveRecord::Migration<%= migration_version %>
2
+ class DelayedJob < ActiveRecord::Base
3
+ end
4
+
5
+ def up
6
+ DelayedJob.find_each do |job|
7
+ loaded = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(job.handler) : YAML.load(job.handler)
8
+ job.update_columns(payload: loaded.job_data)
9
+ end
10
+ end
11
+
12
+ def down
13
+ DelayedJob.find_each do |job|
14
+ handler = ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(job.payload).to_yaml
15
+ job.update_columns(handler: handler)
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delayed_job_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshikazu Kaneta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: delayed_job
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: delayed_job_active_record
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '6.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '6.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
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: rake
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: rspec-rails
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
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !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: pg
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: mysql2
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: sqlite3
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
+ description: Migrate handler of text column to json column for delayed_job
168
+ email:
169
+ - kaneta@sitebridge.co.jp
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".github/workflows/ci.yml"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - CHANGELOG.md
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - delayed_job_json.gemspec
183
+ - gemfiles/rails60.gemfile
184
+ - gemfiles/rails61.gemfile
185
+ - gemfiles/rails70.gemfile
186
+ - lib/delayed/backend/json.rb
187
+ - lib/delayed/backend/json/patch.rb
188
+ - lib/delayed/backend/json/version.rb
189
+ - lib/delayed_job_json.rb
190
+ - lib/generators/delayed_job_json/migration_generator.rb
191
+ - lib/generators/delayed_job_json/templates/migration1.rb
192
+ - lib/generators/delayed_job_json/templates/migration2.rb
193
+ homepage: https://github.com/kanety/delayed_job_json
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '2.7'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubygems_version: 3.3.3
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Migrate handler of text column to json column for delayed_job
216
+ test_files: []