Class: CommandProposal::CommandRunnerJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/command_proposal/command_runner_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(iteration_id, runner_key = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/command_proposal/command_runner_job.rb', line 5

def perform(iteration_id, runner_key=nil)
  iteration = ::CommandProposal::Iteration.find(iteration_id)
  runner = ::CommandProposal.sessions[runner_key] if runner_key.present?

  if runner_key.present? && runner.blank?
    if iteration.task.console? && iteration.task.iterations.count > 2 # 1 for init, and the 1 for current running code
      return ::CommandProposal::Services::Runner.new.quick_fail(
        iteration,
        "Session has expired. Please start a new session."
      )
    else
      runner = ::CommandProposal::Services::Runner.new
    end

    ::CommandProposal.sessions[runner_key] = runner if runner_key.present?
  else
    runner ||= ::CommandProposal::Services::Runner.new
  end

  runner.execute(iteration)
end