Class: RobotLab::RailsIntegration::Job

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/robot_lab/rails_integration/job.rb

Overview

Base class for RobotLab background jobs.

Examples:

Minimal subclass using the robot_class DSL

class SupportRobotJob < RobotLab::Job
  queue_as :default
  robot_class SupportRobot
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.robot_class(klass = nil) ⇒ Object



14
15
16
# File 'lib/robot_lab/rails_integration/job.rb', line 14

def self.robot_class(klass = nil)
  klass ? @robot_class = klass : @robot_class
end

Instance Method Details

#perform(message:, robot_class: nil, thread_id: nil, **context) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/robot_lab/rails_integration/job.rb', line 21

def perform(message:, robot_class: nil, thread_id: nil, **context)
  klass  = resolve_robot_class(robot_class)
  thread = setup_thread(thread_id, message)
  robot  = build_robot(klass, thread_id)
  result = robot.run(message, **context)

  if thread
    persist_result(thread, result)
    broadcast_completion(thread_id)
  end

  result
rescue StandardError => e
  broadcast_error(thread_id, e) if thread_id
  raise
end