Class: TriggerSwitchD::Application
- Inherits:
-
Object
- Object
- TriggerSwitchD::Application
- Defined in:
- lib/trigger_switch_d/application.rb
Overview
starts an instance of the daemon.
Instance Attribute Summary collapse
-
#devices ⇒ Object
(also: #list_devices)
readonly
Returns the value of attribute devices.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Application
constructor
Prepares the run by loading up the environment located in config/config.rb.
-
#list_schedule ⇒ Object
:nodoc:.
-
#start ⇒ Object
Runs the daemon untill process killed or it receives stop from client connected via unix socket.
Constructor Details
#initialize(config_file) ⇒ Application
Prepares the run by loading up the environment located in config/config.rb
32 33 34 35 36 37 |
# File 'lib/trigger_switch_d/application.rb', line 32 def initialize(config_file) @current_date = Date.new ConfigFactory.new(config_file) @logger = Logger.new(Config.log_object) logger.info("Environment prepared") end |
Instance Attribute Details
#devices ⇒ Object (readonly) Also known as: list_devices
Returns the value of attribute devices.
27 28 29 |
# File 'lib/trigger_switch_d/application.rb', line 27 def devices @devices end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
27 28 29 |
# File 'lib/trigger_switch_d/application.rb', line 27 def logger @logger end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
27 28 29 |
# File 'lib/trigger_switch_d/application.rb', line 27 def schedule @schedule end |
Instance Method Details
#list_schedule ⇒ Object
:nodoc:
67 68 69 |
# File 'lib/trigger_switch_d/application.rb', line 67 def list_schedule #:nodoc: schedule.by_name.keys end |
#start ⇒ Object
Runs the daemon untill process killed or it receives stop from client connected via unix socket
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trigger_switch_d/application.rb', line 41 def start com_thread = IPC.create(Config.unix_socket_path) logger.info("IPC started") com_thread["received"] = "anything" while ((command = com_thread["received"].to_sym) != :stop) now_time = Time.new load_db(now_time.strftime("%Y-%m-%d %H:%M:%S")) hhmm_now_time = now_time.strftime("%H:%M") if methods.include? command.to_s com_thread["response"] = send(command).to_yaml logger.info("Received #{command} via IPC") Config.log_object.flush com_thread["received"] = "anything" com_thread.run end if (schedule.cronological.keys.include? hhmm_now_time) logger.info("Executed #{schedule.cronological[hhmm_now_time].length} action(s) at #{hhmm_now_time}") Config.log_object.flush schedule.execute(hhmm_now_time,Config.output) end Kernel.sleep(1) com_thread["received"] = "anything" if com_thread["received"] == "" end logger.info("Received #{command} via IPC") end |