From 7d712df3efbfad515ca43cb69eb3e992d11335e5 Mon Sep 17 00:00:00 2001 From: America Calleros Date: Sat, 1 Jun 2024 10:31:09 -0400 Subject: [PATCH 1/4] Alphabetize gems in Gemfile --- Gemfile | 102 +++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 76 deletions(-) diff --git a/Gemfile b/Gemfile index ab6d55e..76d55d6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,86 +1,36 @@ -source "https://rubygems.org" - -ruby "3.2.3" - -# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.1.3", ">= 7.1.3.2" - -# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] -gem "sprockets-rails" - -# Use postgresql as the database for Active Record -gem "pg", "~> 1.1" - -# Use the Puma web server [https://github.com/puma/puma] -gem "puma", ">= 5.0" - -# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails] -gem "jsbundling-rails" - -# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem "turbo-rails" - -# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem "stimulus-rails" - -# Bundle and process CSS [https://github.com/rails/cssbundling-rails] -gem "cssbundling-rails" - -# Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem "jbuilder" - -# Use Redis adapter to run Action Cable in production -# gem "redis", ">= 4.0.1" - -# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] -# gem "kredis" - -# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" - -# Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ windows jruby ] - -# Reduces boot times through caching; required in config/boot.rb -gem "bootsnap", require: false - -# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] -# gem "image_processing", "~> 1.2" +source 'https://rubygems.org' + +ruby '3.2.3' + +gem 'rails', '~> 7.1.3', '>= 7.1.3.2' + +gem 'administrate', '~> 0.20.1' +gem 'bootsnap', require: false +gem 'cssbundling-rails' +gem 'devise', '~> 4.9' +gem 'jbuilder' +gem 'jsbundling-rails' +gem 'pg', '~> 1.1' +gem 'puma', '>= 5.0' +gem 'shadcn-ui', '~> 0.0.12' +gem 'sprockets-rails' +gem 'stimulus-rails' +gem 'turbo-rails' +gem 'tzinfo-data', platforms: %i[windows jruby] group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "debug", platforms: %i[ mri windows ] + gem 'debug', platforms: %i[mri windows] end group :development do - # Check for published security issues - gem "bundler-audit" - - gem "pry", "~> 0.14.2" - - # Add a linting command - gem "standardrb" - - # Use console on exceptions pages [https://github.com/rails/web-console] - gem "web-console" - - # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] - # gem "rack-mini-profiler" - - # Speed up commands on slow machines / big apps [https://github.com/rails/spring] - # gem "spring" + gem 'bundler-audit' + gem 'pry', '~> 0.14.2' + gem 'standardrb' + gem 'web-console' end group :test do - # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] - gem "capybara" - gem "selenium-webdriver" + gem 'capybara' + gem 'selenium-webdriver' end - -gem "shadcn-ui", "~> 0.0.12" - -gem "devise", "~> 4.9" - -gem "administrate", "~> 0.20.1" - - From 0c8ad186aaa77679b23c5d99011c77a4554fea50 Mon Sep 17 00:00:00 2001 From: America Calleros Date: Sat, 1 Jun 2024 10:33:07 -0400 Subject: [PATCH 2/4] [GEM] Install delayed_job_active_record gem --- Gemfile | 1 + Gemfile.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 76d55d6..875fa55 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'rails', '~> 7.1.3', '>= 7.1.3.2' gem 'administrate', '~> 0.20.1' gem 'bootsnap', require: false gem 'cssbundling-rails' +gem 'delayed_job_active_record' gem 'devise', '~> 4.9' gem 'jbuilder' gem 'jsbundling-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 5a7bc13..282205a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,6 +115,11 @@ GEM debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) + delayed_job (4.1.11) + activesupport (>= 3.0, < 8.0) + delayed_job_active_record (4.1.8) + activerecord (>= 3.0, < 8.0) + delayed_job (>= 3.0, < 5) devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -358,6 +363,7 @@ DEPENDENCIES capybara cssbundling-rails debug + delayed_job_active_record devise (~> 4.9) jbuilder jsbundling-rails From a0d2048d2b35986c059cf68c79d37b6177e3dfe2 Mon Sep 17 00:00:00 2001 From: America Calleros Date: Sat, 1 Jun 2024 10:38:43 -0400 Subject: [PATCH 3/4] [MIGRATION] Create delayed_jobs table --- bin/delayed_job | 5 +++++ .../20240601143331_create_delayed_jobs.rb | 22 +++++++++++++++++++ db/schema.rb | 17 +++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 bin/delayed_job create mode 100644 db/migrate/20240601143331_create_delayed_jobs.rb diff --git a/bin/delayed_job b/bin/delayed_job new file mode 100755 index 0000000..edf1959 --- /dev/null +++ b/bin/delayed_job @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) +require 'delayed/command' +Delayed::Command.new(ARGV).daemonize diff --git a/db/migrate/20240601143331_create_delayed_jobs.rb b/db/migrate/20240601143331_create_delayed_jobs.rb new file mode 100644 index 0000000..c7c81d0 --- /dev/null +++ b/db/migrate/20240601143331_create_delayed_jobs.rb @@ -0,0 +1,22 @@ +class CreateDelayedJobs < ActiveRecord::Migration[7.1] + def self.up + create_table :delayed_jobs do |table| + table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue + table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. + table.text :handler, null: false # YAML-encoded string of the object that will do work + table.text :last_error # reason for last failure (See Note below) + table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. + table.datetime :locked_at # Set when a client is working on this object + table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) + table.string :locked_by # Who is working on this object (if locked) + table.string :queue # The name of the queue this job is in + table.timestamps null: true + end + + add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" + end + + def self.down + drop_table :delayed_jobs + end +end diff --git a/db/schema.rb b/db/schema.rb index 8b3f071..8fa86e5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_31_175716) do +ActiveRecord::Schema[7.1].define(version: 2024_06_01_143331) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,6 +25,21 @@ t.index ["year_id"], name: "index_classrooms_on_year_id" end + create_table "delayed_jobs", force: :cascade do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by" + t.string "queue" + t.datetime "created_at" + t.datetime "updated_at" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" + end + create_table "orders", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "stock_id", null: false From d5d59339f562203d92b8487be86ae367a79ff6fe Mon Sep 17 00:00:00 2001 From: America Calleros Date: Sat, 1 Jun 2024 11:19:44 -0400 Subject: [PATCH 4/4] [GEM] Install daemons gem and set queue_adapter to :delayed_job --- Gemfile | 49 ++++++++++++++++++++++--------------------- Gemfile.lock | 2 ++ Procfile.dev | 1 + config/application.rb | 4 +++- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Gemfile b/Gemfile index 875fa55..4ab74d4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,37 +1,38 @@ -source 'https://rubygems.org' +source "https://rubygems.org" -ruby '3.2.3' +ruby "3.2.3" -gem 'rails', '~> 7.1.3', '>= 7.1.3.2' +gem "rails", "~> 7.1.3", ">= 7.1.3.2" -gem 'administrate', '~> 0.20.1' -gem 'bootsnap', require: false -gem 'cssbundling-rails' -gem 'delayed_job_active_record' -gem 'devise', '~> 4.9' -gem 'jbuilder' -gem 'jsbundling-rails' -gem 'pg', '~> 1.1' -gem 'puma', '>= 5.0' -gem 'shadcn-ui', '~> 0.0.12' -gem 'sprockets-rails' -gem 'stimulus-rails' -gem 'turbo-rails' -gem 'tzinfo-data', platforms: %i[windows jruby] +gem "administrate", "~> 0.20.1" +gem "bootsnap", require: false +gem "cssbundling-rails" +gem "daemons" +gem "delayed_job_active_record" +gem "devise", "~> 4.9" +gem "jbuilder" +gem "jsbundling-rails" +gem "pg", "~> 1.1" +gem "puma", ">= 5.0" +gem "shadcn-ui", "~> 0.0.12" +gem "sprockets-rails" +gem "stimulus-rails" +gem "turbo-rails" +gem "tzinfo-data", platforms: %i[windows jruby] group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem 'debug', platforms: %i[mri windows] + gem "debug", platforms: %i[mri windows] end group :development do - gem 'bundler-audit' - gem 'pry', '~> 0.14.2' - gem 'standardrb' - gem 'web-console' + gem "bundler-audit" + gem "pry", "~> 0.14.2" + gem "standardrb" + gem "web-console" end group :test do - gem 'capybara' - gem 'selenium-webdriver' + gem "capybara" + gem "selenium-webdriver" end diff --git a/Gemfile.lock b/Gemfile.lock index 282205a..504bdcd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,6 +111,7 @@ GEM crass (1.0.6) cssbundling-rails (1.4.0) railties (>= 6.0.0) + daemons (1.4.1) date (3.3.4) debug (1.9.2) irb (~> 1.10) @@ -362,6 +363,7 @@ DEPENDENCIES bundler-audit capybara cssbundling-rails + daemons debug delayed_job_active_record devise (~> 4.9) diff --git a/Procfile.dev b/Procfile.dev index c1cb248..f23de8d 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,4 @@ web: env RUBY_DEBUG_OPEN=true bin/rails server js: yarn build --watch css: yarn build:css --watch +job: bin/rake jobs:work diff --git a/config/application.rb b/config/application.rb index 9195821..03a96e4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,9 @@ class Application < Rails::Application # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w(assets tasks)) + config.autoload_lib(ignore: %w[assets tasks]) + + config.active_job.queue_adapter = :delayed_job # Configuration for the application, engines, and railties goes here. #