Skip to content

Commit

Permalink
Remove database migration shims and old migrations (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon authored Jun 26, 2022
1 parent 275c372 commit 253a084
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 107 deletions.
2 changes: 1 addition & 1 deletion app/controllers/good_job/processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module GoodJob
class ProcessesController < GoodJob::ApplicationController
def index
@processes = GoodJob::Process.active.order(created_at: :desc) if GoodJob::Process.migrated?
@processes = GoodJob::Process.active.order(created_at: :desc)
end
end
end
10 changes: 1 addition & 9 deletions app/views/good_job/processes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
</div>

<div data-live-poll-region="processes">
<% if !GoodJob::Process.migrated? %>
<div class="card my-3">
<div class="card-body">
<p class="card-text">
<em>Feature unavailable because of pending database migration.</em>
</p>
</div>
</div>
<% elsif @processes.present? %>
<% if @processes.present? %>
<div class="card my-3">
<div class="table-responsive">
<table class="table card-table table-bordered table-hover table-sm mb-0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ class CreateGoodJobs < ActiveRecord::Migration<%= migration_version %>
t.text :concurrency_key
t.text :cron_key
t.uuid :retried_good_job_id
t.timestamp :cron_at
end

create_table :good_job_processes, id: :uuid do |t|
t.timestamps
t.jsonb :state
end

add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)", name: "index_good_jobs_on_scheduled_at"
add_index :good_jobs, [:queue_name, :scheduled_at], where: "(finished_at IS NULL)", name: :index_good_jobs_on_queue_name_and_scheduled_at
add_index :good_jobs, [:active_job_id, :created_at], name: :index_good_jobs_on_active_job_id_and_created_at
add_index :good_jobs, :concurrency_key, where: "(finished_at IS NULL)", name: :index_good_jobs_on_concurrency_key_when_unfinished
add_index :good_jobs, [:cron_key, :created_at], name: :index_good_jobs_on_cron_key_and_created_at
add_index :good_jobs, [:cron_key, :cron_at], name: :index_good_jobs_on_cron_key_and_cron_at, unique: true
add_index :good_jobs, [:active_job_id], name: :index_good_jobs_on_active_job_id
add_index :good_jobs, [:finished_at], where: "retried_good_job_id IS NULL AND finished_at IS NOT NULL", name: :index_good_jobs_jobs_on_finished_at
end
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions lib/good_job/notifier/process_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ module ProcessRegistration
# Registers the current process.
def register_process
GoodJob::Process.with_connection(connection) do
next unless Process.migrated?

GoodJob::Process.cleanup
@process = GoodJob::Process.register
end
Expand All @@ -24,8 +22,6 @@ def register_process
# Deregisters the current process.
def deregister_process
GoodJob::Process.with_connection(connection) do
next unless Process.migrated?

@process&.deregister
end
end
Expand Down
9 changes: 1 addition & 8 deletions lib/models/good_job/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ def self.enqueue(active_job, scheduled_at: nil, create_with_advisory_lock: false

if CurrentThread.cron_key
execution_args[:cron_key] = CurrentThread.cron_key

@cron_at_index = column_names.include?('cron_at') && connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at) unless instance_variable_defined?(:@cron_at_index)

if @cron_at_index
execution_args[:cron_at] = CurrentThread.cron_at
else
migration_pending_warning!
end
execution_args[:cron_at] = CurrentThread.cron_at
elsif CurrentThread.active_job_id && CurrentThread.active_job_id == active_job.job_id
execution_args[:cron_key] = CurrentThread.execution.cron_key
end
Expand Down
9 changes: 0 additions & 9 deletions lib/models/good_job/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ class Process < BaseRecord
# @return [ActiveRecord::Relation]
scope :inactive, -> { advisory_unlocked }

# Whether the +good_job_processes+ table exsists.
# @return [Boolean]
def self.migrated?
return true if connection.table_exists?(table_name)

migration_pending_warning!
false
end

# UUID that is unique to the current process and changes when forked.
# @return [String]
def self.current_id
Expand Down

0 comments on commit 253a084

Please sign in to comment.