Class: Kuroko2::Command::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/autoload/kuroko2/command/shell.rb

Constant Summary collapse

MAX_OUTPUT_LENGTH =
60_000
MAX_READ_LENGTH =
1024

Instance Method Summary collapse

Constructor Details

#initialize(hostname:, worker_id: 0, worker:, queue: Execution::DEFAULT_QUEUE) ⇒ Shell

Returns a new instance of Shell.



8
9
10
11
12
13
# File 'lib/autoload/kuroko2/command/shell.rb', line 8

def initialize(hostname:, worker_id: 0, worker:, queue: Execution::DEFAULT_QUEUE)
  @hostname  = hostname
  @worker_id = worker_id
  @worker    = worker
  @queue     = queue
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/autoload/kuroko2/command/shell.rb', line 15

def execute
  @worker.reload
  return nil if @worker.suspended?
  unless @worker.execution_id?
    if (execution = Execution.poll(@queue))
      do_execute(execution)
      execution
    end
  end
rescue RuntimeError => e
  Kuroko2.logger.error("[#{@hostname}-#{@worker_id}] #{e.message}\n" +
    e.backtrace.map { |trace| "[#{@hostname}-#{@worker_id}]    #{trace}" }.join("\n"))

  nil
end