-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Active Job extension for Labels (#1188)
- Loading branch information
1 parent
5247637
commit a181f81
Showing
15 changed files
with
293 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateGoodJobLabels < ActiveRecord::Migration[7.1] | ||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.column_exists?(:good_jobs, :labels) | ||
end | ||
end | ||
|
||
add_column :good_jobs, :labels, :text, array: true | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
demo/db/migrate/20231216183915_create_good_job_labels_index.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateGoodJobLabelsIndex < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels) | ||
add_index :good_jobs, :labels, where: "(labels IS NOT NULL)", | ||
using: :gin, name: :index_good_jobs_on_labels, algorithm: :concurrently | ||
end | ||
end | ||
|
||
dir.down do | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels) | ||
remove_index :good_jobs, name: :index_good_jobs_on_labels | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
lib/generators/good_job/templates/update/migrations/08_create_good_job_labels.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateGoodJobLabels < ActiveRecord::Migration<%= migration_version %> | ||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.column_exists?(:good_jobs, :labels) | ||
end | ||
end | ||
|
||
add_column :good_jobs, :labels, :text, array: true | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/generators/good_job/templates/update/migrations/09_create_good_job_labels_index.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateGoodJobLabelsIndex < ActiveRecord::Migration<%= migration_version %> | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels) | ||
add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", | ||
name: :index_good_jobs_on_labels, algorithm: :concurrently | ||
end | ||
end | ||
|
||
dir.down do | ||
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels) | ||
remove_index :good_jobs, name: :index_good_jobs_on_labels | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob | ||
module ActiveJobExtensions | ||
module Labels | ||
extend ActiveSupport::Concern | ||
|
||
module Prepends | ||
def initialize(*arguments) | ||
super | ||
self.good_job_labels = Array(self.class.good_job_labels) | ||
end | ||
|
||
def enqueue(options = {}) | ||
self.good_job_labels = Array(options[:good_job_labels]) if options.key?(:good_job_labels) | ||
super | ||
end | ||
|
||
def deserialize(job_data) | ||
super | ||
self.good_job_labels = job_data.delete("good_job_labels")&.dup || [] | ||
end | ||
end | ||
|
||
included do | ||
prepend Prepends | ||
class_attribute :good_job_labels, instance_accessor: false, instance_predicate: false, default: [] | ||
attr_accessor :good_job_labels | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.