Add sucker_punch as job worker

pull/300/head
Rick Carlino 2016-11-28 13:45:42 -06:00
parent cb2883cc15
commit 94251cb5b5
7 changed files with 47 additions and 22 deletions

View File

@ -11,6 +11,7 @@ gem "ice_cube"
gem "rack-cors", require: "rack/cors"
gem "mysql"
gem "database_cleaner"
gem "sucker_punch"
group :development, :test do
gem "sqlite3"

View File

@ -178,6 +178,8 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.12)
sucker_punch (2.0.2)
concurrent-ruby (~> 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
@ -212,6 +214,7 @@ DEPENDENCIES
simplecov
smarf_doc!
sqlite3
sucker_punch
RUBY VERSION
ruby 2.3.2p217

View File

@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end

View File

@ -0,0 +1,8 @@
class SendWelcomeEmailJob < ApplicationJob
queue_as :default
def perform(user)
# This is a stub until we come back and add real background workers.
puts "Welcome, #{user.email}!"
end
end

View File

@ -21,10 +21,11 @@ module Users
password_confirmation: password_confirmation,
name: name)
device = Devices::Create.run!(user: resp[:user])
resp.merge!(Auth::CreateToken.run!(email: email,
password: password))
device = Devices::Create.run!(user: resp[:user])
auth_stuff = Auth::CreateToken.run!(email: email, password: password)
resp.merge!(auth_stuff)
SendWelcomeEmailJob.perform_later(resp[:user])
resp
end
end
end

View File

@ -0,0 +1,22 @@
class CreateDelayedJobs < ActiveRecord::Migration
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

@ -1,4 +1,3 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@ -13,14 +12,6 @@
ActiveRecord::Schema.define(version: 20161028175744) do
create_table "ar_internal_metadata", primary_key: "key", force: :cascade do |t|
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "ar_internal_metadata", ["key"], name: "sqlite_autoindex_ar_internal_metadata_1", unique: true
create_table "devices", force: :cascade do |t|
t.integer "planting_area_id"
t.string "name"
@ -34,10 +25,9 @@ ActiveRecord::Schema.define(version: 20161028175744) do
t.string "label"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["device_id"], name: "index_peripherals_on_device_id"
end
add_index "peripherals", ["device_id"], name: "index_peripherals_on_device_id"
create_table "planting_areas", force: :cascade do |t|
t.integer "width"
t.integer "length"
@ -82,12 +72,11 @@ ActiveRecord::Schema.define(version: 20161028175744) do
t.string "dependency_type"
t.integer "dependency_id"
t.integer "sequence_id"
t.index ["dependency_id"], name: "index_sequence_dependencies_on_dependency_id"
t.index ["dependency_type"], name: "index_sequence_dependencies_on_dependency_type"
t.index ["sequence_id"], name: "index_sequence_dependencies_on_sequence_id"
end
add_index "sequence_dependencies", ["dependency_id"], name: "index_sequence_dependencies_on_dependency_id"
add_index "sequence_dependencies", ["dependency_type"], name: "index_sequence_dependencies_on_dependency_type"
add_index "sequence_dependencies", ["sequence_id"], name: "index_sequence_dependencies_on_sequence_id"
create_table "sequences", force: :cascade do |t|
t.integer "device_id"
t.string "name"
@ -112,9 +101,8 @@ ActiveRecord::Schema.define(version: 20161028175744) do
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end