Class: Fasten::Worker

Inherits:
Object
  • Object
show all
Includes:
Support::Logger, Support::State
Defined in:
lib/fasten/worker.rb

Instance Attribute Summary collapse

Attributes included from Support::State

#dif, #error, #fin, #ini, #state

Attributes included from Support::Logger

#log_file, #logger

Instance Method Summary collapse

Methods included from Support::State

#deps, #deps_str, #deps_str_runner, #deps_str_task, #idle?, #last_avg, #last_err, #last_stat, #paused?, #pausing?, #quitting?, #running?

Methods included from Support::Logger

#close_logger, #initialize_logger, #log_fin, #log_ini

Constructor Details

#initialize(runner:, name: nil, use_threads: nil) ⇒ Worker

Returns a new instance of Worker.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fasten/worker.rb', line 23

def initialize(runner:, name: nil, use_threads: nil)
  if use_threads
    extend Fasten::Support::ThreadWorker
  else
    extend Fasten::Support::ForkWorker
  end

  self.runner = runner
  self.name = name
  self.spinner = 0

  initialize_logger(log_file: runner.log_file) if runner
end

Instance Attribute Details

#child_readObject

Returns the value of attribute child_read.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def child_read
  @child_read
end

#child_writeObject

Returns the value of attribute child_write.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def child_write
  @child_write
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def name
  @name
end

#parent_readObject

Returns the value of attribute parent_read.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def parent_read
  @parent_read
end

#parent_writeObject

Returns the value of attribute parent_write.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def parent_write
  @parent_write
end

#runnerObject

Returns the value of attribute runner.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def runner
  @runner
end

#running_taskObject

Returns the value of attribute running_task.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def running_task
  @running_task
end

#spinnerObject

Returns the value of attribute spinner.



21
22
23
# File 'lib/fasten/worker.rb', line 21

def spinner
  @spinner
end

Instance Method Details

#kindObject



47
48
49
# File 'lib/fasten/worker.rb', line 47

def kind
  'worker'
end

#perform(task) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/fasten/worker.rb', line 37

def perform(task)
  if task.ruby
    perform_ruby(task)
  elsif task.shell
    perform_shell(task)
  elsif task.block
    perform_block(task, task.block)
  end
end

#to_sObject



51
52
53
# File 'lib/fasten/worker.rb', line 51

def to_s
  name
end