problem with time calculation in ruby condition

0 views
Skip to first unread message

Maarten

unread,
Apr 23, 2008, 3:38:13 PM4/23/08
to OpenWFEru users
I have the following expression in my process:

<wait runtil="Time.now >= workitem.start_time - (2 * 3600)"/>

which fails because somehow the start_time attribute is converted from
Time to String during the process, probably while the workitem is
restored from the database by ActiveParticipant.

As a workaround I want to use the following expression:

<wait runtil="Time.now >= Time.parse(workitem.start_time.to_s) - (2 *
3600)"/>

However this one fails because I can't load the Time (standard)
library properly. I tried including "require 'time'" in various source
files, but it keeps failing with the following exception:

exception : undefined method `parse' for Time:Class
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/condition.rb:239:in `do_eval'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
rufus-eval-0.1/lib/rufus/eval.rb:105:in `join'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
rufus-eval-0.1/lib/rufus/eval.rb:105:in `eval_safely'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/condition.rb:239:in `do_eval'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/condition.rb:113:in
`do_eval_condition'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/condition.rb:71:in
`eval_condition'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/time.rb:258:in
`evaluate_condition'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/time.rb:217:in `trigger'
/Users/maarten/Documents/Projects/ejai/journeys/config/../vendor/gems/
openwferu-0.9.17/lib/openwfe/expressions/time.rb:178:in `apply'

Any ideas?

Thanks in advance,

Maarten

John Mettraux

unread,
Apr 23, 2008, 8:46:37 PM4/23/08
to openwfe...@googlegroups.com
On Thu, Apr 24, 2008 at 4:38 AM, Maarten <oele...@gmail.com> wrote:
>
> <wait runtil="Time.now >= workitem.start_time - (2 * 3600)"/>
>
> which fails because somehow the start_time attribute is converted from
> Time to String during the process, probably while the workitem is
> restored from the database by ActiveParticipant.
>
> As a workaround I want to use the following expression:
>
> <wait runtil="Time.now >= Time.parse(workitem.start_time.to_s) - (2 *
> 3600)"/>


> However this one fails because I can't load the Time (standard)
> library properly. I tried including "require 'time'" in various source
> files, but it keeps failing with the following exception:
>
> exception : undefined method `parse' for Time:Class


Hi Maarten,

I managed to fix the "flattened time in db" issue :

http://github.com/jmettraux/ruote/commit/3340464c366bb91293f07f5b79a9c54581d570f9

I have also made sure Date is handled correctly as well, see tests 6 and 6b :

http://github.com/jmettraux/ruote/commit/3340464c366bb91293f07f5b79a9c54581d570f9#diff-3


About the missing parse method, I discovered that by putting "require
'date'" at the top of the rufus/eval.rb file, I was able to use
Time.parse(). Maybe by putting that require before the first mention
to "require 'openwfe/...'" would do the trick.


I hope this will help, thanks for the feedback,

--
John Mettraux - http://jmettraux.wordpress.com

Arjan van Bentem

unread,
Apr 24, 2008, 5:57:00 PM4/24/08
to openwfe...@googlegroups.com

> <wait runtil="Time.now >= workitem.start_time - (2 * 3600)"/>

This workitem.start_time is your own field, right (and if I understand
correctly: is some time in the future)?

For such "wait" expression, can one access :launch_time from
OpenWFE::ProcessStatus?

${f:launch_time} seems empty. In Densha, ${f:launcher} is set in app/
controllers/launchp_controller.rb -- in which I can easily add
something:

def launch
:
li = OpenWFE::LaunchItem.new
li.workflow_definition_url = lp.real_url
li.launcher = user.name

# NEW
li.launched_at = Time.now
:

...and then use "${f:launch_time}" in my process definition.

Or is there a way to get to the actual process information directly?

Thanks!
Arjan.

Maarten

unread,
Apr 27, 2008, 3:44:05 PM4/27/08
to OpenWFEru users
John,

Many thanks for fixing this so quickly.

Arjen, start_time is a custom workitem attribute in my application.

Maarten


John Mettraux

unread,
Apr 27, 2008, 7:43:09 PM4/27/08
to openwfe...@googlegroups.com
On Fri, Apr 25, 2008 at 6:57 AM, Arjan van Bentem
<arjan.v...@bidnetwork.org> wrote:
>
> > <wait runtil="Time.now >= workitem.start_time - (2 * 3600)"/>
>
> This workitem.start_time is your own field, right (and if I understand
> correctly: is some time in the future)?
>
> For such "wait" expression, can one access :launch_time from
> OpenWFE::ProcessStatus?


In those "r" prefixed expression attributes, "wi" and "fe" are
available, being respectively the current workitem and the current
flowexpression.

You could thus do

<wait runtil="Time.now >=
fe.get_engine.process_status(fe.fei.wfid).launch_time + x" />

but maybe the intention is just

<sleep for="x" />


> ${f:launch_time} seems empty. In Densha, ${f:launcher} is set in app/
> controllers/launchp_controller.rb -- in which I can easily add
> something:
>
> def launch
> :
> li = OpenWFE::LaunchItem.new
> li.workflow_definition_url = lp.real_url
> li.launcher = user.name
>
> # NEW
> li.launched_at = Time.now
> :
>
> ...and then use "${f:launch_time}" in my process definition.

It's more economical than fetching the process status (an operation
that has to query the expression storage... with a cache on, it's not
a big problem though).


Best regards,

Arjan van Bentem

unread,
Apr 28, 2008, 1:57:47 AM4/28/08
to openwfe...@googlegroups.com

> You could thus do
>
> <wait runtil="Time.now >=
> fe.get_engine.process_status(fe.fei.wfid).launch_time + x" />
>
> but maybe the intention is just
>
> <sleep for="x" />

Great explanation!

By the way: I did consider using sleep, but for my process definition
that would imply a concurrence spanning from the very start of my
process all the way to the end (after some initial steps, the user is
to receive an email some days after starting the process, and the
process is to be cancelled if not completed within some specific time).

Thanks,
Arjan.


John Mettraux

unread,
Apr 28, 2008, 2:16:27 AM4/28/08
to openwfe...@googlegroups.com
On Mon, Apr 28, 2008 at 2:57 PM, Arjan van Bentem
<arjan.v...@bidnetwork.org> wrote:
>
> By the way: I did consider using sleep, but for my process definition
> that would imply a concurrence spanning from the very start of my
> process all the way to the end (after some initial steps, the user is
> to receive an email some days after starting the process, and the
> process is to be cancelled if not completed within some specific time).

Hello,

something like :

---8<---
class ArjanProcess0 < OpenWFE::ProcessDefinition

concurrence :count => 1 do
# with count set to 1, when 1 branch replies
# the other branches get cancelled

core

sequence do
sleep "7d"
send_warning
sleep "3d"
# exit (other branches will get cancelled)
end
end

process_definition :name => "core" do
# ...
end
end
--->8---

?

Note that the process "core" could be another process (document)
referenced by URL or name. This this "ArjanProcess0" could become a
"pattern" and wrap any other process. See
http://openwferu.rubyforge.org/expressions.html#exp_subprocess or
http://github.com/jmettraux/ruote/tree/master/test/ft_29_httprb.rb
(where the <subprocess ref="http://process.server/definitionX.xml" />
is used).


Cheers,

Reply all
Reply to author
Forward
0 new messages