lib/openwfe/expressions/fe_cron.rb in openwferu-0.9.16 vs lib/openwfe/expressions/fe_cron.rb in openwferu-0.9.17

- old
+ new

@@ -1,8 +1,8 @@ # #-- -# Copyright (c) 2006-2007, John Mettraux, OpenWFE.org +# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # @@ -36,12 +36,10 @@ # # John Mettraux at openwfe.org # require 'openwfe/utils' -require 'openwfe/util/otime' -require 'openwfe/util/scheduler' require 'openwfe/expressions/time' module OpenWFE @@ -60,12 +58,11 @@ # 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' : + # It's possible to specify 'every' instead of 'tab' : # # cron :every => "10m3s" do # send_reminder # end # @@ -77,19 +74,18 @@ names :cron attr_accessor \ :raw_child, :tab, :every, :name, :counter + def apply (workitem) + return reply_to_parent(workitem) \ + if @children.size < 1 + @counter = 0 - if @children.size < 1 - reply_to_parent workitem - return - end - @applied_workitem = workitem.dup @applied_workitem.flow_expression_id = nil @tab = lookup_attribute(:tab, workitem) @every = lookup_attribute(:every, workitem) @@ -98,20 +94,20 @@ @name = fei.to_s unless @name @raw_child, _fei = get_expression_pool.fetch(@children[0]) @raw_child.parent_id = nil - clean_children() + clean_children @children = nil determine_scheduler_tags # # schedule self - reschedule(get_scheduler) + 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) @@ -140,18 +136,22 @@ @raw_child.application_context = @application_context begin get_expression_pool.launch_template( - @fei.wfid, @counter, @raw_child, @applied_workitem.dup) + @fei.wfid, nil, @counter, @raw_child, @applied_workitem.dup) # # update count and store self @counter += 1 - #set_variable(@name, self) + if @name[0, 2] == '//' + set_variable @name, self + else + store_itself + end rescue lerror do "trigger() cron caught exception\n"+ OpenWFE::exception_to_s($!) @@ -166,13 +166,14 @@ # def reschedule (scheduler) #return unless @applied_workitem - @scheduler_job_id = @name.dup - - @scheduler_job_id = "#{@fei.wfid}__#{@scheduler_job_id}" \ - unless OpenWFE::starts_with(@name, "//") + @scheduler_job_id = if @name[0, 2] == "//" + @name + else + "#{@fei.wfid}__#{@scheduler_job_id}" + end if @tab get_scheduler.schedule( @tab, {