Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "bundler"
directory: "/"
schedule:
interval: "monthly"
groups:
ruby:
patterns:
- "*"
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
push:
tags: [ v* ]

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: rubygems/release-gem@v1
- name: Create GitHub release
run: |
tag_name="$(git describe --tags --abbrev=0)"
gh release create "${tag_name}" --verify-tag --generate-notes --latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
# Single source of truth: the same steps run locally via bin/ci (== rake).
- name: Test
run: bin/ci
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require spec_helper
--format documentation
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ plugins:
inherit_mode:
merge:
- Exclude

# This is a gem, not a Rails app: there's no :environment task to depend on.
Rails/RakeEnvironment:
Exclude:
- Rakefile
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.5
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ source "https://rubygems.org"

gemspec

gem "brakeman", require: false
gem "rake"
gem "rspec"
gem "rubocop-katalyst"
29 changes: 26 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
katalyst-thermite (1.0.0)
activesupport
railties
solid_queue

GEM
remote: https://rubygems.org/
Expand All @@ -24,6 +25,15 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (8.1.3)
activesupport (= 8.1.3)
globalid (>= 0.3.6)
activemodel (8.1.3)
activesupport (= 8.1.3)
activerecord (8.1.3)
activemodel (= 8.1.3)
activesupport (= 8.1.3)
timeout (>= 0.4.0)
activesupport (8.1.3)
base64
bigdecimal
Expand All @@ -40,8 +50,6 @@ GEM
ast (2.4.3)
base64 (0.3.0)
bigdecimal (4.1.2)
brakeman (8.0.5)
racc
builder (3.3.0)
concurrent-ruby (1.3.7)
connection_pool (3.0.2)
Expand All @@ -51,6 +59,13 @@ GEM
drb (2.2.3)
erb (6.0.4)
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
fugit (1.12.2)
et-orbi (~> 1.4)
raabro (~> 1.4)
globalid (1.3.0)
activesupport (>= 6.1)
i18n (1.15.2)
concurrent-ruby (~> 1.0)
io-console (0.8.2)
Expand Down Expand Up @@ -84,6 +99,7 @@ GEM
psych (5.4.0)
date
stringio
raabro (1.4.0)
racc (1.8.1)
rack (3.2.6)
rack-session (2.1.2)
Expand Down Expand Up @@ -184,8 +200,16 @@ GEM
rubocop-rspec (~> 3.5)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
solid_queue (1.4.0)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11)
railties (>= 7.1)
thor (>= 1.3.1)
stringio (3.2.0)
thor (1.5.0)
timeout (0.6.1)
tsort (0.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -203,7 +227,6 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
brakeman
katalyst-thermite!
rake
rspec
Expand Down
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "bundler/gem_tasks"

desc "Run the full CI suite (style, security, tests) via bin/ci"
task :ci do
sh "bin/ci"
end

task default: :ci
8 changes: 8 additions & 0 deletions bin/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "active_support/continuous_integration"

CI = ActiveSupport::ContinuousIntegration
require_relative "../config/ci"
6 changes: 6 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

Dir.chdir(File.expand_path("..", __dir__)) do
system("bundle check") || system("bundle install", exception: true)
end
9 changes: 9 additions & 0 deletions config/ci.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# Run using bin/ci

CI.run do
step "Setup", "bin/setup"
step "Style: Ruby", "bundle exec rubocop"
step "Tests: RSpec", "bundle exec rspec"
end
1 change: 1 addition & 0 deletions katalyst-thermite.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "activesupport"
spec.add_dependency "railties"
spec.add_dependency "solid_queue"
end
18 changes: 18 additions & 0 deletions lib/generators/thermite/install/solid_queue/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Description:
Installs Solid Queue using a single, shared database (Katalyst's preferred setup).

Unlike `solid_queue:install`, this does not provision a separate queue
database. The solid_queue tables are added to the primary database via a
normal migration in db/migrate, and `config.active_job.queue_adapter` is set
to :solid_queue without a `connects_to` configuration.

Requires the solid_queue gem to be present in the host application.

Example:
bin/rails thermite:install:solid_queue

This will:
Create config/queue.yml and config/recurring.yml
Create a db/migrate migration for the solid_queue tables
Install the bin/jobs binstub
Set the Active Job queue adapter to :solid_queue (non dev/test environments)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

require "rails"
require "rails/generators"
require "rails/generators/active_record/migration"

require "active_record"

# For a single-database install, solid queue's documented setup is to copy the contents
# of db/queue_schema.rb into a normal migration, delete db/queue_schema.rb,
# remove config.solid_queue.connects_to, then run db:migrate.
module Thermite
module Install
class SolidQueueGenerator < Rails::Generators::Base
include ActiveRecord::Generators::Migration

# Reuse solid_queue's own templates. Resolved lazily so the class loads
# without solid_queue present; populated once #verify_solid_queue! requires it.
def self.source_root
::SolidQueue::InstallGenerator.source_root if defined?(::SolidQueue::InstallGenerator)
end

# Search our own templates (the migration) first, then solid_queue's
# (queue.yml, recurring.yml, bin/jobs).
def self.source_paths
[File.expand_path("templates", __dir__), source_root].compact
end

# Our source_root points into solid_queue, so the inherited USAGE lookup
# would resolve to solid_queue's USAGE. Point it at ours instead.
def self.usage_path
File.expand_path("USAGE", __dir__)
end

# Fail early with a helpful message when solid_queue isn't available.
def verify_solid_queue!
require "solid_queue/version"
require "generators/solid_queue/install/install_generator"
rescue LoadError
raise Thor::Error, <<~MSG.strip
thermite:install:solid_queue requires the solid_queue gem, which is not available.
Add it to your Gemfile and run `bundle install`:

gem "solid_queue"
MSG
end

# Based on SolidQueue::InstallGenerator#copy_files but writing schema to a migration instead
# @see https://github.com/rails/solid_queue#single-database-configuration
def copy_files
template "config/queue.yml"
template "config/recurring.yml"
migration_template "add_solid_queue.rb", "db/migrate/add_solid_queue.rb", skip: true
template "bin/jobs"
chmod "bin/jobs", 0o755 & ~File.umask, verbose: false
end

# Based on SolidQueue::InstallGenerator#configure_adapter but without connects_to configuration
# @see https://github.com/rails/solid_queue#single-database-configuration
def configure_adapter
Pathname(destination_root).join("config/environments").glob("*.rb").each do |pathname|
next if %w[development.rb test.rb].include?(pathname.basename.to_s)

gsub_file pathname, /\n\s*config\.solid_queue\.connects_to\s+=.*\n/, "\n", verbose: false
gsub_file pathname, /(# )?config\.active_job\.queue_adapter\s+=.*\n/,
"config.active_job.queue_adapter = :solid_queue\n"
end
end

private

# The application's environments, derived from config/environments/*.rb so
# we don't hard-code names like "staging" / "uat".
def application_environments
Pathname(destination_root).join("config/environments")
.glob("*.rb")
.map { |path| path.basename(".rb").to_s }
.sort
end

def solid_queue_schema_body
schema = File.read(File.join(self.class.source_root, "db/queue_schema.rb"))

schema
# Keep only the schema block body.
.sub(%r{\A.*ActiveRecord::Schema[^\n]+do\n}, "")
.sub(/\nend\n?\z/, "")
.lines
.map { |line| line == "\n" ? line : " #{line}" }
.join
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
<%= solid_queue_schema_body.chomp %>
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default: &default
dispatchers:
- polling_interval: 1
batch_size: 500
workers:
- queues: "*"
threads: 3
processes: <%%= ENV.fetch("JOB_CONCURRENCY", 1) %>
polling_interval: 0.1
<% application_environments.each do |environment| -%>

<%= environment %>:
<<: *default
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
production: &production
clear_solid_queue_finished_jobs:
command: "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)"
schedule: every hour at minute 12
<% (application_environments - %w[development test production]).each do |environment| -%>

<%= environment %>:
<<: *production
<% end -%>
2 changes: 1 addition & 1 deletion lib/katalyst-thermite.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "katalyst/thermite"
require "thermite"
9 changes: 0 additions & 9 deletions lib/katalyst/thermite.rb

This file was deleted.

17 changes: 17 additions & 0 deletions lib/thermite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require "thermite/engine"

require "active_support"

require "zeitwerk"

loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
loader.ignore("#{__dir__}/generators")
loader.ignore("#{__dir__}/katalyst-thermite.rb")
loader.ignore("#{__dir__}/thermite/tasks.rb")
loader.setup

module Thermite
extend self
end
11 changes: 11 additions & 0 deletions lib/thermite/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Thermite
class Engine < ::Rails::Engine
isolate_namespace Thermite

rake_tasks do
load "thermite/tasks.rb"
end
end
end
Loading