Module: Orchestrator::Core::Mixin
- Included in:
- Device::Mixin, Logic::Mixin, Service::Mixin
- Defined in:
- lib/orchestrator/core/mixin.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
Thread safe status access.
-
#[]=(status, value) ⇒ Object
thread safe status settings.
-
#__STATS__ ⇒ Object
Outputs any statistics collected on the module.
- #current_user ⇒ Object
-
#define_setting(name, value) ⇒ ::Libuv::Q::Promise
Updates a setting that will effect the local module only.
- #logger ⇒ Object
-
#schedule ⇒ ::Orchestrator::Core::ScheduleProxy
Returns a wrapper around a shared instance of ::UV::Scheduler.
- #setting(name) ⇒ Object
-
#subscribe(status, callback = nil, &block) ⇒ Object
thread safe status subscription.
-
#systems(name) ⇒ ::Libuv::Q::Promise
Looks up a system based on its name and returns a proxy to that system via a promise.
-
#task(callback = nil, &block) ⇒ ::Libuv::Q::Promise
Performs a long running task on a thread pool in parallel.
- #thread ⇒ Object
-
#unsubscribe(sub) ⇒ Object
thread safe unsubscribe.
- #wake_device(mac, ip = '<broadcast>') ⇒ Object
Instance Method Details
#[](name) ⇒ Object
Thread safe status access
39 40 41 |
# File 'lib/orchestrator/core/mixin.rb', line 39 def [](name) @__config__.status[name.to_sym] end |
#[]=(status, value) ⇒ Object
thread safe status settings
44 45 46 47 48 49 50 51 |
# File 'lib/orchestrator/core/mixin.rb', line 44 def []=(status, value) @__config__.trak(status.to_sym, value) # Check level to speed processing if @__config__.logger.level == 0 @__config__.logger.debug "Status updated: #{status} = #{value}" end end |
#__STATS__ ⇒ Object
Outputs any statistics collected on the module
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/orchestrator/core/mixin.rb', line 105 def __STATS__ stats = {} if @__config__.respond_to? :processor stats[:queue_size] = @__config__.processor.queue.length stats[:queue_waiting] = !@__config__.processor.queue.waiting.nil? stats[:queue_pause] = @__config__.processor.queue.pause stats[:queue_state] = @__config__.processor.queue.state stats[:last_send] = @__config__.processor.last_sent_at stats[:last_receive] = @__config__.processor.last_receive_at if @__config__.processor.timeout stats[:timeout_created] = @__config__.processor.timeout.created stats[:timeout_triggered] = @__config__.processor.timeout.trigger_count stats[:timeout_scheduled] = @__config__.processor.timeout.next_scheduled end end stats[:time_now] = @__config__.thread.now stats[:schedules] = schedule.schedules.to_a logger.debug JSON.generate(stats) end |
#current_user ⇒ Object
100 101 102 |
# File 'lib/orchestrator/core/mixin.rb', line 100 def current_user @__config__.current_user end |
#define_setting(name, value) ⇒ ::Libuv::Q::Promise
Updates a setting that will effect the local module only
90 91 92 |
# File 'lib/orchestrator/core/mixin.rb', line 90 def define_setting(name, value) @__config__.define_setting(name.to_sym, value) end |
#logger ⇒ Object
73 74 75 |
# File 'lib/orchestrator/core/mixin.rb', line 73 def logger @__config__.logger end |
#schedule ⇒ ::Orchestrator::Core::ScheduleProxy
Returns a wrapper around a shared instance of ::UV::Scheduler
10 11 12 13 |
# File 'lib/orchestrator/core/mixin.rb', line 10 def schedule raise SCHEDULE_ACCESS_DENIED unless @__config__.thread.reactor_thread? @__config__.get_scheduler end |
#setting(name) ⇒ Object
77 78 79 |
# File 'lib/orchestrator/core/mixin.rb', line 77 def setting(name) @__config__.setting(name.to_sym) end |
#subscribe(status, callback = nil, &block) ⇒ Object
thread safe status subscription
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/orchestrator/core/mixin.rb', line 54 def subscribe(status, callback = nil, &block) callback ||= block raise 'callback required' unless callback.respond_to? :call thread = @__config__.thread defer = thread.defer thread.schedule do defer.resolve(@__config__.subscribe(status, callback)) end defer.promise end |
#systems(name) ⇒ ::Libuv::Q::Promise
Looks up a system based on its name and returns a proxy to that system via a promise
19 20 21 22 23 |
# File 'lib/orchestrator/core/mixin.rb', line 19 def systems(name) task do @__config__.get_system(name) end end |
#task(callback = nil, &block) ⇒ ::Libuv::Q::Promise
Performs a long running task on a thread pool in parallel.
29 30 31 32 33 34 35 36 |
# File 'lib/orchestrator/core/mixin.rb', line 29 def task(callback = nil, &block) thread = @__config__.thread defer = thread.defer thread.schedule do defer.resolve(thread.work(callback, &block)) end defer.promise end |
#thread ⇒ Object
81 82 83 |
# File 'lib/orchestrator/core/mixin.rb', line 81 def thread @__config__.thread end |
#unsubscribe(sub) ⇒ Object
thread safe unsubscribe
67 68 69 70 71 |
# File 'lib/orchestrator/core/mixin.rb', line 67 def unsubscribe(sub) @__config__.thread.schedule do @__config__.unsubscribe(sub) end end |
#wake_device(mac, ip = '<broadcast>') ⇒ Object
94 95 96 97 98 |
# File 'lib/orchestrator/core/mixin.rb', line 94 def wake_device(mac, ip = '<broadcast>') @__config__.thread.schedule do @__config__.thread.wake_device(mac, ip) end end |