openwferu 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/examples/mano_tracker.rb +165 -0
  2. data/examples/scheduler_cron_usage.rb +46 -0
  3. data/examples/scheduler_usage.rb +54 -0
  4. data/lib/openwfe/contextual.rb +7 -1
  5. data/lib/openwfe/engine/engine.rb +58 -15
  6. data/lib/openwfe/expool/expressionpool.rb +116 -14
  7. data/lib/openwfe/expool/expstorage.rb +12 -12
  8. data/lib/openwfe/expool/journalexpstorage.rb +1 -1
  9. data/lib/openwfe/expool/yamlexpstorage.rb +58 -22
  10. data/lib/openwfe/expressions/environment.rb +32 -2
  11. data/lib/openwfe/expressions/expressionmap.rb +17 -0
  12. data/lib/openwfe/expressions/fe_condition.rb +122 -0
  13. data/lib/openwfe/expressions/fe_cursor.rb +14 -5
  14. data/lib/openwfe/expressions/fe_participant.rb +55 -4
  15. data/lib/openwfe/expressions/fe_raw.rb +43 -12
  16. data/lib/openwfe/expressions/fe_subprocess.rb +10 -0
  17. data/lib/openwfe/expressions/fe_time.rb +117 -22
  18. data/lib/openwfe/expressions/fe_value.rb +27 -8
  19. data/lib/openwfe/expressions/flowexpression.rb +13 -6
  20. data/lib/openwfe/expressions/raw_prog.rb +13 -11
  21. data/lib/openwfe/expressions/timeout.rb +94 -0
  22. data/lib/openwfe/flowexpressionid.rb +17 -19
  23. data/lib/openwfe/logging.rb +35 -16
  24. data/lib/openwfe/participants/atomparticipants.rb +31 -7
  25. data/lib/openwfe/participants/enoparticipant.rb +43 -3
  26. data/lib/openwfe/participants/participant.rb +21 -1
  27. data/lib/openwfe/participants/participantmap.rb +4 -2
  28. data/lib/openwfe/participants/participants.rb +12 -17
  29. data/lib/openwfe/participants/soapparticipants.rb +15 -3
  30. data/lib/openwfe/rudefinitions.rb +3 -0
  31. data/lib/openwfe/service.rb +8 -0
  32. data/lib/openwfe/storage/yamlfilestorage.rb +85 -47
  33. data/lib/openwfe/{otime.rb → util/otime.rb} +0 -0
  34. data/lib/openwfe/util/scheduler.rb +415 -231
  35. data/lib/openwfe/util/schedulers.rb +11 -3
  36. data/lib/openwfe/util/stoppable.rb +69 -0
  37. data/lib/openwfe/utils.rb +14 -25
  38. data/lib/openwfe/workitem.rb +12 -6
  39. data/lib/openwfe/worklist/storeparticipant.rb +145 -0
  40. data/test/{atomtest.rb → atom_test.rb} +0 -0
  41. data/test/{crontest.rb → cron_test.rb} +7 -6
  42. data/test/cronline_test.rb +51 -0
  43. data/test/{dollartest.rb → dollar_test.rb} +0 -0
  44. data/test/{feitest.rb → fei_test.rb} +0 -0
  45. data/test/file_persistence_test.rb +15 -9
  46. data/test/flowtestbase.rb +11 -5
  47. data/test/ft_0.rb +8 -0
  48. data/test/ft_10_loop.rb +72 -10
  49. data/test/ft_11_ppd.rb +49 -0
  50. data/test/ft_17_condition.rb +83 -0
  51. data/test/ft_18_pname.rb +59 -0
  52. data/test/hparticipant_test.rb +96 -0
  53. data/test/{misctest.rb → misc_test.rb} +1 -1
  54. data/test/rake_qtest.rb +10 -4
  55. data/test/rake_test.rb +12 -1
  56. data/test/raw_prog_test.rb +1 -1
  57. data/test/restart_cron_test.rb +78 -0
  58. data/test/restart_test.rb +79 -0
  59. data/test/scheduler_test.rb +92 -0
  60. data/test/{timetest.rb → time_test.rb} +3 -38
  61. data/test/timeout_test.rb +73 -0
  62. metadata +26 -11
  63. data/lib/openwfe/worklist/worklists.rb +0 -175
