1
0
mirror of https://github.com/danbee/my-images synced 2025-03-04 08:49:05 +00:00

Use delayed_job for job queue

This commit is contained in:
Daniel Barber 2018-08-26 12:42:01 -04:00
parent 71c124e688
commit c31a215b14
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
8 changed files with 69 additions and 1 deletions

View File

@ -6,6 +6,7 @@ gem "dotenv-rails", groups: %i[development test]
gem "rails", "5.2.1"
gem "delayed_job_active_record"
gem "dragonfly"
gem "http"
gem "jquery-rails"

View File

@ -65,6 +65,11 @@ GEM
safe_yaml (~> 1.0.0)
crass (1.0.4)
debug_inspector (0.0.3)
delayed_job (4.1.5)
activesupport (>= 3.0, < 5.3)
delayed_job_active_record (4.1.3)
activerecord (>= 3.0, < 5.3)
delayed_job (>= 3.0, < 5)
diff-lcs (1.3)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
@ -244,6 +249,7 @@ DEPENDENCIES
better_errors
binding_of_caller
capybara
delayed_job_active_record
dotenv-rails
dragonfly
http

2
Procfile Normal file
View File

@ -0,0 +1,2 @@
web: bundle exec puma -C config/puma.rb
worker: bundle exec rake jobs:work

5
bin/delayed_job Executable file
View File

@ -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

View File

@ -26,5 +26,7 @@ module MyImages
# ]
# config.i18n.default_locale = :de
config.autoload_paths += %W(#{config.root}/lib)
config.active_job.queue_adapter = :delayed_job
end
end

15
config/puma.rb Normal file
View File

@ -0,0 +1,15 @@
workers Integer(ENV["WEB_CONCURRENCY"] || 2)
threads_count = Integer(ENV["RAILS_MAX_THREADS"] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV["PORT"] || 3000
environment ENV["RACK_ENV"] || "development"
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end

View File

@ -0,0 +1,22 @@
class CreateDelayedJobs < ActiveRecord::Migration[5.2]
def self.up
create_table :delayed_jobs, force: true 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

View File

@ -10,11 +10,26 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_08_25_150330) do
ActiveRecord::Schema.define(version: 2018_08_26_163510) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
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 "images", force: :cascade do |t|
t.integer "user_id"
t.string "image_uid"