-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use unique index on [cron_key, cron_at] columns to prevent duplicate …
…cron jobs from being enqueued (#423)
- Loading branch information
1 parent
c8828e5
commit ec73ea3
Showing
15 changed files
with
123 additions
and
6 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
14 changes: 14 additions & 0 deletions
14
lib/generators/good_job/templates/update/migrations/02_add_cron_at_to_good_jobs.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,14 @@ | ||
# frozen_string_literal: true | ||
class AddCronAtToGoodJobs < 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, :cron_at) | ||
end | ||
end | ||
|
||
add_column :good_jobs, :cron_at, :timestamp | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...rs/good_job/templates/update/migrations/03_add_cron_key_cron_at_index_to_good_jobs.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,20 @@ | ||
# frozen_string_literal: true | ||
class AddCronKeyCronAtIndexToGoodJobs < ActiveRecord::Migration<%= migration_version %> | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
end | ||
end | ||
|
||
add_index :good_jobs, | ||
[:cron_key, :cron_at], | ||
algorithm: :concurrently, | ||
name: :index_good_jobs_on_cron_key_and_cron_at, | ||
unique: true | ||
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
RSpec.describe GoodJob::CurrentThread do | ||
[ | ||
:cron_at, | ||
:cron_key, | ||
:execution, | ||
:error_on_discard, | ||
|
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
14 changes: 14 additions & 0 deletions
14
spec/test_app/db/migrate/20211011221037_add_cron_at_to_good_jobs.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,14 @@ | ||
# frozen_string_literal: true | ||
class AddCronAtToGoodJobs < ActiveRecord::Migration[5.2] | ||
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, :cron_at) | ||
end | ||
end | ||
|
||
add_column :good_jobs, :cron_at, :timestamp | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
spec/test_app/db/migrate/20211011221038_add_cron_key_cron_at_index_to_good_jobs.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,20 @@ | ||
# frozen_string_literal: true | ||
class AddCronKeyCronAtIndexToGoodJobs < ActiveRecord::Migration[5.2] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) | ||
end | ||
end | ||
|
||
add_index :good_jobs, | ||
[:cron_key, :cron_at], | ||
algorithm: :concurrently, | ||
name: :index_good_jobs_on_cron_key_and_cron_at, | ||
unique: true | ||
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