Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PGHero to the demo app #1294

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: Run linter
run: bin/lint --nofix

development_environment:
name: Development Environment
development_demo:
name: Tests for Development and Demo
runs-on: ubuntu-latest
timeout-minutes: 10
env:
Expand All @@ -39,6 +39,7 @@ jobs:
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
DISABLE_SPRING: 1
TEST_DEMO: 1
services:
postgres:
image: postgres:15
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ gem 'nokogiri'
gem 'pg', platforms: [:mri, :mingw, :x64_mingw]
gem 'rack', '~> 2.2'
gem 'rails'
gem "sprockets-rails"
# PGHero for the demo app
gem 'pghero'

platforms :ruby do
gem "bootsnap"
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.4)
pghero (3.4.1)
activerecord (>= 6)
prettier_print (1.2.1)
prism (0.24.0)
protocol-hpack (1.4.2)
Expand Down Expand Up @@ -452,6 +454,13 @@ GEM
thor (>= 0.19.2)
spoon (0.0.6)
ffi
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
stackprof (0.2.25)
stringio (3.1.0)
syntax_tree (6.2.0)
Expand Down Expand Up @@ -528,6 +537,7 @@ DEPENDENCIES
net-smtp
nokogiri
pg
pghero
pry-byebug
pry-rails
puma
Expand All @@ -545,6 +555,7 @@ DEPENDENCIES
sorbet
sorbet-runtime
spoom
sprockets-rails
stackprof
tapioca
timecop
Expand Down
15 changes: 15 additions & 0 deletions demo/app/jobs/pg_hero_maintenance_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PgHeroMaintenanceJob < ApplicationJob
include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
key: "pg_hero_maintenance",
total_limit: 1
)

discard_on StandardError

def perform
PgHero.capture_query_stats
PgHero.clean_query_stats
end
end
5 changes: 5 additions & 0 deletions demo/config/initializers/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
complex_schedule: {
cron: -> (last_ran) { last_ran ? last_ran + 17.hours : Time.now},
class: "OtherJob",
},
pg_hero_maintenance: {
cron: "*/10 * * * *", # Every 10 minutes
class: "PgHeroMaintenanceJob",
description: "Runs PG Hero maintenance",
}
}
end
Expand Down
2 changes: 2 additions & 0 deletions demo/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
mount GoodJob::Engine => "/good_job"

get :create_job, to: 'application#create_job'

mount PgHero::Engine, at: "pghero"
end
17 changes: 17 additions & 0 deletions demo/db/migrate/20240321162554_create_pghero_query_stats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreatePgheroQueryStats < ActiveRecord::Migration[7.1]
def change
enable_extension "pg_stat_statements"

create_table :pghero_query_stats do |t|
t.text :database
t.text :user
t.text :query
t.integer :query_hash, limit: 8
t.float :total_time
t.integer :calls, limit: 8
t.timestamp :captured_at
end

add_index :pghero_query_stats, [:database, :captured_at]
end
end
14 changes: 13 additions & 1 deletion demo/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_01_14_221613) do
ActiveRecord::Schema.define(version: 2024_03_21_162554) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "pgcrypto"
enable_extension "plpgsql"

Expand Down Expand Up @@ -94,4 +95,15 @@
t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)"
end

create_table "pghero_query_stats", force: :cascade do |t|
t.text "database"
t.text "user"
t.text "query"
t.bigint "query_hash"
t.float "total_time"
t.bigint "calls"
t.datetime "captured_at", precision: nil
t.index ["database", "captured_at"], name: "index_pghero_query_stats_on_database_and_captured_at"
end

end
Loading
Loading