module Nutella::App

App-level APIs sub-module

Public Class Methods

app_runs_list() click to toggle source
# File lib/nutella_lib/app_core.rb, line 26
def self.app_runs_list
  raise 'Nutella has not been initialized: you need to call the proper init method before you can start using nutella' if @app_runs_list.nil?
  @app_runs_list
end
app_runs_list=(val) click to toggle source

Setter/getter for runs_list

# File lib/nutella_lib/app_core.rb, line 25
def self.app_runs_list=(val) @app_runs_list=val; end
extract_component_id() click to toggle source

Extracts the component name from the folder where the code for this component is located

@return [String] the component name

# File lib/nutella_lib/app_core.rb, line 51
def self.extract_component_id
  Nutella.extract_component_id
end
init( broker_hostname, app_id, component_id ) click to toggle source

Initializes this component as an application component @param [String] broker_hostname @param [String] app_id @param [String] component_id

# File lib/nutella_lib/app_core.rb, line 9
def self.init( broker_hostname, app_id, component_id )
  Nutella.app_id = app_id
  Nutella.run_id = nil
  Nutella.component_id = component_id
  Nutella.resource_id = nil
  Nutella.mongo_host = broker_hostname
  Nutella.mqtt = SimpleMQTTClient.new broker_hostname
  
  # Start pinging
  Nutella.net.start_pinging
  # Fetch the `run_id`s list for this application and subscribe to its updates
  net.async_request('app_runs_list', lambda { |res| Nutella.app.app_runs_list = res })
  self.net.subscribe('app_runs_list', lambda {|message, _| Nutella.app.app_runs_list = message })
end
log() click to toggle source
# File lib/nutella_lib/app_core.rb, line 33
def self.log; Nutella::App::Log; end
net() click to toggle source

Accessors for sub-modules

# File lib/nutella_lib/app_core.rb, line 32
def self.net; Nutella::App::Net; end
parse_args(args) click to toggle source

Parse command line arguments for app level components

@param [Array] args command line arguments array @return [String, String] broker and app_id

# File lib/nutella_lib/app_core.rb, line 40
def self.parse_args(args)
  if args.length < 2
    STDERR.puts 'Couldn\'t read broker address and app_id from the command line, impossible to initialize component!'
    return
  end
  return args[0], args[1]
end
persist() click to toggle source
# File lib/nutella_lib/app_core.rb, line 34
def self.persist; Nutella::App::Persist; end
set_resource_id( resource_id ) click to toggle source

Sets the resource id

@param [String] resource_id the resource id (i.e. the particular instance of this component)

# File lib/nutella_lib/app_core.rb, line 58
def self.set_resource_id( resource_id )
  Nutella.set_resource_id resource_id
end