Class: Ductwork::Processes::JobWorkerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ductwork/processes/job_worker_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(*pipelines) ⇒ JobWorkerRunner

Returns a new instance of JobWorkerRunner.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ductwork/processes/job_worker_runner.rb', line 6

def initialize(*pipelines)
  @pipelines = pipelines
  @running_context = Ductwork::RunningContext.new
  @job_workers = []

  Signal.trap(:INT) { running_context.shutdown! }
  Signal.trap(:TERM) { running_context.shutdown! }
  Signal.trap(:TTIN) do
    Thread.list.each do |thread|
      puts thread.name
      if thread.backtrace
        puts thread.backtrace.join("\n")
      else
        puts "No backtrace to dump"
      end
      puts
    end
  end
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ductwork/processes/job_worker_runner.rb', line 26

def run
  adopt_or_create_process!
  start_job_workers

  Ductwork.logger.debug(
    msg: "Entering main work loop",
    role: :job_worker_runner,
    pipelines: pipelines
  )

  while running?
    # TODO: Increase or make configurable
    sleep(5)
    check_workers_health
    report_heartbeat!
  end

  shutdown!
end