@@ -50,15 +50,23 @@ module OpenWFE
50
50
  # infrastructure (so that one could easily use it without OpenWFE)
51
51
  #
52
52
  class SchedulerService < Scheduler
53
- include ServiceMixin
53
+ include ServiceMixin, Logging
54
54
 
55
55
  def initialize (service_name, application_context)
56
+
56
57
  super()
57
- @service_name = service_name
58
- @application_context = application_context
58
+
59
+ service_init(service_name, application_context)
60
+
61
+ ldebug { "initialize() SchedulerService #{self.object_id}" }
59
62
 
60
63
  start()
61
64
  end
65
+
66
+ def stop
67
+ linfo { "stop() for scheduler #{self.object_id}" }
68
+ do_stop
69
+ end
62
70
  end
63
71
 
64
72
  end
@@ -0,0 +1,69 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+
43
+ module OpenWFE
44
+
45
+ #
46
+ # A simple mixin for adding a stopped instance variable and some
47
+ # methods around it to a class (or an object).
48
+ #
49
+ module Stoppable
50
+
51
+ def initialize
52
+ @stopped = false
53
+ end
54
+
55
+ def do_stop
56
+ @stopped = true
57
+ end
58
+
59
+ def do_restart
60
+ @stopped = false
61
+ end
62
+
63
+ def is_stopped?
64
+ @stopped
65
+ end
66
+ end
67
+
68
+ end
69
+
@@ -95,7 +95,7 @@ module OpenWFE
95
95
  #
96
96
  # an automatic dup implementation attempt
97
97
  #
98
- def OpenWFE.dup (object)
98
+ def OpenWFE.fulldup (object)
99
99
 
100
100
  return nil if object == nil
101
101
 
@@ -103,25 +103,27 @@ module OpenWFE
103
103
  return object if object.kind_of? TrueClass
104
104
  return object if object.kind_of? FalseClass
105
105
 
106
+ return object.dup if object.kind_of? String
107
+
106
108
  o = object.class.new
107
109
 
108
110
  #
109
111
  # some kind of collection ?
110
112
 
111
- if object.kind_of?(Array)
113
+ if object.kind_of? Array
112
114
  object.each do |i|
113
- o << dup(i)
115
+ o << fulldup(i)
114
116
  end
115
- elsif object.kind_of?(Hash)
117
+ elsif object.kind_of? Hash
116
118
  object.each do |k, v|
117
- o[copy(k)] = dup(v)
119
+ o[copy(k)] = fulldup(v)
118
120
  end
119
121
  end
120
122
 
121
123
  #
122
124
  # duplicate the attributes of the object
123
125
 
124
- object.instance_variables.each do | v |
126
+ object.instance_variables.each do |v|
125
127
 
126
128
  #puts "v is #{v}"
127
129
 
@@ -129,11 +131,11 @@ module OpenWFE
129
131
 
130
132
  #puts "value is '#{value}'"
131
133
 
132
- value = dup(value)
134
+ value = fulldup(value)
133
135
 
134
136
  begin
135
137
  o.instance_variable_set(v, value)
136
- rescue Exception => e
138
+ rescue
137
139
  # ignore, must be readonly
138
140
  end
139
141
  end
@@ -142,24 +144,11 @@ module OpenWFE
142
144
  end
143
145
 
144
146
  def OpenWFE.to_underscore (string)
145
- replace_char(string, "-", "_")
147
+ string.gsub("-", "_")
146
148
  end
147
149
 
148
150
  def OpenWFE.to_dash (string)
149
- replace_char(string, "_", "-")
150
- end
151
-
152
- def OpenWFE.replace_char (string, from, to)
153
- s = ""
154
- 0.upto(string.length) do |i|
155
- c = string[i, 1]
156
- s << if c == from
157
- to
158
- else
159
- c
160
- end
161
- end
162
- return s
151
+ string.gsub("_", "-")
163
152
  end
164
153
 
165
154
  #
@@ -171,7 +160,7 @@ module OpenWFE
171
160
  # method to the String class, but that could be intrusive
