Class: OpenWFE::CronExpression
- Inherits:
-
TimeExpression
- Object
- ObjectWithMeta
- FlowExpression
- TimeExpression
- OpenWFE::CronExpression
- Defined in:
- lib/openwfe/expressions/fe_cron.rb
Overview
Scheduling subprocesses for repeating execution
<cron tab="0 9-17 * * mon-fri" name="//reminder">
<send-reminder/>
</cron>
In this short process definition snippet, the subprocess “send-reminder” will get triggered once per hour (minute 0) from 0900 to 1700 and this, from monday to friday.
The ‘name’ of the cron indicates also at which level the cron should be bound. A double slash means the cron is bound at engine level (and will continue until it is unbound, as long as the engine is up, if the engine is a persisted one, the cron will continue when the engine restarts).
It’s possible to specify ‘every’ instead of ‘tab’ :
cron :every => "10m3s" do
send_reminder
end
The subprocess ‘send_reminder’ will thus be triggered every ten minutes and three seconds.
Instance Attribute Summary collapse
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#every ⇒ Object
Returns the value of attribute every.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_child ⇒ Object
Returns the value of attribute raw_child.
-
#tab ⇒ Object
Returns the value of attribute tab.
Attributes inherited from TimeExpression
#applied_workitem, #scheduler_job_id, #scheduler_tags
Attributes inherited from FlowExpression
#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation
Attributes included from Contextual
Instance Method Summary collapse
- #apply(workitem) ⇒ Object
- #reply(workitem) ⇒ Object
-
#reschedule(scheduler) ⇒ Object
This method is called at the first schedule of this expression or each time the engine is restarted and this expression has to be rescheduled.
-
#trigger(params) ⇒ Object
This is the method called each time the scheduler triggers this cron.
Methods inherited from TimeExpression
Methods inherited from FlowExpression
#cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Methods inherited from ObjectWithMeta
#class_def, meta_def, meta_eval, metaclass
Constructor Details
This class inherits a constructor from OpenWFE::FlowExpression
Instance Attribute Details
#counter ⇒ Object
Returns the value of attribute counter.
76 77 78 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 76 def counter @counter end |
#every ⇒ Object
Returns the value of attribute every.
76 77 78 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 76 def every @every end |
#name ⇒ Object
Returns the value of attribute name.
76 77 78 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 76 def name @name end |
#raw_child ⇒ Object
Returns the value of attribute raw_child.
76 77 78 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 76 def raw_child @raw_child end |
#tab ⇒ Object
Returns the value of attribute tab.
76 77 78 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 76 def tab @tab end |
Instance Method Details
#apply(workitem) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 80 def apply (workitem) return reply_to_parent(workitem) \ if @children.size < 1 @counter = 0 @applied_workitem = workitem.dup @applied_workitem.flow_expression_id = nil @tab = lookup_attribute(:tab, workitem) @every = lookup_attribute(:every, workitem) @name = lookup_attribute(:name, workitem) @name = fei.to_s unless @name @raw_child, _fei = get_expression_pool.fetch(@children[0]) @raw_child.parent_id = nil clean_children @children = nil # # schedule self reschedule get_scheduler # # store self as a variable # (have to do it after the reschedule, so that the schedule # info is stored within the variable) set_variable @name, self # # resume flow reply_to_parent workitem end |
#reply(workitem) ⇒ Object
123 124 125 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 123 def reply (workitem) # discard silently... should never get called though end |
#reschedule(scheduler) ⇒ Object
This method is called at the first schedule of this expression or each time the engine is restarted and this expression has to be rescheduled.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 167 def reschedule (scheduler) #return unless @applied_workitem @scheduler_job_id = if @name[0, 2] == "//" @name else "#{@fei.wfid}__#{@scheduler_job_id}" end if @tab get_scheduler.schedule( @tab, { :schedulable => self, :job_id => @scheduler_job_id, :tags => }) else get_scheduler.schedule_every( @every, { :schedulable => self, :job_id => @scheduler_job_id, :tags => }) end ldebug { "reschedule() name is '#{@name}'" } ldebug { "reschedule() job id is '#{@scheduler_job_id}'" } #store_itself # # done by the containing environment itself end |
#trigger(params) ⇒ Object
This is the method called each time the scheduler triggers this cron. The contained segment of process will get executed.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/openwfe/expressions/fe_cron.rb', line 132 def trigger (params) ldebug { "trigger() cron : #{@fei.to_debug_s}" } @raw_child.application_context = @application_context begin get_expression_pool.launch_template( @fei.wfid, nil, @counter, @raw_child, @applied_workitem.dup) # # update count and store self @counter += 1 if @name[0, 2] == '//' set_variable @name, self else store_itself end rescue lerror do "trigger() cron caught exception\n"+ OpenWFE::exception_to_s($!) end end end |