Class: Ductwork::Processes::JobWorker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, id) ⇒ JobWorker

Returns a new instance of JobWorker.



8
9
10
11
12
13
14
# File 'lib/ductwork/processes/job_worker.rb', line 8

def initialize(pipeline, id)
  @pipeline = pipeline
  @id = id
  @running_context = Ductwork::RunningContext.new
  @thread = nil
  @last_heartbeat_at = Time.current
end

Instance Attribute Details

#executionObject (readonly)

Returns the value of attribute execution.



6
7
8
# File 'lib/ductwork/processes/job_worker.rb', line 6

def execution
  @execution
end

#last_heartbeat_atObject (readonly)

Returns the value of attribute last_heartbeat_at.



6
7
8
# File 'lib/ductwork/processes/job_worker.rb', line 6

def last_heartbeat_at
  @last_heartbeat_at
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



6
7
8
# File 'lib/ductwork/processes/job_worker.rb', line 6

def pipeline
  @pipeline
end

#threadObject (readonly)

Returns the value of attribute thread.



6
7
8
# File 'lib/ductwork/processes/job_worker.rb', line 6

def thread
  @thread
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ductwork/processes/job_worker.rb', line 26

def alive?
  thread&.alive? || false
end

#join(limit) ⇒ Object



43
44
45
# File 'lib/ductwork/processes/job_worker.rb', line 43

def join(limit)
  thread&.join(limit)
end

#killObject



38
39
40
41
# File 'lib/ductwork/processes/job_worker.rb', line 38

def kill
  stop
  thread&.kill
end

#nameObject



47
48
49
# File 'lib/ductwork/processes/job_worker.rb', line 47

def name
  "ductwork.job_worker.#{pipeline}.#{id}"
end

#restartObject



21
22
23
24
# File 'lib/ductwork/processes/job_worker.rb', line 21

def restart
  cleanup_dead_thread!
  start
end

#startObject



16
17
18
19
# File 'lib/ductwork/processes/job_worker.rb', line 16

def start
  @thread = Thread.new { work_loop }
  @thread.name = name
end

#stopObject



34
35
36
# File 'lib/ductwork/processes/job_worker.rb', line 34

def stop
  running_context.shutdown!
end

#stuck?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ductwork/processes/job_worker.rb', line 30

def stuck?
  execution.nil? && last_heartbeat_too_long_ago?
end