172
161
  # (as OpenWFE is meant at first as an embeddable workflow engine).
173
162
  #
174
- return false if not string
163
+ return false unless string
175
164
  return false if string.length < start.length
176
165
  return string[0, start.length] == start
177
166
  end
@@ -180,7 +169,7 @@ module OpenWFE
180
169
  # Returns true if the given string ends with the '_end' string.
181
170
  #
182
171
  def OpenWFE.ends_with (string, _end)
183
- return false if not string
172
+ return false unless string
184
173
  return false if string.length < _end.length
185
174
  return string[-_end.length..-1] == _end
186
175
  end
@@ -116,6 +116,10 @@ module OpenWFE
116
116
 
117
117
  super(m, args)
118
118
  end
119
+
120
+ def dup
121
+ return OpenWFE::fulldup(self)
122
+ end
119
123
  end
120
124
 
121
125
  #
@@ -136,7 +140,8 @@ module OpenWFE
136
140
  #
137
141
  # Just a handy alias for flow_expression_id
138
142
  #
139
- alias fei flow_expression_id
143
+ alias :fei :flow_expression_id
144
+ alias :fei= :flow_expression_id=
140
145
  end
141
146
 
142
147
  #
@@ -153,10 +158,6 @@ module OpenWFE
153
158
  #
154
159
  # special : added by the ruby lib, not given by the worklist
155
160
 
156
- def dup
157
- return OpenWFE::dup(self)
158
- end
159
-
160
161
  #
161
162
  # Outputting the workitem in a human readable format
162
163
  #
@@ -183,6 +184,11 @@ module OpenWFE
183
184
  # receiving a cancel item.
184
185
  #
185
186
  class CancelItem < InFlowItem
187
+
188
+ def initialize (workitem)
189
+ super()
190
+ @flow_expression_id = workitem.fei.dup
191
+ end
186
192
  end
187
193
 
188
194
  #
@@ -234,7 +240,7 @@ module OpenWFE
234
240
  :expression_id
235
241
 
236
242
  def dup
237
- return OpenWFE::dup(self)
243
+ return OpenWFE::fulldup(self)
238
244
  end
239
245
  end
240
246
 
@@ -0,0 +1,145 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ #
34
+
35
+ #
36
+ # "made in Japan"
37
+ #
38
+ # Alain Hoang at openwfe.org
39
+ #
40
+
41
+ require 'openwfe/participants/participant'
42
+
43
+
44
+ module OpenWFE
45
+
46
+ #
47
+ # A mixin gathering the methods a workitem store participant needs.
48
+ #
49
+ # Two kinds of methods are involved here, the ones used by the engine
50
+ # (its participant map) and the ones used by 'workflow clients'.
51
+ # Thus consume() and cancel() are triggered by the engine, and
52
+ # save() and forward() are at the disposal of 'workflow clients'.
53
+ #
54
+ # A 'workflow client' is supposed to use methods similar to hash methods
55
+ # to retrieve workitems, like in
56
+ #
57
+ # storeparticipant.each do |fei, workitem|
58
+ # puts "workitem : #{fei.to_s}"
59
+ # do_some_work(workitem)
60
+ # end
61
+ #
62
+ #
63
+ module StoreParticipantMixin
64
+ include LocalParticipant
65
+
66
+ #def initialize ()
67
+ #end
68
+
69
+ #
70
+ # Called by the engine (the participant expression) when handing
71
+ # out a workitem (to this participant).
72
+ #
73
+ def consume (workitem)
74
+
75
+ self[workitem.flow_expression_id] = workitem
76
+ end
77
+
78
+ #
79
+ # Called by the participant expression when this participant is
80
+ # 'cancelled' within a flow. The workitem then gets removed.
81
+ #
82
+ def cancel (cancelitem)
83
+
84
+ ldebug do
85
+ "cancel() removing workitem #{cancelitem.flow_expression_id}"
86
+ end
87
+
88
+ self.delete(cancelitem.flow_expression_id)
89
+ end
90
+
91
+ #
92
+ # The workitem is to be stored again within the store participant,
93
+ # it will probably be reused later. Don't send back to engine yet.
94
+ #
95
+ def save (workitem)
96
+
97
+ raise "Workitem not found in #{self.class}, cannot save." \
98
+ unless self.has_key? workitem.flow_expression_id
99
+
100
+ self[workitem.flow_expression_id] = workitem
101
+ end
102
+
103
+ #
104
+ # The workflow client is done with the workitem, send it back to
105
+ # the engine and make sure it's not in the store participant anymore.
106
+ #
107
+ def forward (workitem)
108
+
109
+ raise "Workitem not found in #{self.class}, cannot forward." \
110
+ unless self.has_key? workitem.flow_expression_id
111
+
112
+ self.delete(workitem.flow_expression_id)
113
+ reply_to_engine(workitem)
114
+ end
115
+
116
+ #
117
+ # 'proceed' is just an alias for 'forward'
118
+ #
119
+ alias :proceed :forward
120
+
121
+ #
122
+ # Returns all the workitems for a given workflow isntance id.
123
+ #
124
+ def list_workitems (workflow_instance_id)
125
+
126
+ result = []
127
+ self.each_value do |workitem|
128
+ result << workitem \
129
+ if workitem.fei.parent_wfid == workflow_instance_id
130
+ end
131
+
132
+ result
133
+ end
134
+ end
135
+
136
+ #
137
+ # The simplest workitem store possible, gathers the workitem in a
138
+ # hash (this class is an extension of Hash).
139
+ #
140
+ class HashParticipant < Hash
141
+ include StoreParticipantMixin
142
+
143
+ # that's all...
144
+ end
145
+ end
File without changes
@@ -8,14 +8,15 @@
8
8
  #
