Explorar el Código

Begin work on asynchronous jobs

Maarten van den Berg %!s(int64=7) %!d(string=hace) años
padre
commit
551451eb79
Se han modificado 6 ficheros con 59 adiciones y 1 borrados
  1. 5 0
      Gemfile
  2. 9 0
      Gemfile.lock
  3. 5 0
      bin/delayed_job
  4. 2 0
      config/application.rb
  5. 22 0
      db/migrate/20170916212858_create_delayed_jobs.rb
  6. 16 1
      db/schema.rb

+ 5 - 0
Gemfile

@@ -59,6 +59,11 @@ gem 'mailgun_rails'
59 59
 gem 'will_paginate', '~> 3.1.0'
60 60
 gem 'bootstrap-will_paginate'
61 61
 
62
+# Delayed jobs
63
+gem 'delayed_job'
64
+gem 'delayed_job_active_record'
65
+gem 'daemons'
66
+
62 67
 group :development, :test do
63 68
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
64 69
   gem 'byebug', platform: :mri

+ 9 - 0
Gemfile.lock

@@ -63,6 +63,12 @@ GEM
63 63
       execjs
64 64
     coffee-script-source (1.12.2)
65 65
     concurrent-ruby (1.0.5)
66
+    daemons (1.2.4)
67
+    delayed_job (4.1.3)
68
+      activesupport (>= 3.0, < 5.2)
69
+    delayed_job_active_record (4.1.2)
70
+      activerecord (>= 3.0, < 5.2)
71
+      delayed_job (>= 3.0, < 5)
66 72
     domain_name (0.5.20170404)
67 73
       unf (>= 0.0.5, < 1.0.0)
68 74
     erubis (2.7.0)
@@ -208,6 +214,9 @@ DEPENDENCIES
208 214
   byebug
209 215
   clipboard-rails
210 216
   coffee-rails (~> 4.2)
217
+  daemons
218
+  delayed_job
219
+  delayed_job_active_record
211 220
   faker
212 221
   font-awesome-sass
213 222
   haml

+ 5 - 0
bin/delayed_job

@@ -0,0 +1,5 @@
1
+#!/usr/bin/env ruby
2
+
3
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
4
+require 'delayed/command'
5
+Delayed::Command.new(ARGV).daemonize

+ 2 - 0
config/application.rb

@@ -17,5 +17,7 @@ module Aardbei
17 17
 
18 18
     config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
19 19
     config.i18n.default_locale = :nl
20
+
21
+    config.active_job.queue_adapter = :delayed_job
20 22
   end
21 23
 end

+ 22 - 0
db/migrate/20170916212858_create_delayed_jobs.rb

@@ -0,0 +1,22 @@
1
+class CreateDelayedJobs < ActiveRecord::Migration[5.0]
2
+  def self.up
3
+    create_table :delayed_jobs, force: true do |table|
4
+      table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
5
+      table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
6
+      table.text :handler,                 null: false # YAML-encoded string of the object that will do work
7
+      table.text :last_error                           # reason for last failure (See Note below)
8
+      table.datetime :run_at                           # When to run. Could be Time.zone.now for immediately, or sometime in the future.
9
+      table.datetime :locked_at                        # Set when a client is working on this object
10
+      table.datetime :failed_at                        # Set when all retries have failed (actually, by default, the record is deleted instead)
11
+      table.string :locked_by                          # Who is working on this object (if locked)
12
+      table.string :queue                              # The name of the queue this job is in
13
+      table.timestamps null: true
14
+    end
15
+
16
+    add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
17
+  end
18
+
19
+  def self.down
20
+    drop_table :delayed_jobs
21
+  end
22
+end

+ 16 - 1
db/schema.rb

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 20170815155155) do
13
+ActiveRecord::Schema.define(version: 20170916212858) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "name"
@@ -25,6 +25,21 @@ ActiveRecord::Schema.define(version: 20170815155155) do
25 25
     t.index ["group_id"], name: "index_activities_on_group_id"
26 26
   end
27 27
 
28
+  create_table "delayed_jobs", force: :cascade do |t|
29
+    t.integer  "priority",   default: 0, null: false
30
+    t.integer  "attempts",   default: 0, null: false
31
+    t.text     "handler",                null: false
32
+    t.text     "last_error"
33
+    t.datetime "run_at"
34
+    t.datetime "locked_at"
35
+    t.datetime "failed_at"
36
+    t.string   "locked_by"
37
+    t.string   "queue"
38
+    t.datetime "created_at"
39
+    t.datetime "updated_at"
40
+    t.index ["priority", "run_at"], name: "delayed_jobs_priority"
41
+  end
42
+
28 43
   create_table "groups", force: :cascade do |t|
29 44
     t.string   "name"
30 45
     t.datetime "created_at", null: false