diff --git a/Gemfile b/Gemfile index ab6d55e..4ab74d4 100644 --- a/Gemfile +++ b/Gemfile @@ -2,85 +2,37 @@ 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 "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" - -# 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 "shadcn-ui", "~> 0.0.12" +gem "sprockets-rails" 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" +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" end group :test do - # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" gem "selenium-webdriver" end - -gem "shadcn-ui", "~> 0.0.12" - -gem "devise", "~> 4.9" - -gem "administrate", "~> 0.20.1" - - diff --git a/Gemfile.lock b/Gemfile.lock index 5a7bc13..504bdcd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,10 +111,16 @@ 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) 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) @@ -357,7 +363,9 @@ DEPENDENCIES bundler-audit capybara cssbundling-rails + daemons debug + delayed_job_active_record devise (~> 4.9) jbuilder jsbundling-rails 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/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/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. # 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