I have some custom code that calls some backend systems and updates the database remotely. I have an ActiveJob that performs the task:
## Runs join code
class DataJoin < ApplicationJob
join = Joiner.new
I want to kick off an ActiveJob manually from a controller/view:
class AdminController < ApplicationController
private def verify_is_admin
(current_user.nil?) ? redirect_to(root_path) : (redirect_to(root_path) unless current_user.admin?)
@username = current_user.name
@intro = "Welcome to the admin console"
## Code to start ActiveJob DataJoin??
How can I kick off an ActiveJob from a controller?
Rails ActiveJob Start From Controller
nr: #1 dodano: 2017-07-11 13:07
perform_later enqueues the job in the specified queue. If the perform method of your active job accepts some arguments, you can even pass them in perform_later, and those will be available at the time of execution.
DataJoin.perform_later(1, 2, 3)
def perform(a1, a2, a3)
# a1 will be 1
# a2 will be 2
# a3 will be 3