lib/openwfe/expressions/fe_cron.rb in openwferu-0.9.13 vs lib/openwfe/expressions/fe_cron.rb in openwferu-0.9.14

- old
+ new

@@ -28,20 +28,17 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #++ # -# $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $ -# # # "made in Japan" # # John Mettraux at openwfe.org # -#require 'openwfe/rudefinitions' require 'openwfe/utils' require 'openwfe/util/otime' require 'openwfe/util/scheduler' require 'openwfe/expressions/time' @@ -63,16 +60,26 @@ # 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). # + # Since OpenWFEru 0.9.14, 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. + # class CronExpression < TimeExpression names :cron attr_accessor \ - :raw_child, :tab, :name, :counter + :raw_child, :tab, :every, :name, :counter def apply (workitem) @counter = 0 @@ -83,11 +90,14 @@ @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() @@ -102,11 +112,11 @@ # # 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) if @name + set_variable(@name, self) # # resume flow reply_to_parent(workitem) @@ -120,17 +130,15 @@ #end # # implemented in parent TimeExpression class # - # This is the method called each time, the scheduler triggers + # This is the method called each time the scheduler triggers # this cron. The contained segment of process will get # executed. # def trigger (params) - # - # launch raw child ldebug { "trigger() cron : #{@fei.to_debug_s}" } @raw_child.application_context = @application_context @@ -142,11 +150,11 @@ # # update count and store self @counter += 1 - set_variable(@name, self) if @name + #set_variable(@name, self) rescue lerror do "trigger() cron caught exception\n"+ OpenWFE::exception_to_s($!) @@ -164,15 +172,22 @@ #return unless @applied_workitem @scheduler_job_id = @name.dup @scheduler_job_id = "#{@fei.wfid}__#{@scheduler_job_id}" \ - if not OpenWFE::starts_with(@name, "//") + unless OpenWFE::starts_with(@name, "//") - get_scheduler.schedule( - @tab, - { :schedulable => self, :job_id => @scheduler_job_id }) + if @tab + get_scheduler.schedule( + @tab, + { :schedulable => self, :job_id => @scheduler_job_id }) + else + get_scheduler.schedule_every( + @every, + { :schedulable => self, :job_id => @scheduler_job_id }) + end + ldebug { "reschedule() name is '#{@name}'" } ldebug { "reschedule() job id is '#{@scheduler_job_id}'" } #store_itself() # # done by the containing environment itself