lib/openwfe/expressions/environment.rb in openwferu-0.9.2 vs lib/openwfe/expressions/environment.rb in openwferu-0.9.3
- old
+ new
@@ -38,20 +38,22 @@
#
# John Mettraux at openwfe.org
#
require 'openwfe/utils'
+require 'openwfe/util/scheduler'
require 'openwfe/expressions/flowexpression'
module OpenWFE
#
# An environment is a store for variables.
# It's an expression as it's storable in the expression pool.
#
class Environment < FlowExpression
+ include Schedulable
attr_accessor \
:variables
def initialize \
@@ -120,19 +122,47 @@
# variables in this environment.
#
def unbind ()
@variables.each do |key, value|
- get_expression_pool().remove(value) \
- if value.kind_of? OpenWFE::FlowExpressionId
+ if value.kind_of? FlowExpressionId
+ get_expression_pool().remove(value)
+ elsif value.kind_of? FlowExpression
+ value.cancel
+ end
end
end
#
# Returns true if this environment is the engine environment
#
def is_engine_environment?
return @fei == get_expression_pool().engine_environment_id
+ end
+
+ #
+ # Should never get used, only the reschedule() method is relevant
+ # for the Schedulable aspect of an environment expression.
+ #
+ def trigger (params)
+ raise "an environment should never get directly triggered"
+ end
+
+ #
+ # Will reschedule any 'Schedulable' variable found in this environment
+ # this method especially targets cron expressions that are stored
+ # as variables and need to be rescheduled upon engine restart.
+ #
+ def reschedule (scheduler)
+
+ @variables.each do |key, value|
+ ldebug { "reschedule() - item of class #{value.class}" }
+ next unless value.kind_of? Schedulable
+ value.application_context = @application_context
+ value.reschedule(scheduler)
+ end
+
+ store_itself()
end
protected
def get_root_environment ()