-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track processes in the database and on the Dashboard
- Loading branch information
1 parent
b3fe7f8
commit a90be5e
Showing
20 changed files
with
387 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
module GoodJob | ||
class ProcessesController < GoodJob::BaseController | ||
def index | ||
@processes = GoodJob::Process.active.order(created_at: :desc) if GoodJob::Process.migrated? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<% 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? %> | ||
<div class="card my-3"> | ||
<div class="table-responsive"> | ||
<table class="table card-table table-bordered table-hover table-sm mb-0"> | ||
<thead> | ||
<tr> | ||
<th>Process UUID</th> | ||
<th>Created At</th></th> | ||
<th>State</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @processes.each do |process| %> | ||
<tr class="<%= dom_class(process) %>" id="<%= dom_id(process) %>"> | ||
<td><%= process.id %></td> | ||
<td><%= relative_time(process.created_at) %></td> | ||
<td><%= tag.pre JSON.pretty_generate(process.state) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<% else %> | ||
<div class="card my-3"> | ||
<div class="card-body"> | ||
<p class="card-text"> | ||
<em>No GoodJob processes found.</em> | ||
</p> | ||
</div> | ||
</div> | ||
<% 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
19 changes: 19 additions & 0 deletions
19
lib/generators/good_job/templates/update/migrations/04_create_good_job_processes.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,19 @@ | ||
# frozen_string_literal: true | ||
class CreateGoodJobProcesses < ActiveRecord::Migration<%= migration_version %> | ||
def change | ||
enable_extension 'pgcrypto' | ||
|
||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.table_exists?(:good_job_processes) | ||
end | ||
end | ||
|
||
create_table :good_job_processes, id: :uuid do |t| | ||
t.timestamps | ||
t.jsonb :state | ||
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,28 @@ | ||
# frozen_string_literal: true | ||
module GoodJob | ||
module AssignableConnection | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
cattr_accessor :_connection | ||
end | ||
|
||
class_methods do | ||
def connection=(conn) | ||
self._connection = conn | ||
end | ||
|
||
def connection | ||
_connection || super | ||
end | ||
|
||
def assign_connection(conn) | ||
original_conn = _connection | ||
self.connection = conn | ||
yield | ||
ensure | ||
self._connection = original_conn | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
module GoodJob | ||
# Base ActiveRecord class that all GoodJob models inherit from. | ||
# Parent class can be configured with +GoodJob.active_record_parent_class+. | ||
# @!parse | ||
# class BaseRecord < ActiveRecord::Base; end | ||
class BaseRecord < Object.const_get(GoodJob.active_record_parent_class) | ||
def self.migration_pending_warning! | ||
ActiveSupport::Deprecation.warn(<<~DEPRECATION) | ||
GoodJob has pending database migrations. To create the migration files, run: | ||
rails generate good_job:update | ||
To apply the migration files, run: | ||
rails db:migrate | ||
DEPRECATION | ||
nil | ||
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
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
Oops, something went wrong.