Class: OpenHAB::DSL::Rules::Triggers::CronHandler::CronTriggerHandler
- Inherits:
-
Object
- Object
- OpenHAB::DSL::Rules::Triggers::CronHandler::CronTriggerHandler
- Defined in:
- lib/openhab/dsl/rules/triggers/cron/cron_handler.rb
Overview
Cron Trigger Handler that provides trigger IDs Unfortunatly because the CronTriggerHandler in openHAB core is marked internal the entire thing must be recreated here
Instance Method Summary collapse
-
#dispose ⇒ Object
Dispose of the handler cancel the cron scheduled task.
-
#getTemporalAdjuster ⇒ CronAdjuster
Get the temporal adjuster.
-
#initialize(trigger) ⇒ CronTriggerHandler
constructor
Creates a new CronTriggerHandler.
-
#run ⇒ Object
Execute the callback.
-
#setCallback(callback) ⇒ Object
Set the callback to execute when cron trigger fires.
Constructor Details
#initialize(trigger) ⇒ CronTriggerHandler
Creates a new CronTriggerHandler
32 33 34 35 36 37 38 |
# File 'lib/openhab/dsl/rules/triggers/cron/cron_handler.rb', line 32 def initialize(trigger) @trigger = trigger @scheduler = OSGi.service("org.openhab.core.scheduler.CronScheduler") @schedule = nil @expression = trigger.configuration.get("cronExpression") super(trigger) end |
Instance Method Details
#dispose ⇒ Object
Dispose of the handler cancel the cron scheduled task
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/openhab/dsl/rules/triggers/cron/cron_handler.rb', line 71 def dispose synchronized do super return unless @schedule @schedule.cancel(true) @schedule = nil end logger.trace { "cancelled job for trigger '#{@trigger.id}'." } end |
#getTemporalAdjuster ⇒ CronAdjuster
Get the temporal adjuster
56 57 58 |
# File 'lib/openhab/dsl/rules/triggers/cron/cron_handler.rb', line 56 def getTemporalAdjuster # rubocop:disable Naming/MethodName org.openhab.core.scheduler.CronAdjuster.new(@expression) end |
#run ⇒ Object
Execute the callback
63 64 65 |
# File 'lib/openhab/dsl/rules/triggers/cron/cron_handler.rb', line 63 def run callback&.triggered(@trigger, { "module" => @trigger.id }) end |
#setCallback(callback) ⇒ Object
Set the callback to execute when cron trigger fires
44 45 46 47 48 49 50 |
# File 'lib/openhab/dsl/rules/triggers/cron/cron_handler.rb', line 44 def setCallback(callback) # rubocop:disable Naming/MethodName synchronized do super(callback) @schedule = @scheduler.schedule(self, @expression) logger.trace { "Scheduled cron job '#{@expression}' for trigger '#{@trigger.id}'." } end end |