Module: Polyseerio::SDK::Method
- Defined in:
- lib/sdk/factory.rb,
lib/sdk/method/fact.rb,
lib/sdk/method/save.rb,
lib/sdk/method/check.rb,
lib/sdk/method/gauge.rb,
lib/sdk/method/index.rb,
lib/sdk/method/attach.rb,
lib/sdk/method/detach.rb,
lib/sdk/method/remove.rb,
lib/sdk/method/execute.rb,
lib/sdk/method/message.rb,
lib/sdk/method/to_json.rb,
lib/sdk/method/trigger.rb,
lib/sdk/method/add_fact.rb,
lib/sdk/method/add_gauge.rb
Overview
Instance methods.
Constant Summary collapse
- MAP =
Polyseerio::Helper.dir_proc_map(File.dirname(__FILE__), self)
Class Method Summary collapse
- .add_fact ⇒ Object
- .add_gauge ⇒ Object
- .attach ⇒ Object
- .check ⇒ Object
- .detach ⇒ Object
- .execute ⇒ Object
- .fact ⇒ Object
-
.factory(_request, _resource, methods = [], _options = {}) ⇒ Object
Generates method (instance) functions.
- .gauge ⇒ Object
- .message ⇒ Object
- .remove ⇒ Object
- .save ⇒ Object
- .to_json ⇒ Object
- .trigger ⇒ Object
Class Method Details
.add_fact ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/sdk/method/add_fact.rb', line 5 def self.add_fact proc do |instance, key, value| instance._facts ||= {} instance._facts[key] = value end end |
.add_gauge ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/sdk/method/add_gauge.rb', line 5 def self.add_gauge proc do |instance, key, value| instance._gauges ||= {} instance._gauges[key] = value end end |
.attach ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sdk/method/attach.rb', line 9 def self.attach proc do |instance| = Polyseerio::Helper.defaults( {}, delay: Constant::DEFAULT_HEARTBEAT_DELAY ) uri = Helper.instance_to_uri instance [:delay] = Polyseerio::Helper.ms_to_seconds [:delay] Concurrent::Promise.new do heartbeat_thread = Thread.new(instance, ) do |inst, opts| begin loop do payload = {} Polyseerio.log 'debug', 'Sending heartbeat.' inst.request.post("#{uri}/heartbeat", payload).execute.value sleep(opts[:delay]) end rescue => err Polyseerio.log 'error', 'Heartbeat failed.' Polyseerio.log 'error', err. end end heartbeat_thread end end end |
.check ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/check.rb', line 5 def self.check proc do || end end |
.detach ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/detach.rb', line 5 def self.detach proc do || end end |
.execute ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/execute.rb', line 5 def self.execute proc do || end end |
.fact ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/fact.rb', line 5 def self.fact proc do || end end |
.factory(_request, _resource, methods = [], _options = {}) ⇒ Object
Generates method (instance) functions.
29 30 31 32 33 34 35 |
# File 'lib/sdk/factory.rb', line 29 def self.factory(_request, _resource, methods = [], = {}) accumulator = Helper.accumulate_procs('method', MAP) methods = methods.each_with_object({}, &accumulator) methods end |
.gauge ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/gauge.rb', line 5 def self.gauge proc do || end end |
.message ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/message.rb', line 5 def self. proc do || end end |
.remove ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/remove.rb', line 5 def self.remove proc do || end end |
.save ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sdk/method/save.rb', line 7 def self.save proc do |instance| uri = Helper.instance_to_uri instance # TODO: need a way to make raw requests without middleware. # TODO: there is no reason to have to create another instance. if instance.new? instance.request.post(uri, instance.properties) .then do |result| instance.override_properties(result.properties) instance end else instance.request.put(uri, instance.properties) .then do |result| instance.override_properties(result.properties) instance end end end end |
.to_json ⇒ Object
5 6 7 8 |
# File 'lib/sdk/method/to_json.rb', line 5 def self.to_json proc do || end end |
.trigger ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/sdk/method/trigger.rb', line 7 def self.trigger proc do |instance, payload = {}| # raise if the instance has not been saved yet... uri = Helper.instance_to_uri instance instance.request.post("#{uri}/trigger", payload) end end |