9
9
 
10
10
  require 'test/unit'
11
- require 'otime'
12
- require 'ru/util/scheduler'
11
+
12
+ require 'openwfe/util/otime'
13
+ require 'openwfe/util/scheduler'
14
+
13
15
 
14
16
  #
15
- # testing otime and the scheduler
17
+ # testing otime and the scheduler (its cron aspect)
16
18
  #
17
-
18
- class TimeTest < Test::Unit::TestCase
19
+ class CronTest < Test::Unit::TestCase
19
20
 
20
21
  #def setup
21
22
  #end
@@ -29,7 +30,7 @@ class TimeTest < Test::Unit::TestCase
29
30
  scheduler = OpenWFE::Scheduler.new()
30
31
  scheduler.start
31
32
 
32
- sid = scheduler.schedule('* * * * *', CounterSchedulable.new, nil)
33
+ sid = scheduler.schedule('* * * * *', nil, CounterSchedulable.new, nil)
33
34
 
34
35
  assert \
35
36
  sid,
@@ -0,0 +1,51 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Sun Oct 29 16:18:25 JST 2006
8
+ #
9
+
10
+ require 'pp'
11
+ require 'test/unit'
12
+
13
+ require 'openwfe/util/scheduler'
14
+
15
+
16
+ #
17
+ # testing the Scheduler's CronLine system
18
+ #
19
+ class CronLineTest < Test::Unit::TestCase
20
+
21
+ #def setup
22
+ #end
23
+
24
+ #def teardown
25
+ #end
26
+
27
+ def do_cltest (line, array)
28
+ cl = OpenWFE::CronLine.new(line)
29
+
30
+ unless cl.to_array == array
31
+ puts
32
+ pp cl.to_array
33
+ puts " should be"
34
+ pp array
35
+ end
36
+
37
+ assert \
38
+ cl.to_array == array
39
+ end
40
+
41
+ def test_cron_line_0
42
+ do_cltest "* * * * *", [ nil, nil, nil, nil, nil ]
43
+ do_cltest "10-12 * * * *", [ [10, 11, 12], nil, nil, nil, nil ]
44
+ do_cltest "* * * * sun,mon", [ nil, nil, nil, nil, [7, 1] ]
45
+ do_cltest "* * * * mon-wed", [ nil, nil, nil, nil, [1, 2, 3] ]
46
+
47
+ #do_cltest "* * * * sun,mon-tue", [ nil, nil, nil, nil, [7, 1, 2] ]
48
+ #do_cltest "* * * * 7-1", [ nil, nil, nil, nil, [7, 1, 2] ]
49
+ end
50
+
51
+ end