Class: RSMP::Node

Inherits:
Object
  • Object
show all
Includes:
Inspect, Logging, Task
Defined in:
lib/rsmp/node/node.rb

Direct Known Subclasses

Site, Supervisor

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Task

#initialize_task, #restart, #run, #start, #stop, #stop_task, #task_status, #wait, #wait_for_condition

Methods included from Inspect

#inspect, #inspector

Methods included from Logging

#initialize_logging, #log

Constructor Details

#initialize(options = {}) ⇒ Node

Returns a new instance of Node.



11
12
13
14
15
16
17
18
19
# File 'lib/rsmp/node/node.rb', line 11

def initialize(options = {})
  initialize_logging options
  initialize_task
  @deferred = []
  @clock = Clock.new
  @error_queue = Async::Queue.new
  @ignore_errors = []
  @collect = options[:collect]
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def archive
  @archive
end

#clockObject (readonly)

Returns the value of attribute clock.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def clock
  @clock
end

#collectorObject (readonly)

Returns the value of attribute collector.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def collector
  @collector
end

#deferredObject (readonly)

Returns the value of attribute deferred.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def deferred
  @deferred
end

#error_queueObject (readonly)

Returns the value of attribute error_queue.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def error_queue
  @error_queue
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def logger
  @logger
end

#taskObject (readonly)

Returns the value of attribute task.



9
10
11
# File 'lib/rsmp/node/node.rb', line 9

def task
  @task
end

Instance Method Details

#authorObject



76
77
78
# File 'lib/rsmp/node/node.rb', line 76

def author
  site_id
end

#check_required_settings(settings, required) ⇒ Object

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
# File 'lib/rsmp/node/node.rb', line 68

def check_required_settings(settings, required)
  raise ArgumentError, 'Settings is empty' unless settings

  required.each do |setting|
    raise ArgumentError, "Missing setting: #{setting}" unless settings.include? setting.to_s
  end
end

#clear_deferredObject



64
65
66
# File 'lib/rsmp/node/node.rb', line 64

def clear_deferred
  @deferred.clear
end

#defer(key, item = nil) ⇒ Object



50
51
52
# File 'lib/rsmp/node/node.rb', line 50

def defer(key, item = nil)
  @deferred << [key, item]
end

#distribute_error(error, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/rsmp/node/node.rb', line 40

def distribute_error(error, options = {})
  return if @ignore_errors.find { |klass| error.is_a? klass }

  if options[:level] == :internal
    log ["#{error} in task: #{Async::Task.current}", error.backtrace].flatten.join("\n"),
        level: :error
  end
  @error_queue.enqueue error
end

#do_deferred(key, item = nil) ⇒ Object



62
# File 'lib/rsmp/node/node.rb', line 62

def do_deferred(key, item = nil); end

#ignore_errors(classes) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rsmp/node/node.rb', line 32

def ignore_errors(classes)
  was = @ignore_errors
  @ignore_errors = [classes].flatten
  yield
ensure
  @ignore_errors = was
end

#nowObject



21
22
23
# File 'lib/rsmp/node/node.rb', line 21

def now
  clock.now
end

#process_deferredObject



54
55
56
57
58
59
60
# File 'lib/rsmp/node/node.rb', line 54

def process_deferred
  cloned = @deferred.clone # clone in case do_deferred restarts the current task
  @deferred.clear
  cloned.each do |pair|
    do_deferred pair.first, pair.last
  end
end

#stop_subtasksObject

stop proxies, then call super



26
27
28
29
30
# File 'lib/rsmp/node/node.rb', line 26

def stop_subtasks
  @proxies.each(&:stop)
  @proxies.clear
  super
end