Module: Kryten::Weaver

Included in:
ThreadedTask
Defined in:
lib/kryten/weaver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workerObject (readonly)

Returns the value of attribute worker.



2
3
4
# File 'lib/kryten/weaver.rb', line 2

def worker
  @worker
end

#workersObject

Returns the value of attribute workers.



3
4
5
# File 'lib/kryten/weaver.rb', line 3

def workers
  @workers
end

Instance Method Details

#log_pathObject



38
39
40
# File 'lib/kryten/weaver.rb', line 38

def log_path
  "/tmp/#{name}.log"
end

#setupObject



5
6
7
8
9
10
# File 'lib/kryten/weaver.rb', line 5

def setup
  if workers
    log 'starting workers'
    workers.each(&:start_work)
  end
end

#shutdownObject



22
23
24
# File 'lib/kryten/weaver.rb', line 22

def shutdown
  workers.each(&:stop_running) if workers
end

#start_workObject



12
13
14
15
16
17
18
19
20
# File 'lib/kryten/weaver.rb', line 12

def start_work
  if worker && worker.alive?
    log 'worker already running'
    return false
  end

  @started = true
  @worker = Thread.new { start }
end

#stop_workObject



26
27
28
# File 'lib/kryten/weaver.rb', line 26

def stop_work
  stop_running
end