【发布时间】:2017-12-15 10:25:03
【问题描述】:
我有一些自定义代码可以调用一些后端系统并远程更新数据库。我有一个执行任务的 ActiveJob:
## Runs join code
class DataJoin < ApplicationJob
queue_as :default
def perform
join = Joiner.new
join.run
NotifMailer.sample_email.deliver_now
end
end
我想从控制器/视图手动启动 ActiveJob:
class AdminController < ApplicationController
before_action :verify_is_admin
private def verify_is_admin
(current_user.nil?) ? redirect_to(root_path) : (redirect_to(root_path) unless current_user.admin?)
end
def index
@username = current_user.name
@intro = "Welcome to the admin console"
end
def join
## Code to start ActiveJob DataJoin??
end
end
如何从控制器启动 ActiveJob?
【问题讨论】:
标签: ruby-on-rails rails-activejob