ruote 0.9.19 → 0.9.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (401) hide show
  1. data/README.txt +16 -6
  2. data/examples/engine_template.rb +6 -43
  3. data/examples/quickstart.rb +87 -0
  4. data/examples/quotereporter.rb +42 -49
  5. data/examples/simple.rb +56 -0
  6. data/lib/openwfe.rb +20 -34
  7. data/lib/openwfe/contextual.rb +45 -36
  8. data/lib/openwfe/def.rb +21 -30
  9. data/lib/openwfe/engine.rb +17 -26
  10. data/lib/openwfe/engine/engine.rb +132 -397
  11. data/lib/openwfe/engine/expool_methods.rb +34 -122
  12. data/lib/openwfe/engine/file_persisted_engine.rb +39 -60
  13. data/lib/openwfe/engine/fs_engine.rb +54 -0
  14. data/lib/openwfe/engine/launch_methods.rb +245 -0
  15. data/lib/openwfe/engine/listener_methods.rb +128 -0
  16. data/lib/openwfe/engine/lookup_methods.rb +156 -0
  17. data/lib/openwfe/engine/participant_methods.rb +60 -52
  18. data/lib/openwfe/engine/status_methods.rb +102 -97
  19. data/lib/openwfe/engine/tc_engine.rb +55 -0
  20. data/lib/openwfe/engine/tt_engine.rb +55 -0
  21. data/lib/openwfe/engine/update_exp_methods.rb +46 -39
  22. data/lib/openwfe/expool/def_parser.rb +196 -0
  23. data/lib/openwfe/expool/errorjournal.rb +51 -219
  24. data/lib/openwfe/expool/errors.rb +69 -0
  25. data/lib/openwfe/expool/expool_pause_methods.rb +32 -43
  26. data/lib/openwfe/expool/expressionpool.rb +398 -594
  27. data/lib/openwfe/expool/expstorage.rb +68 -72
  28. data/lib/openwfe/expool/fs_expstorage.rb +302 -0
  29. data/lib/openwfe/expool/history.rb +54 -38
  30. data/lib/openwfe/expool/journal.rb +24 -38
  31. data/lib/openwfe/expool/journal_replay.rb +20 -36
  32. data/lib/openwfe/expool/representation.rb +62 -78
  33. data/lib/openwfe/expool/tc_expstorage.rb +239 -0
  34. data/lib/openwfe/expool/{threadedexpstorage.rb → threaded_expstorage.rb} +25 -53
  35. data/lib/openwfe/expool/tt_expstorage.rb +55 -0
  36. data/lib/openwfe/expool/wfidgen.rb +23 -43
  37. data/lib/openwfe/expool/yaml_errorjournal.rb +187 -0
  38. data/lib/openwfe/expressions/condition.rb +33 -58
  39. data/lib/openwfe/expressions/environment.rb +62 -76
  40. data/lib/openwfe/expressions/{expressionmap.rb → expression_map.rb} +40 -54
  41. data/lib/openwfe/expressions/expression_tree.rb +265 -0
  42. data/lib/openwfe/expressions/fe_cancel.rb +19 -39
  43. data/lib/openwfe/expressions/fe_command.rb +80 -84
  44. data/lib/openwfe/expressions/fe_concurrence.rb +250 -313
  45. data/lib/openwfe/expressions/fe_cron.rb +38 -55
  46. data/lib/openwfe/expressions/fe_cursor.rb +49 -74
  47. data/lib/openwfe/expressions/fe_define.rb +44 -90
  48. data/lib/openwfe/expressions/fe_do.rb +83 -70
  49. data/lib/openwfe/expressions/fe_equals.rb +17 -35
  50. data/lib/openwfe/expressions/fe_error.rb +103 -0
  51. data/lib/openwfe/expressions/fe_filter.rb +27 -44
  52. data/lib/openwfe/expressions/fe_filter_definition.rb +37 -54
  53. data/lib/openwfe/expressions/fe_fqv.rb +46 -65
  54. data/lib/openwfe/expressions/fe_http.rb +17 -31
  55. data/lib/openwfe/expressions/fe_if.rb +39 -55
  56. data/lib/openwfe/expressions/fe_iterator.rb +25 -42
  57. data/lib/openwfe/expressions/fe_listen.rb +71 -115
  58. data/lib/openwfe/expressions/fe_losfor.rb +34 -43
  59. data/lib/openwfe/expressions/fe_misc.rb +70 -109
  60. data/lib/openwfe/expressions/fe_participant.rb +61 -99
  61. data/lib/openwfe/expressions/fe_reserve.rb +28 -59
  62. data/lib/openwfe/expressions/fe_save.rb +62 -81
  63. data/lib/openwfe/expressions/fe_sequence.rb +45 -70
  64. data/lib/openwfe/expressions/fe_set.rb +22 -40
  65. data/lib/openwfe/expressions/fe_step.rb +22 -37
  66. data/lib/openwfe/expressions/fe_subprocess.rb +34 -55
  67. data/lib/openwfe/expressions/fe_timeout.rb +28 -44
  68. data/lib/openwfe/expressions/fe_wait.rb +142 -36
  69. data/lib/openwfe/expressions/fe_when.rb +22 -46
  70. data/lib/openwfe/expressions/filter.rb +24 -43
  71. data/lib/openwfe/expressions/flowexpression.rb +211 -192
  72. data/lib/openwfe/expressions/iterator.rb +24 -39
  73. data/lib/openwfe/expressions/merge.rb +30 -52
  74. data/lib/openwfe/expressions/raw.rb +168 -384
  75. data/lib/openwfe/expressions/rprocdef.rb +79 -76
  76. data/lib/openwfe/expressions/time.rb +89 -103
  77. data/lib/openwfe/expressions/timeout.rb +98 -92
  78. data/lib/openwfe/expressions/value.rb +43 -69
  79. data/lib/openwfe/extras/engine/ar_engine.rb +58 -0
  80. data/lib/openwfe/extras/engine/db_persisted_engine.rb +37 -57
  81. data/lib/openwfe/extras/engine/dm_engine.rb +59 -0
  82. data/lib/openwfe/extras/expool/ar_expstorage.rb +337 -0
  83. data/lib/openwfe/extras/expool/db_errorjournal.rb +165 -0
  84. data/lib/openwfe/extras/expool/db_expstorage.rb +73 -0
  85. data/lib/openwfe/extras/expool/db_history.rb +163 -0
  86. data/lib/openwfe/extras/expool/dm_expstorage.rb +327 -0
  87. data/lib/openwfe/extras/listeners/jabber_listeners.rb +102 -0
  88. data/lib/openwfe/extras/listeners/jabberlisteners.rb +26 -0
  89. data/lib/openwfe/extras/listeners/sqs_listeners.rb +128 -0
  90. data/lib/openwfe/extras/misc/activityfeed.rb +19 -34
  91. data/lib/openwfe/extras/misc/jabber_common.rb +122 -0
  92. data/lib/openwfe/extras/participants/active_participants.rb +724 -0
  93. data/lib/openwfe/extras/participants/active_resource_participants.rb +213 -0
  94. data/lib/openwfe/extras/participants/activeparticipants.rb +1 -747
  95. data/lib/openwfe/extras/participants/ar_participants.rb +285 -0
  96. data/lib/openwfe/extras/participants/atomfeed_participants.rb +19 -34
  97. data/lib/openwfe/extras/participants/atompub_participants.rb +19 -34
  98. data/lib/openwfe/extras/participants/basecamp_participants.rb +17 -31
  99. data/lib/openwfe/extras/participants/{csvparticipants.rb → decision_participants.rb} +17 -31
  100. data/lib/openwfe/extras/participants/jabber_participants.rb +147 -0
  101. data/lib/openwfe/extras/participants/jabberparticipants.rb +3 -0
  102. data/lib/openwfe/extras/participants/sqs_participants.rb +108 -0
  103. data/lib/openwfe/extras/participants/{twitterparticipants.rb → twitter_participants.rb} +20 -34
  104. data/lib/openwfe/extras/singlecon.rb +56 -0
  105. data/lib/openwfe/filterdef.rb +83 -65
  106. data/lib/openwfe/flowexpressionid.rb +99 -62
  107. data/lib/openwfe/listeners/listener.rb +54 -65
  108. data/lib/openwfe/listeners/listeners.rb +52 -56
  109. data/lib/openwfe/logging.rb +17 -31
  110. data/lib/openwfe/omixins.rb +25 -58
  111. data/lib/openwfe/participants.rb +1 -34
  112. data/lib/openwfe/participants/{enoparticipants.rb → mail_participants.rb} +33 -47
  113. data/lib/openwfe/participants/participant.rb +37 -36
  114. data/lib/openwfe/participants/participant_map.rb +245 -0
  115. data/lib/openwfe/participants/participants.rb +43 -69
  116. data/lib/openwfe/participants/{soapparticipants.rb → soap_participants.rb} +22 -36
  117. data/lib/openwfe/participants/{storeparticipants.rb → store_participants.rb} +57 -62
  118. data/lib/openwfe/{storage/yamlfilestorage.rb → participants/yaml_filestorage.rb} +35 -64
  119. data/lib/openwfe/representations.rb +770 -0
  120. data/lib/openwfe/rudefinitions.rb +17 -29
  121. data/lib/openwfe/service.rb +21 -32
  122. data/lib/openwfe/tools/flowtracer.rb +21 -35
  123. data/lib/openwfe/util/dollar.rb +48 -61
  124. data/lib/openwfe/util/irb.rb +19 -34
  125. data/lib/openwfe/util/json.rb +55 -0
  126. data/lib/openwfe/util/observable.rb +22 -41
  127. data/lib/openwfe/util/ometa.rb +21 -35
  128. data/lib/openwfe/util/treechecker.rb +17 -31
  129. data/lib/openwfe/util/workqueue.rb +45 -44
  130. data/lib/openwfe/util/xml.rb +80 -234
  131. data/lib/openwfe/utils.rb +67 -110
  132. data/lib/openwfe/version.rb +19 -27
  133. data/lib/openwfe/workitem.rb +119 -84
  134. data/lib/openwfe/worklist/storelocks.rb +17 -33
  135. data/lib/openwfe/worklist/storeparticipant.rb +1 -39
  136. data/lib/openwfe/worklist/worklist.rb +17 -31
  137. data/lib/pooltool.ru +311 -0
  138. data/test/{extras/active_connection.rb → ar_test_connection.rb} +26 -11
  139. data/test/bm/fatxml.rb +70 -0
  140. data/test/bm/load_26c.rb +79 -0
  141. data/test/dm_test_connection.rb +11 -0
  142. data/test/extras/base.rb +3 -0
  143. data/test/extras/et_0_sqs.rb +37 -0
  144. data/test/extras/et_jabber_test.rb +226 -0
  145. data/test/extras/test.rb +16 -0
  146. data/test/functional/base.rb +198 -0
  147. data/test/functional/db_ft_0_ar_participants.rb +136 -0
  148. data/test/functional/eft_0_process_definition.rb +34 -0
  149. data/test/functional/eft_10_unset.rb +60 -0
  150. data/test/functional/eft_11_sleep.rb +95 -0
  151. data/test/functional/eft_12_wait.rb +57 -0
  152. data/test/functional/eft_13_cursor.rb +139 -0
  153. data/test/functional/eft_14_loop.rb +36 -0
  154. data/test/functional/eft_15_undo.rb +77 -0
  155. data/test/functional/eft_16_redo.rb +88 -0
  156. data/test/functional/eft_1_print.rb +57 -0
  157. data/test/functional/eft_2_sequence.rb +47 -0
  158. data/test/functional/eft_3_equals.rb +98 -0
  159. data/test/functional/eft_4_if.rb +96 -0
  160. data/test/functional/eft_5_eval.rb +89 -0
  161. data/test/functional/eft_6_reval.rb +101 -0
  162. data/test/functional/eft_7_exp.rb +47 -0
  163. data/test/functional/eft_8_log.rb +50 -0
  164. data/test/functional/eft_9_set.rb +132 -0
  165. data/test/functional/engine_helper.rb +122 -0
  166. data/test/functional/ft_0_vars_at_launch.rb +27 -0
  167. data/test/functional/ft_1_process_status.rb +46 -0
  168. data/test/functional/ft_2_file_listener.rb +45 -0
  169. data/test/functional/ft_3_on_cancel.rb +171 -0
  170. data/test/functional/ft_4_on_error.rb +220 -0
  171. data/test/functional/ft_5_process_uri.rb +82 -0
  172. data/test/functional/ft_6_process_status.rb +62 -0
  173. data/test/functional/ft_7_parameters.rb +103 -0
  174. data/test/functional/ft_8_dollar.rb +53 -0
  175. data/test/functional/ft_9_register_participants.rb +119 -0
  176. data/test/functional/restart_base.rb +43 -0
  177. data/test/functional/rft_0_sleep.rb +76 -0
  178. data/test/functional/test.rb +24 -0
  179. data/test/path_helper.rb +12 -0
  180. data/test/test.rb +11 -1
  181. data/test/{rutest_utils.rb → test_helper.rb} +8 -31
  182. data/test/unit/test.rb +19 -0
  183. data/test/{fei_test.rb → unit/ut_0_fei.rb} +34 -49
  184. data/test/unit/ut_10_lookup_attribute.rb +86 -0
  185. data/test/unit/ut_11_filter.rb +124 -0
  186. data/test/{condition_test.rb → unit/ut_12_conditional.rb} +33 -40
  187. data/test/unit/ut_13_xmlutil.rb +57 -0
  188. data/test/unit/ut_14_var_field_lookup.rb +85 -0
  189. data/test/{fe_lookup_att_test.rb → unit/ut_15_fe_att_lookup.rb} +14 -21
  190. data/test/{storage_test.rb → unit/ut_16_expstorage_findexp.rb} +3 -9
  191. data/test/unit/ut_17_representations.rb +330 -0
  192. data/test/{hash_test.rb → unit/ut_17b_representations_hash.rb} +25 -21
  193. data/test/{slock_test.rb → unit/ut_18_store_lock.rb} +17 -20
  194. data/test/{wfid_test.rb → unit/ut_1_wfid.rb} +2 -73
  195. data/test/unit/ut_2_utils.rb +53 -0
  196. data/test/unit/ut_3_expmap.rb +65 -0
  197. data/test/{clone_test.rb → unit/ut_4_fulldup.rb} +41 -46
  198. data/test/{obs_test.rb → unit/ut_5_observable.rb} +9 -19
  199. data/test/unit/ut_6_treechecker.rb +101 -0
  200. data/test/unit/ut_7_parser_ruby.rb +344 -0
  201. data/test/unit/ut_7b_parser_ruby.rb +56 -0
  202. data/test/{description_test.rb → unit/ut_8_parser_description.rb} +8 -19
  203. data/test/unit/ut_9_workitem.rb +72 -0
  204. metadata +117 -234
  205. data/lib/openwfe/exceptions.rb +0 -51
  206. data/lib/openwfe/expool/parser.rb +0 -278
  207. data/lib/openwfe/expool/paused_error.rb +0 -77
  208. data/lib/openwfe/expool/yamlexpstorage.rb +0 -224
  209. data/lib/openwfe/expressions/fe_sleep.rb +0 -173
  210. data/lib/openwfe/extras/expool/dberrorjournal.rb +0 -189
  211. data/lib/openwfe/extras/expool/dbexpstorage.rb +0 -355
  212. data/lib/openwfe/extras/expool/dbhistory.rb +0 -135
  213. data/lib/openwfe/extras/listeners/sqslisteners.rb +0 -146
  214. data/lib/openwfe/extras/participants/sqsparticipants.rb +0 -125
  215. data/lib/openwfe/listeners/socketlisteners.rb +0 -272
  216. data/lib/openwfe/orest/definitions.rb +0 -113
  217. data/lib/openwfe/orest/osocket.rb +0 -148
  218. data/lib/openwfe/orest/xmlcodec.rb +0 -682
  219. data/lib/openwfe/participants/participantmap.rb +0 -249
  220. data/lib/openwfe/participants/socketparticipants.rb +0 -202
  221. data/lib/openwfe/storage/yamlcustom.rb +0 -106
  222. data/lib/openwfe/worklist/oldrest.rb +0 -244
  223. data/test/README.txt +0 -27
  224. data/test/back_0916_test.rb +0 -109
  225. data/test/bm/bm_1_xml_vs_prog.rb +0 -59
  226. data/test/bm/bm_2_step.rb +0 -109
  227. data/test/bm/ft_0f_5ms.rb +0 -35
  228. data/test/bm/ft_26_load.rb +0 -208
  229. data/test/bm/ft_26b_load.rb +0 -84
  230. data/test/bm/ft_26c_load.rb +0 -102
  231. data/test/bm/ft_recu.rb +0 -71
  232. data/test/concurrence_test.rb +0 -77
  233. data/test/console_test.rb +0 -12
  234. data/test/cron_ltest.rb +0 -15
  235. data/test/eno_test.rb +0 -76
  236. data/test/expmap_test.rb +0 -54
  237. data/test/expool_20031219_0916.tgz +0 -0
  238. data/test/extras/README.txt +0 -5
  239. data/test/extras/active_with_engine_test.rb +0 -140
  240. data/test/extras/activityfeed_test.rb +0 -85
  241. data/test/extras/ap_0_test.rb +0 -287
  242. data/test/extras/ap_1_test.rb +0 -53
  243. data/test/extras/ap_test_base.rb +0 -24
  244. data/test/extras/atomfeedp_test.rb +0 -113
  245. data/test/extras/atompubp_test.rb +0 -91
  246. data/test/extras/basecamp_test.rb +0 -53
  247. data/test/extras/db_errorjournal_utest.rb +0 -75
  248. data/test/extras/db_expstorage_utest.rb +0 -171
  249. data/test/extras/db_history_0_test.rb +0 -58
  250. data/test/extras/ft_19_csv.rb +0 -58
  251. data/test/extras/ft_71_b14008.rb +0 -85
  252. data/test/extras/sqs_test.rb +0 -57
  253. data/test/extras/twitter_test.rb +0 -62
  254. data/test/file_persisted_engine_test.rb +0 -64
  255. data/test/file_persistence_test.rb +0 -135
  256. data/test/filep_cancel_test.rb +0 -123
  257. data/test/filter_test.rb +0 -109
  258. data/test/flowtestbase.rb +0 -339
  259. data/test/ft_0.rb +0 -68
  260. data/test/ft_0b_sequence.rb +0 -36
  261. data/test/ft_0c_testname.rb +0 -33
  262. data/test/ft_0d_participant.rb +0 -30
  263. data/test/ft_0e_multibody.rb +0 -34
  264. data/test/ft_10_loop.rb +0 -133
  265. data/test/ft_11_ppd.rb +0 -411
  266. data/test/ft_11b_ppd.rb +0 -54
  267. data/test/ft_12_blockparticipant.rb +0 -97
  268. data/test/ft_13_eno.rb +0 -52
  269. data/test/ft_14_subprocess.rb +0 -88
  270. data/test/ft_14b_subprocess.rb +0 -192
  271. data/test/ft_14c_subprocess.rb +0 -68
  272. data/test/ft_15_iterator.rb +0 -216
  273. data/test/ft_15b_iterator.rb +0 -74
  274. data/test/ft_16_fqv.rb +0 -73
  275. data/test/ft_17_condition.rb +0 -84
  276. data/test/ft_18_pname.rb +0 -56
  277. data/test/ft_1_unset.rb +0 -175
  278. data/test/ft_1b_unset.rb +0 -39
  279. data/test/ft_20_cron.rb +0 -53
  280. data/test/ft_21_cron.rb +0 -87
  281. data/test/ft_21b_cron_pause.rb +0 -82
  282. data/test/ft_22_history.rb +0 -78
  283. data/test/ft_23_when.rb +0 -77
  284. data/test/ft_23b_when.rb +0 -70
  285. data/test/ft_23c_wait.rb +0 -80
  286. data/test/ft_23d_cww.rb +0 -58
  287. data/test/ft_24_def.rb +0 -44
  288. data/test/ft_25_cancel.rb +0 -92
  289. data/test/ft_27_getflowpos.rb +0 -143
  290. data/test/ft_28_fileparticipant.rb +0 -63
  291. data/test/ft_29_httprb.rb +0 -106
  292. data/test/ft_2_concurrence.rb +0 -137
  293. data/test/ft_2b_concurrence.rb +0 -188
  294. data/test/ft_2c_concurrence.rb +0 -64
  295. data/test/ft_30_socketlistener.rb +0 -203
  296. data/test/ft_31_flowname.rb +0 -39
  297. data/test/ft_32_journal.rb +0 -91
  298. data/test/ft_32c_journal.rb +0 -102
  299. data/test/ft_32d_journal.rb +0 -81
  300. data/test/ft_33_description.rb +0 -107
  301. data/test/ft_34_cancelwfid.rb +0 -80
  302. data/test/ft_35_localdefs.rb +0 -77
  303. data/test/ft_36_subprocids.rb +0 -97
  304. data/test/ft_37_pnames.rb +0 -70
  305. data/test/ft_38_tag.rb +0 -127
  306. data/test/ft_38b_tag.rb +0 -161
  307. data/test/ft_38c_tag.rb +0 -100
  308. data/test/ft_38d_tag.rb +0 -53
  309. data/test/ft_39_reserve.rb +0 -63
  310. data/test/ft_39b_reserve.rb +0 -84
  311. data/test/ft_3_equals.rb +0 -170
  312. data/test/ft_3b_lookup_vf.rb +0 -83
  313. data/test/ft_40_defined.rb +0 -61
  314. data/test/ft_41_case.rb +0 -110
  315. data/test/ft_42_environments.rb +0 -75
  316. data/test/ft_43_pat10.rb +0 -85
  317. data/test/ft_44_save.rb +0 -70
  318. data/test/ft_44b_restore.rb +0 -212
  319. data/test/ft_45_citerator.rb +0 -214
  320. data/test/ft_45b_citerator.rb +0 -77
  321. data/test/ft_46_pparams.rb +0 -62
  322. data/test/ft_47_filter.rb +0 -160
  323. data/test/ft_48_fe_filter.rb +0 -88
  324. data/test/ft_49_condition.rb +0 -133
  325. data/test/ft_4_misc.rb +0 -232
  326. data/test/ft_50_xml_attribute.rb +0 -152
  327. data/test/ft_51_stack.rb +0 -55
  328. data/test/ft_52_obs_participant.rb +0 -123
  329. data/test/ft_53_null_noop_participant.rb +0 -62
  330. data/test/ft_54_listen.rb +0 -288
  331. data/test/ft_54b_listen.rb +0 -66
  332. data/test/ft_54c_listen.rb +0 -99
  333. data/test/ft_55_ptimeout.rb +0 -58
  334. data/test/ft_56_timeout.rb +0 -59
  335. data/test/ft_57_a.rb +0 -148
  336. data/test/ft_58_ejournal.rb +0 -154
  337. data/test/ft_58b_ejournal.rb +0 -82
  338. data/test/ft_59_ps.rb +0 -212
  339. data/test/ft_5_time.rb +0 -118
  340. data/test/ft_60_ecancel.rb +0 -161
  341. data/test/ft_61_elsub.rb +0 -51
  342. data/test/ft_62_procparticipant.rb +0 -71
  343. data/test/ft_63_pause.rb +0 -137
  344. data/test/ft_64_alias.rb +0 -101
  345. data/test/ft_65_stringlaunch.rb +0 -59
  346. data/test/ft_66_subforget.rb +0 -70
  347. data/test/ft_67_schedlaunch.rb +0 -115
  348. data/test/ft_68_ifparticipant.rb +0 -70
  349. data/test/ft_69_cancelmissing.rb +0 -53
  350. data/test/ft_6_lambda.rb +0 -64
  351. data/test/ft_70_lookupvar.rb +0 -55
  352. data/test/ft_71_log.rb +0 -60
  353. data/test/ft_72_lookup_processes.rb +0 -79
  354. data/test/ft_73_cancel_sub.rb +0 -139
  355. data/test/ft_74_block_and_workitem_dup.rb +0 -63
  356. data/test/ft_75_ruby_attributes.rb +0 -89
  357. data/test/ft_76_merge_isolate.rb +0 -88
  358. data/test/ft_77_segments.rb +0 -35
  359. data/test/ft_78_eval.rb +0 -150
  360. data/test/ft_79_tticket.rb +0 -187
  361. data/test/ft_79b_tticket.rb +0 -172
  362. data/test/ft_79c_outcome.rb +0 -56
  363. data/test/ft_7_lose.rb +0 -104
  364. data/test/ft_7b_lose.rb +0 -78
  365. data/test/ft_80_spname.rb +0 -91
  366. data/test/ft_81_exp.rb +0 -60
  367. data/test/ft_82_trecu.rb +0 -52
  368. data/test/ft_83_badpause.rb +0 -58
  369. data/test/ft_84_updateexp.rb +0 -198
  370. data/test/ft_84b_subrepr.rb +0 -72
  371. data/test/ft_85_dolhash.rb +0 -43
  372. data/test/ft_86_dollar_fv.rb +0 -68
  373. data/test/ft_87_define.rb +0 -74
  374. data/test/ft_88_http.rb +0 -100
  375. data/test/ft_8_forget.rb +0 -44
  376. data/test/ft_9_cursor.rb +0 -154
  377. data/test/ft_9b_cursor.rb +0 -105
  378. data/test/ft_tests.rb +0 -130
  379. data/test/hparticipant_test.rb +0 -168
  380. data/test/lookup_att_test.rb +0 -90
  381. data/test/lookup_vf_test.rb +0 -94
  382. data/test/misc_test.rb +0 -94
  383. data/test/nut_0_irb.rb +0 -20
  384. data/test/param_test.rb +0 -290
  385. data/test/participant_test.rb +0 -101
  386. data/test/pending.rb +0 -23
  387. data/test/ps_representation.rb +0 -133
  388. data/test/rake_ltest.rb +0 -38
  389. data/test/rake_qtest.rb +0 -68
  390. data/test/raw_prog_test.rb +0 -407
  391. data/test/restart_cron_test.rb +0 -136
  392. data/test/restart_paused_test.rb +0 -103
  393. data/test/restart_sleep_test.rb +0 -140
  394. data/test/restart_tests.rb +0 -18
  395. data/test/restart_when_test.rb +0 -112
  396. data/test/ruby_procdef_test.rb +0 -132
  397. data/test/sec_test.rb +0 -206
  398. data/test/timeout_test.rb +0 -105
  399. data/test/treechecker_test.rb +0 -111
  400. data/test/util_xml_test.rb +0 -112
  401. data/test/wi_test.rb +0 -75
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module OpenWFE
27
+
28
+ #
29
+ # This error is raised when an expression belonging to a paused
30
+ # process is applied or replied to.
31
+ #
32
+ class PausedError < RuntimeError
33
+
34
+ attr_reader :wfid
35
+
36
+ def initialize (wfid)
37
+
38
+ super "process '#{wfid}' is paused"
39
+ @wfid = wfid
40
+ end
41
+
42
+ #
43
+ # Returns a hash for this PausedError instance.
44
+ # (simply returns the hash of the paused process' wfid).
45
+ #
46
+ def hash
47
+
48
+ @wfid.hash
49
+ end
50
+
51
+ #
52
+ # Returns true if the other is a PausedError issued for the
53
+ # same process instance (wfid).
54
+ #
55
+ def == (other)
56
+
57
+ return false unless other.is_a?(PausedError)
58
+
59
+ (@wfid == other.wfid)
60
+ end
61
+ end
62
+
63
+ #
64
+ # This is the error used by the 'error' expression (forcing an error...)
65
+ #
66
+ class ForcedError < RuntimeError
67
+ end
68
+ end
69
+
@@ -1,60 +1,48 @@
1
- #
2
1
  #--
3
- # Copyright (c) 2006-2008, 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:
2
+ # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
8
3
  #
9
- # . Redistributions of source code must retain the above copyright notice, this
10
- # list of conditions and the following disclaimer.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
11
10
  #
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.
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
15
13
  #
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.
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
19
21
  #
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.
22
+ # Made in Japan.
31
23
  #++
32
- #
33
24
 
34
- #
35
- # "made in Japan"
36
- #
37
- # John Mettraux at openwfe.org
38
- #
39
25
 
40
- #
41
- # Gets included into the ExpressionPool class
42
- #
43
- module OpenWFE::ExpoolPauseMethods
26
+ module OpenWFE
27
+
28
+ #
29
+ # Gets included into the ExpressionPool class
30
+ #
31
+ module ExpoolPauseMethods
44
32
 
45
33
  #
46
34
  # Pauses a process (sets its /__paused__ variable to true).
47
35
  #
48
36
  def pause_process (wfid)
49
37
 
50
- wfid = extract_wfid wfid
38
+ wfid = extract_wfid(wfid)
51
39
 
52
- root_expression = fetch_root wfid
40
+ root_expression = fetch_root(wfid)
53
41
 
54
42
  @paused_instances[wfid] = true
55
- root_expression.set_variable OpenWFE::VAR_PAUSED, true
43
+ root_expression.set_variable(OpenWFE::VAR_PAUSED, true)
56
44
 
57
- onotify :pause, root_expression.fei
45
+ onotify(:pause, root_expression.fei)
58
46
  end
59
47
 
60
48
  #
@@ -66,18 +54,18 @@ module OpenWFE::ExpoolPauseMethods
66
54
 
67
55
  wfid = extract_wfid wfid
68
56
 
69
- root_expression = fetch_root wfid
57
+ root_expression = fetch_root(wfid)
70
58
 
71
59
  #
72
60
  # remove 'paused' flag
73
61
 
74
- @paused_instances.delete wfid
75
- root_expression.unset_variable OpenWFE::VAR_PAUSED
62
+ @paused_instances.delete(wfid)
63
+ root_expression.unset_variable(OpenWFE::VAR_PAUSED)
76
64
 
77
65
  #
78
66
  # notify ...
79
67
 
80
- onotify :resume, root_expression.fei
68
+ onotify(:resume, root_expression.fei)
81
69
 
82
70
  #
83
71
  # replay
@@ -94,5 +82,6 @@ module OpenWFE::ExpoolPauseMethods
94
82
 
95
83
  paused_errors.each { |e| get_error_journal.replay_at_error e }
96
84
  end
85
+ end
97
86
  end
98
87
 
@@ -1,43 +1,27 @@
1
- #
2
1
  #--
3
- # Copyright (c) 2006-2008, 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:
2
+ # Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
8
3
  #
9
- # . Redistributions of source code must retain the above copyright notice, this
10
- # list of conditions and the following disclaimer.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
11
10
  #
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.
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
15
13
  #
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.
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
19
21
  #
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.
22
+ # Made in Japan.
31
23
  #++
32
- #
33
24
 
34
- #
35
- # "made in Japan"
36
- #
37
- # John Mettraux at openwfe.org
38
- #
39
-
40
- require 'uri'
41
25
 
42
26
  require 'openwfe/utils'
43
27
  require 'openwfe/service'
@@ -46,15 +30,12 @@ require 'openwfe/omixins'
46
30
  require 'openwfe/rudefinitions'
47
31
  require 'openwfe/flowexpressionid'
48
32
  require 'openwfe/util/observable'
49
- require 'openwfe/expool/parser'
50
- require 'openwfe/expool/representation'
51
- require 'openwfe/expool/paused_error'
33
+ require 'openwfe/expool/errors'
52
34
  require 'openwfe/expool/expool_pause_methods'
35
+ require 'openwfe/expool/representation'
53
36
  require 'openwfe/expressions/environment'
54
37
  require 'openwfe/expressions/raw'
55
38
 
56
- require 'rufus/verbs' # gem 'rufus-lru'
57
-
58
39
 
59
40
  module OpenWFE
60
41
 
@@ -90,8 +71,6 @@ module OpenWFE
90
71
 
91
72
  @paused_instances = {}
92
73
 
93
- #@monitors = MonitorProvider.new(application_context)
94
-
95
74
  @observers = {}
96
75
 
97
76
  @stopped = false
@@ -107,108 +86,7 @@ module OpenWFE
107
86
 
108
87
  @stopped = true
109
88
 
110
- onotify :stop
111
- end
112
-
113
- #--
114
- # Obtains a unique monitor for an expression.
115
- # It avoids the need for the FlowExpression instances to include
116
- # the monitor mixin by themselves
117
- #
118
- #def get_monitor (fei)
119
- # @monitors[fei]
120
- #end
121
- #++
122
-
123
- #
124
- # This method is called by the launch method. It's actually the first
125
- # stage of that method.
126
- # It may be interessant to use to 'validate' a launchitem and its
127
- # process definition, as it will raise an exception in case
128
- # of 'parameter' mismatch.
129
- #
130
- # There is a 'pre_launch_check' alias for this method in the
131
- # Engine class.
132
- #
133
- def prepare_raw_expression (launchitem)
134
-
135
- wfdurl = launchitem.workflow_definition_url
136
-
137
- raise "launchitem.workflow_definition_url not set, cannot launch" \
138
- unless wfdurl
139
-
140
- definition = if wfdurl.match "^field:"
141
-
142
- raise(
143
- ":definition_in_launchitem_allowed not set to true, "+
144
- "cannot launch"
145
- ) if ac[:definition_in_launchitem_allowed] != true
146
-
147
- wfdfield = wfdurl[6..-1]
148
- launchitem.attributes.delete wfdfield
149
- else
150
-
151
- read_uri wfdurl
152
- end
153
-
154
- raise "didn't find process definition at '#{wfdurl}'" \
155
- unless definition
156
-
157
- raw_expression = build_raw_expression launchitem, definition
158
-
159
- raw_expression.check_parameters launchitem
160
- #
161
- # will raise an exception if there are requirements
162
- # and one of them is not met
163
-
164
- raw_expression
165
- end
166
-
167
- #
168
- # Instantiates a workflow definition and launches it.
169
- #
170
- # This method call will return immediately, it could even return
171
- # before the actual launch is completely over.
172
- #
173
- # Returns the FlowExpressionId instance of the root expression of
174
- # the newly launched flow.
175
- #
176
- def launch (launchitem, options={})
177
-
178
- wait = (options[:wait_for] == true)
179
-
180
- #
181
- # prepare raw expression
182
-
183
- raw_expression = prepare_raw_expression launchitem
184
- #
185
- # will raise an exception if there are requirements
186
- # and one of them is not met
187
-
188
- raw_expression = wrap_in_schedule(raw_expression, options) \
189
- if options.size > 0
190
-
191
- raw_expression.new_environment
192
- #
193
- # as this expression is the root of a new process instance,
194
- # it has to have an environment for all the variables of
195
- # the process instance
196
-
197
- fei = raw_expression.fei
198
-
199
- #
200
- # apply prepared raw expression
201
-
202
- wi = build_workitem launchitem
203
-
204
- onotify :launch, fei, launchitem
205
-
206
- if wait
207
- wait_for(fei) { apply raw_expression, wi }
208
- else
209
- apply raw_expression, wi
210
- fei
211
- end
89
+ onotify(:stop)
212
90
  end
213
91
 
214
92
  #
@@ -217,33 +95,38 @@ module OpenWFE
217
95
  # (it's used by the concurrent iterator when preparing all its
218
96
  # iteration children)
219
97
  #
220
- def tprepare_child (
221
- parent_exp, template, sub_id, register_child, vars)
98
+ def tprepare_child (parent_exp, template, sub_id, options={})
222
99
 
223
- return fetch_expression(template) \
224
- if template.is_a?(FlowExpressionId)
100
+ return fetch_expression(template) if template.is_a?(FlowExpressionId)
101
+ # used for "scheduled launches"
225
102
 
226
103
  fei = parent_exp.fei.dup
227
- fei.expression_name = template.first
228
104
  fei.expression_id = "#{fei.expid}.#{sub_id}"
105
+ fei.expression_name = template.first
229
106
 
230
- raw_exp = RawExpression.new_raw(
231
- fei, nil, nil, @application_context, template)
107
+ parent_id = options[:orphan] ? nil : parent_exp.fei
232
108
 
233
- raw_exp.parent_id = parent_exp.fei
109
+ raw_exp = RawExpression.new_raw(
110
+ fei, parent_id, nil, @application_context, template)
234
111
 
235
- if vars
236
- raw_exp.new_environment vars
112
+ if vars = options[:variables]
113
+ raw_exp.new_environment(vars)
237
114
  else
238
115
  raw_exp.environment_id = parent_exp.environment_id
239
116
  end
240
117
 
118
+ raw_exp.dup_environment if options[:dup_environment]
119
+
241
120
  #workitem.fei = raw_exp.fei
242
121
  # done in do_apply...
243
122
 
244
- if register_child
123
+ if options[:register_child] == true
124
+
245
125
  (parent_exp.children ||= []) << raw_exp.fei
246
- update raw_exp
126
+
127
+ update(raw_exp)
128
+
129
+ parent_exp.store_itself unless options[:dont_store_parent]
247
130
  end
248
131
 
249
132
  raw_exp
@@ -258,48 +141,13 @@ module OpenWFE
258
141
  #
259
142
  # (used by 'cron' and more)
260
143
  #
261
- def tlaunch_child (
262
- parent_exp, template, sub_id, workitem, register_child, vars=nil)
263
-
264
- raw_exp = tprepare_child(
265
- parent_exp, template, sub_id, register_child, vars)
266
-
267
- onotify :tlaunch_child, raw_exp.fei, workitem
268
-
269
- apply raw_exp, workitem
270
-
271
- raw_exp.fei
272
- end
273
-
274
- #
275
- # Launches a template, but makes sure the new expression has no
276
- # parent.
277
- #
278
- # (used by 'listen')
279
- #
280
- def tlaunch_orphan (
281
- firing_exp, template, sub_id, workitem, register_child)
144
+ def tlaunch_child (parent_exp, template, sub_id, workitem, opts={})
282
145
 
283
- fei = firing_exp.fei.dup
284
- fei.expression_id = "#{fei.expid}.#{sub_id}"
285
- fei.expression_name = template.first
286
-
287
- raw_exp = RawExpression.new_raw(
288
- fei, nil, nil, @application_context, template)
146
+ raw_exp = tprepare_child(parent_exp, template, sub_id, opts)
289
147
 
290
- #raw_exp.parent_id = GONE_PARENT_ID
291
- raw_exp.parent_id = nil
292
- # it's an orphan, no parent
148
+ onotify(:tlaunch_child, raw_exp.fei, workitem)
293
149
 
294
- raw_exp.environment_id = firing_exp.environment_id
295
- # tapping anyway into the firer's environment
296
-
297
- (firing_exp.children ||= []) << raw_exp.fei \
298
- if register_child
299
-
300
- onotify :tlaunch_orphan, raw_exp.fei, workitem
301
-
302
- apply raw_exp, workitem
150
+ apply(raw_exp, workitem)
303
151
 
304
152
  raw_exp.fei
305
153
  end
@@ -308,45 +156,26 @@ module OpenWFE
308
156
  # Launches a subprocess.
309
157
  # The resulting wfid is a subid for the wfid of the firing expression.
310
158
  #
311
- # (used by 'subprocess')
159
+ # (used by the 'subprocess' expression, the 'on_cancel' feature and the
160
+ # ProcessParticipant)
312
161
  #
313
162
  def launch_subprocess (
314
- firing_exp, template, forget, workitem, params)
315
-
316
- raw_exp = if template.is_a?(FlowExpressionId)
163
+ firing_exp, template, forget, workitem, initial_variables)
317
164
 
318
- fetch_expression template
165
+ raw_exp = build_raw_expression(template)
319
166
 
320
- elsif template.is_a?(RawExpression)
167
+ raw_exp.parent_id = forget ? nil : firing_exp.fei
321
168
 
322
- template.application_context = @application_context
323
- template
169
+ raw_exp.fei.workflow_definition_url = firing_exp.fei.wfurl
324
170
 
325
- else # probably an URI
326
-
327
- build_raw_expression nil, template
328
- end
329
-
330
- raw_exp = raw_exp.dup
331
- raw_exp.fei = raw_exp.fei.dup
332
-
333
- if forget
334
- raw_exp.parent_id = nil
335
- else
336
- raw_exp.parent_id = firing_exp.fei
337
- end
338
-
339
- #raw_exp.fei.wfid = get_wfid_generator.generate
340
- #raw_exp.fei.wfid =
341
- # "#{firing_exp.fei.wfid}.#{firing_exp.get_next_sub_id}"
342
171
  raw_exp.fei.wfid =
343
172
  "#{firing_exp.fei.parent_wfid}.#{firing_exp.get_next_sub_id}"
344
173
 
345
- raw_exp.new_environment params
174
+ raw_exp.new_environment(initial_variables)
346
175
 
347
176
  raw_exp.store_itself
348
177
 
349
- apply raw_exp, workitem
178
+ apply(raw_exp, workitem)
350
179
 
351
180
  raw_exp.fei
352
181
  end
@@ -357,6 +186,8 @@ module OpenWFE
357
186
  # The raw_representation will be the template.
358
187
  # Stores and then apply the "cuckoo" expression.
359
188
  #
189
+ # Used by 'exp' and 'eval' and the do_handle_error method of the expool.
190
+ #
360
191
  def substitute_and_apply (fexp, template, workitem)
361
192
 
362
193
  re = RawExpression.new_raw(
@@ -366,9 +197,19 @@ module OpenWFE
366
197
  application_context,
367
198
  template)
368
199
 
369
- update re
200
+ update(re)
370
201
 
371
- apply re, workitem
202
+ apply(re, workitem)
203
+ end
204
+
205
+ #
206
+ # Launches new process instance.
207
+ #
208
+ def launch (raw_exp, workitem)
209
+
210
+ onotify(:launch, raw_exp.fei, workitem)
211
+
212
+ apply(raw_exp, workitem)
372
213
  end
373
214
 
374
215
  #
@@ -396,7 +237,7 @@ module OpenWFE
396
237
  #
397
238
  def cancel (exp)
398
239
 
399
- exp, fei = fetch exp
240
+ exp, fei = fetch(exp)
400
241
 
401
242
  unless exp
402
243
  linfo { "cancel() cannot cancel missing #{fei.to_debug_s}" }
@@ -405,11 +246,12 @@ module OpenWFE
405
246
 
406
247
  ldebug { "cancel() for #{fei.to_debug_s}" }
407
248
 
408
- onotify :cancel, exp
249
+ onotify(:cancel, exp)
409
250
 
410
251
  wi = exp.cancel
411
252
 
412
- remove exp
253
+ remove(exp)
254
+ # will remove owned environment if any
413
255
 
414
256
  wi
415
257
  end
@@ -424,19 +266,21 @@ module OpenWFE
424
266
  #
425
267
  def cancel_expression (exp)
426
268
 
427
- exp = fetch_expression exp
269
+ exp, fei = fetch(exp)
270
+
271
+ raise "cannot cancel 'missing' expression #{fei.to_short_s}" unless exp
428
272
 
429
- wi = cancel exp
273
+ wi = cancel(exp)
430
274
 
431
- # ( remember that in case of error, no wi could get returned...)
275
+ # (remember that in case of error, no wi can get returned...)
432
276
 
433
277
  if wi
434
278
 
435
- reply_to_parent exp, wi, false
279
+ reply_to_parent(exp, wi, false)
436
280
 
437
281
  elsif exp.parent_id
438
282
 
439
- parent_exp = fetch_expression exp.parent_id
283
+ parent_exp = fetch_expression(exp.parent_id)
440
284
  parent_exp.remove_child(exp.fei) if parent_exp
441
285
  end
442
286
  end
@@ -447,16 +291,16 @@ module OpenWFE
447
291
  #
448
292
  def cancel_process (exp_or_wfid)
449
293
 
450
- wfid = extract_wfid exp_or_wfid, false
294
+ wfid = extract_wfid(exp_or_wfid, false)
451
295
  # 'true' would have made sure that the parent wfid is used...
452
296
 
453
297
  ldebug { "cancel_process() '#{wfid}'" }
454
298
 
455
- root = fetch_root wfid
299
+ root = fetch_root(wfid)
456
300
 
457
301
  raise "no process to cancel '#{wfid}'" unless root
458
302
 
459
- cancel root
303
+ cancel(root)
460
304
  end
461
305
  alias :cancel_flow :cancel_process
462
306
 
@@ -471,17 +315,15 @@ module OpenWFE
471
315
 
472
316
  return if not exp
473
317
 
474
- onotify :forget, exp
475
-
476
318
  parent_exp.children.delete(fei)
477
319
 
478
- #exp.parent_id = GONE_PARENT_ID
479
320
  exp.parent_id = nil
480
-
481
321
  exp.dup_environment
482
- exp.store_itself()
322
+ exp.store_itself
483
323
 
484
- ldebug { "forget() forgot #{fei}" }
324
+ onotify(:forget, exp)
325
+
326
+ ldebug { "forget() forgot #{fei}" }
485
327
  end
486
328
 
487
329
  #
@@ -489,15 +331,13 @@ module OpenWFE
489
331
  #
490
332
  def reply_to_parent (exp, workitem, remove=true)
491
333
 
492
- ldebug { "reply_to_parent() for #{exp.fei.to_debug_s}" }
493
-
494
334
  workitem.last_expression_id = exp.fei
495
335
 
496
- onotify :reply_to_parent, exp, workitem
336
+ onotify(:reply_to_parent, exp, workitem)
497
337
 
498
338
  if remove
499
339
 
500
- remove exp
340
+ remove(exp)
501
341
  #
502
342
  # remove the expression itself
503
343
 
@@ -509,27 +349,29 @@ module OpenWFE
509
349
  #
510
350
  # manage tag, have to remove it so it can get 'redone' or 'undone'
511
351
  # (preventing abuse)
352
+ #
353
+ # do the same for the on_error handler if any
512
354
 
513
- tagname = exp.attributes["tag"] if exp.attributes
514
-
355
+ tagname = exp.attributes['tag']
515
356
  exp.delete_variable(tagname) if tagname
357
+ #exp.delete_variable(tagname) if tagname and not tagname.match(/^\//)
358
+
359
+ on_error = exp.attributes['on_error'] #if exp.attributes
360
+ exp.delete_variable(on_error) if on_error
516
361
 
517
362
  #
518
363
  # has raw_expression been updated ?
519
364
 
520
- track_child_raw_representation exp
365
+ track_child_raw_representation(exp)
521
366
 
522
367
  #
523
368
  # flow terminated ?
524
369
 
525
370
  if (not exp.parent_id) and (exp.fei.expid == '0')
526
371
 
527
- ldebug do
528
- "reply_to_parent() process " +
529
- "#{exp.fei.workflow_instance_id} terminated"
530
- end
372
+ ldebug { "reply_to_parent() process #{exp.fei.wfid} terminated" }
531
373
 
532
- onotify :terminate, exp, workitem
374
+ onotify(:terminate, exp, workitem)
533
375
 
534
376
  return
535
377
  end
@@ -537,21 +379,19 @@ module OpenWFE
537
379
  #
538
380
  # else, gone parent ?
539
381
 
540
- if (not exp.parent_id) or (exp.parent_id.expname == 'gone')
541
- # this 'gone' is kept for some level of 'backward compatibility'
382
+ #if (not exp.parent_id) or (exp.parent_id.expname == 'gone')
383
+ # # this 'gone' is kept for some level of 'backward compatibility'
542
384
 
543
- ldebug do
544
- "reply_to_parent() parent is gone for " +
545
- exp.fei.to_debug_s
546
- end
385
+ if (not exp.parent_id)
547
386
 
387
+ ldebug { "reply_to_parent() parent is gone for #{exp.fei.to_debug_s}"}
548
388
  return
549
389
  end
550
390
 
551
391
  #
552
392
  # parent still present, reply to it
553
393
 
554
- reply exp.parent_id, workitem
394
+ reply(exp.parent_id, workitem)
555
395
  end
556
396
 
557
397
  #
@@ -561,16 +401,9 @@ module OpenWFE
561
401
 
562
402
  flow_expression.updated_at = Time.now
563
403
 
564
- ldebug { "update() for #{flow_expression.fei.to_debug_s}" }
565
-
566
- #t = Timer.new
404
+ #ldebug { "update() for #{flow_expression.fei.to_debug_s}" }
567
405
 
568
- onotify :update, flow_expression.fei, flow_expression
569
-
570
- #ldebug do
571
- # "update() took #{t.duration} ms " +
572
- # "#{flow_expression.fei.to_debug_s}"
573
- #end
406
+ onotify(:update, flow_expression.fei, flow_expression)
574
407
 
575
408
  flow_expression
576
409
  end
@@ -583,29 +416,10 @@ module OpenWFE
583
416
  # has to be reloaded.
584
417
  #
585
418
  def fetch (exp)
586
- #synchronize do
587
-
588
- #ldebug { "fetch() exp is of kind #{exp.class}" }
589
-
590
- fei = if exp.is_a?(FlowExpression)
591
-
592
- exp.fei
593
-
594
- elsif not exp.is_a?(FlowExpressionId)
595
-
596
- raise \
597
- "Cannot fetch expression with key : "+
598
- "'#{fei}' (#{fei.class})"
599
419
 
600
- else
601
-
602
- exp
603
- end
604
-
605
- #ldebug { "fetch() for #{fei.to_debug_s}" }
420
+ fei = extract_fei(exp)
606
421
 
607
422
  [ get_expression_storage[fei], fei ]
608
- #end
609
423
  end
610
424
 
611
425
  #
@@ -616,20 +430,16 @@ module OpenWFE
616
430
  #
617
431
  def fetch_expression (exp)
618
432
 
619
- exp, fei = fetch exp
620
- exp
433
+ fetch(exp)[0]
621
434
  end
622
435
 
623
436
  #
624
437
  # Returns the engine environment (the top level environment)
625
438
  #
626
439
  def fetch_engine_environment
627
- #synchronize do
628
- #
629
- # synchronize to ensure that there's 1! engine env
630
440
 
631
441
  eei = engine_environment_id
632
- ee, fei = fetch eei
442
+ ee, fei = fetch(eei)
633
443
 
634
444
  return ee if ee
635
445
 
@@ -639,7 +449,6 @@ module OpenWFE
639
449
  ee.store_itself
640
450
 
641
451
  ee
642
- #end
643
452
  end
644
453
 
645
454
  #
@@ -647,7 +456,7 @@ module OpenWFE
647
456
  #
648
457
  def fetch_root (wfid)
649
458
 
650
- get_expression_storage.fetch_root wfid
459
+ get_expression_storage.fetch_root(wfid)
651
460
  end
652
461
 
653
462
  #
@@ -656,21 +465,15 @@ module OpenWFE
656
465
  #
657
466
  def remove (exp)
658
467
 
659
- exp, _fei = fetch(exp) \
660
- if exp.is_a?(FlowExpressionId)
468
+ exp, _fei = fetch(exp) if exp.is_a?(FlowExpressionId)
661
469
 
662
470
  return unless exp
663
471
 
664
- ldebug { "remove() fe #{exp.fei.to_debug_s}" }
472
+ #ldebug { "remove() fe #{exp.fei.to_debug_s}" }
665
473
 
666
- onotify :remove, exp.fei
474
+ onotify(:remove, exp.fei)
667
475
 
668
- #synchronize do
669
- #@monitors.delete(exp.fei)
670
-
671
- remove_environment(exp.environment_id) \
672
- if exp.owns_its_environment?
673
- #end
476
+ remove_environment(exp.environment_id) if exp.owns_its_environment?
674
477
  end
675
478
 
676
479
  #
@@ -684,7 +487,7 @@ module OpenWFE
684
487
 
685
488
  t = OpenWFE::Timer.new
686
489
 
687
- linfo { "reschedule() initiating..." }
490
+ linfo { 'reschedule() initiating...' }
688
491
 
689
492
  options = { :include_classes => Rufus::Schedulable }
690
493
 
@@ -692,9 +495,9 @@ module OpenWFE
692
495
 
693
496
  linfo { "reschedule() for #{fexp.fei.to_s}..." }
694
497
 
695
- onotify :reschedule, fexp.fei
498
+ onotify(:reschedule, fexp.fei)
696
499
 
697
- fexp.reschedule get_scheduler
500
+ fexp.reschedule(get_scheduler)
698
501
  end
699
502
 
700
503
  linfo { "reschedule() done. (took #{t.duration} ms)" }
@@ -706,26 +509,15 @@ module OpenWFE
706
509
  # 'singleton' method.
707
510
  #
708
511
  def engine_environment_id
709
- #synchronize do
710
- # no need, it's been already called at initialization
711
-
712
- return @eei if @eei
713
-
714
- @eei = FlowExpressionId.new
715
- @eei.owfe_version = OPENWFERU_VERSION
716
- @eei.engine_id = get_engine.engine_name
717
- @eei.initial_engine_id = @eei.engine_id
718
- @eei.workflow_definition_url = 'ee'
719
- @eei.workflow_definition_name = 'ee'
720
- @eei.workflow_definition_revision = '0'
721
- @eei.workflow_instance_id = '0'
722
- @eei.expression_name = EN_ENVIRONMENT
723
- @eei.expression_id = '0'
724
- @eei
725
- #end
512
+
513
+ @eei ||= new_fei(
514
+ :workflow_definition_url => 'ee',
515
+ :workflow_definition_name => 'ee',
516
+ :workflow_instance_id => '0',
517
+ :expression_name => EN_ENVIRONMENT)
726
518
  end
727
519
 
728
- #
520
+ #--
729
521
  # Returns the list of applied expressions belonging to a given
730
522
  # workflow instance.
731
523
  #
@@ -733,43 +525,30 @@ module OpenWFE
733
525
  # expressions (even those not yet applied) that compose the process
734
526
  # instance will be returned. Environments will be returned as well.
735
527
  #
736
- def process_stack (wfid, unapplied=false)
737
-
738
- #raise "please provide a non-nil workflow instance id" \
739
- # unless wfid
740
-
741
- wfid = extract_wfid wfid, true
742
-
743
- params = {
744
- #:exclude_classes => [ Environment, RawExpression ],
745
- #:exclude_classes => [ Environment ],
746
- :parent_wfid => wfid
747
- }
748
- params[:applied] = true if (not unapplied)
749
-
750
- stack = get_expression_storage.find_expressions params
751
-
752
- stack.extend(RepresentationMixin) if unapplied
753
-
754
- stack
755
- end
528
+ #def process_stack (wfid)
529
+ # wfid = extract_wfid(wfid, true)
530
+ # params = { :parent_wfid => wfid }
531
+ # stack = get_expression_storage.find_expressions(params)
532
+ # stack.extend(RepresentationMixin)
533
+ # stack
534
+ #end
535
+ #++
756
536
 
757
- #
537
+ #--
758
538
  # Lists all workflows (processes) currently in the expool (in
759
539
  # the engine).
760
540
  # This method will return a list of "process-definition" expressions
761
541
  # (root of flows).
762
542
  #
763
- def list_processes (options={})
764
-
765
- options[:include_classes] = DefineExpression
766
- #
767
- # Maybe it would be better to list root expressions instead
768
- # so that expressions like 'sequence' can be used
769
- # as root expressions. Later...
770
-
771
- get_expression_storage.find_expressions options
772
- end
543
+ #def list_processes (options={})
544
+ # options[:include_classes] = DefineExpression
545
+ # #
546
+ # # Maybe it would be better to list root expressions instead
547
+ # # so that expressions like 'sequence' can be used
548
+ # # as root expressions. Later...
549
+ # get_expression_storage.find_expressions(options)
550
+ #end
551
+ #++
773
552
 
774
553
  #
775
554
  # This method is called when apply() or reply() failed for
@@ -778,15 +557,12 @@ module OpenWFE
778
557
  # class and the do_process_workelement method of this ExpressionPool
779
558
  # class.
780
559
  #
781
- def notify_error (error, fei, message, workitem)
782
-
783
- fei = extract_fei fei
784
- # densha requires that... :(
785
-
786
- se = OpenWFE::exception_to_s error
560
+ # Error handling is done here, if no handler was found, the error simply
561
+ # generate a notification (generally caught by an error journal).
562
+ #
563
+ def handle_error (error, fei, message, workitem)
787
564
 
788
- #onotify :error, fei, message, workitem, error.class.name, se
789
- onotify(:error, fei, message, workitem, error.class.name, error.to_s)
565
+ fei = extract_fei(fei) # just to be sure
790
566
 
791
567
  if error.is_a?(PausedError)
792
568
  lwarn do
@@ -798,21 +574,14 @@ module OpenWFE
798
574
  lwarn do
799
575
  "#{self.service_name} " +
800
576
  "operation :#{message.to_s} on #{fei.to_s} " +
801
- "failed with\n" + se
577
+ "failed with\n" + OpenWFE::exception_to_s(error)
802
578
  end
803
579
  end
804
- end
805
580
 
806
- #
807
- # Gets the process definition (if necessary) and turns into
808
- # into an expression tree (for storing into a RawExpression).
809
- #
810
- def determine_rep (param)
581
+ # notify or really handle ?
811
582
 
812
- param = read_uri(param) if param.is_a?(URI)
813
-
814
- #DefParser.parse param
815
- get_def_parser.parse param
583
+ do_handle_error(fei, workitem) ||
584
+ onotify(:error, fei, message, workitem, error.class.name, error.to_s)
816
585
  end
817
586
 
818
587
  #
@@ -824,313 +593,348 @@ module OpenWFE
824
593
  (@paused_instances[expression.fei.parent_wfid] != nil)
825
594
  end
826
595
 
827
- protected
596
+ #
597
+ # Builds the RawExpression instance at the root of the flow
598
+ # being launched.
599
+ #
600
+ # The param can be a template or a definition (or a URI).
601
+ #
602
+ def build_raw_expression (param, launchitem=nil)
828
603
 
829
- #
830
- # If the launch option :wait_for is set to true, this method
831
- # will be called to apply the raw_expression. It will only return
832
- # when the launched process is over, which means it terminated, it
833
- # had an error or it got cancelled.
834
- #
835
- def wait_for (fei_or_wfid)
604
+ procdef = get_def_parser.determine_rep(param)
836
605
 
837
- wfid = extract_wfid fei_or_wfid, false
606
+ # procdef is a nested [ name, attributes, children ] structure now
838
607
 
839
- t = Thread.current
840
- result = nil
608
+ atts = procdef[1]
841
609
 
842
- to = get_expression_pool.add_observer(:terminate) do |c, fe, wi|
843
- if fe.fei.workflow_instance_id == wfid
844
- result = [ :terminate, wi, fei_or_wfid ]
845
- t.wakeup
846
- end
610
+ h = {
611
+ :workflow_instance_id =>
612
+ get_wfid_generator.generate(launchitem),
613
+ :workflow_definition_name =>
614
+ atts['name'] || procdef[2].first || 'no-name',
615
+ :workflow_definition_revision =>
616
+ atts['revision'] || '0',
617
+ :expression_name =>
618
+ procdef[0]
619
+ }
620
+
621
+ h[:workflow_definition_url] = (
622
+ launchitem.workflow_definition_url || LaunchItem::FIELD_DEF
623
+ ) if launchitem
624
+
625
+ RawExpression.new_raw(
626
+ new_fei(h), nil, nil, @application_context, procdef)
627
+ end
628
+
629
+ #
630
+ # If the launch option :wait_for is set to true, this method
631
+ # will be called to apply the raw_expression. It will only return
632
+ # when the launched process is over, which means it terminated, it
633
+ # had an error or it got cancelled.
634
+ #
635
+ def wait_for (fei_or_wfid)
636
+
637
+ wfid = extract_wfid(fei_or_wfid, false)
638
+
639
+ t = Thread.current
640
+ result = nil
641
+
642
+ to = add_observer(:terminate) do |c, fe, wi|
643
+ if fe.fei.wfid == wfid
644
+ result = [ :terminate, wi, fei_or_wfid ]
645
+ t.wakeup
847
646
  end
848
- te = get_expression_pool.add_observer(:error) do |c, fei, m, i, e|
849
- if fei.parent_wfid == wfid
850
- result = [ :error, e, fei_or_wfid ]
851
- t.wakeup
852
- end
647
+ end
648
+ te = add_observer(:error) do |c, fei, m, i, e|
649
+ if fei.parent_wfid == wfid
650
+ result = [ :error, e, fei_or_wfid ]
651
+ t.wakeup
853
652
  end
854
- tc = get_expression_pool.add_observer(:cancel) do |c, fe|
855
- if fe.fei.wfid == wfid and fe.fei.expid == '0'
856
- result = [ :cancel, wfid, fei_or_wfid ]
857
- t.wakeup
858
- end
653
+ end
654
+ tc = add_observer(:cancel) do |c, fe|
655
+ if fe.fei.wfid == wfid and fe.fei.expid == '0'
656
+ result = [ :cancel, wfid, fei_or_wfid ]
657
+ t.wakeup
859
658
  end
659
+ end
860
660
 
861
- #apply raw_expression, wi
862
- yield if block_given?
661
+ yield if block_given?
863
662
 
864
- Thread.stop unless result
663
+ Thread.stop unless result
865
664
 
866
- linfo { "wait_for() '#{wfid}' is over" }
665
+ linfo { "wait_for() '#{wfid}' is over" }
867
666
 
868
- get_expression_pool.remove_observer to, :terminate
869
- get_expression_pool.remove_observer te, :error
870
- get_expression_pool.remove_observer tc, :cancel
667
+ remove_observer(to, :terminate)
668
+ remove_observer(te, :error)
669
+ remove_observer(tc, :cancel)
871
670
 
872
- result
873
- end
671
+ result
672
+ end
874
673
 
875
- #
876
- # This is the only point in the expression pool where an URI
877
- # is read, so this is where the :remote_definitions_allowed
878
- # security check is enforced.
879
- #
880
- def read_uri (uri)
674
+ protected
675
+
676
+ #
677
+ # Checks if there is an event handler available
678
+ #
679
+ def do_handle_error (fei, workitem)
881
680
 
882
- uri = URI.parse uri.to_s
681
+ fexp = fetch_expression(fei)
883
682
 
884
- raise ":remote_definitions_allowed is set to false" \
885
- if (ac[:remote_definitions_allowed] != true and
886
- uri.scheme and
887
- uri.scheme != 'file')
683
+ eh_stack = fexp.lookup_variable_stack('error_handlers')
888
684
 
889
- #open(uri.to_s).read
685
+ return false if eh_stack.empty?
890
686
 
891
- f = Rufus::Verbs.fopen uri
892
- result = f.read
893
- f.close if f.respond_to?(:close)
687
+ eh_stack.each do |env, ehandlers|
688
+ ehandlers.reverse.each do |ehandler|
894
689
 
895
- result
896
- end
690
+ fei, on_error = ehandler
897
691
 
898
- #
899
- # This is the method called [asynchronously] by the WorkQueue
900
- # upon apply/reply.
901
- #
902
- def do_apply_reply (direction, exp_or_fei, workitem)
692
+ next unless fexp.descendant_of?(fei)
903
693
 
904
- fei = nil
694
+ return false if on_error == ''
695
+ #
696
+ # blanking the 'on_error' makes the block behave like if there
697
+ # were no error handler at all (error is then passed to error
698
+ # journal usually (if there is one listening))
905
699
 
906
- begin
700
+ tryexp = fetch_expression(fei)
907
701
 
908
- exp, fei = if exp_or_fei.is_a?(FlowExpressionId)
909
- fetch exp_or_fei
910
- else
911
- [ exp_or_fei, exp_or_fei.fei ]
912
- end
702
+ # remove error handler before consuming it
913
703
 
914
- #p [ direction, fei.wfid, fei.expid, fei.expname ]
915
- #
916
- # I uncomment that sometimes to see how the stack
917
- # grows (wfids and expids)
704
+ ehandlers.delete(ehandler)
705
+ env.store_itself
918
706
 
919
- ldebug {
920
- ":#{direction} "+
921
- "target #{fei.to_debug_s}" }
707
+ # fetch on_error template
922
708
 
923
- if not exp
709
+ template = (on_error == 'redo') ?
710
+ tryexp.raw_representation :
711
+ tryexp.lookup_variable(on_error) || [ on_error, {}, [] ]
924
712
 
925
- #raise "apply() cannot apply missing #{_fei.to_debug_s}"
926
- # not very helpful anyway
713
+ # cancel block that is adorned with 'on_error'
927
714
 
928
- lwarn { "do_apply_reply() cannot find >#{fei}" }
715
+ environment = tryexp.owns_its_environment? ?
716
+ tryexp.get_environment : nil
929
717
 
930
- return
931
- end
718
+ cancel(tryexp)
932
719
 
933
- check_if_paused exp
720
+ ldebug { "do_handle_error() on_error : '#{on_error}'" }
934
721
 
935
- workitem.fei = exp.fei if direction == :apply
722
+ if on_error == 'undo'
723
+ #
724
+ # block with 'undo' error handler simply gets undone in case of
725
+ # error
726
+ #
727
+ reply_to_parent(tryexp, workitem, false)
728
+ return true
729
+ end
936
730
 
937
- onotify direction, exp, workitem
731
+ # switch to error handling subprocess
938
732
 
939
- exp.send direction, workitem
733
+ environment.store_itself if environment
734
+ #
735
+ # the point of error had variables, make sure they are available
736
+ # to the error handling block.
940
737
 
941
- rescue Exception => e
738
+ substitute_and_apply(tryexp, template, workitem)
942
739
 
943
- notify_error e, fei, direction, workitem
740
+ return true
944
741
  end
945
742
  end
946
743
 
947
- #
948
- # Will raise an exception if the expression belongs to a paused
949
- # process.
950
- #
951
- def check_if_paused (expression)
744
+ false # no error handler found
745
+ end
952
746
 
953
- wfid = expression.fei.parent_wfid
747
+ #
748
+ # This is the method called [asynchronously] by the WorkQueue
749
+ # upon apply/reply.
750
+ #
751
+ def do_apply_reply (direction, exp_or_fei, workitem)
954
752
 
955
- raise PausedError.new(wfid) if @paused_instances[wfid]
956
- end
753
+ fei = nil
957
754
 
958
- #
959
- # if the launch method is called with a schedule option
960
- # (like :at, :in, :cron and :every), this method takes care of
961
- # wrapping the process with a sleep or a cron.
962
- #
963
- def wrap_in_schedule (raw_expression, options)
755
+ begin
964
756
 
965
- oat = options[:at]
966
- oin = options[:in]
967
- ocron = options[:cron]
968
- oevery = options[:every]
757
+ exp, fei = if exp_or_fei.is_a?(FlowExpressionId)
758
+ fetch(exp_or_fei)
759
+ else
760
+ [ exp_or_fei, exp_or_fei.fei ]
761
+ end
969
762
 
970
- fei = new_fei nil, "schedlaunch", "0", "sequence"
763
+ #p [ direction, fei.wfid, fei.expid, fei.expname ]
764
+ #
765
+ # I uncomment that sometimes to see how the stack
766
+ # grows (wfids and expids)
971
767
 
972
- # not very happy with this code, it builds custom
973
- # wrapping processes manually, maybe there is
974
- # a more elegant way, but for now, it's ok.
768
+ if not exp
975
769
 
976
- template = if oat or oin
770
+ #raise "apply() cannot apply missing #{_fei.to_debug_s}"
771
+ # not very helpful anyway
977
772
 
978
- sleep_atts = if oat
979
- { "until" => oat }
980
- else #oin
981
- { "for" => oin }
982
- end
983
- sleep_atts["scheduler-tags"] = "scheduled-launch, #{fei.wfid}"
773
+ lwarn { "do_apply_reply() :#{direction} but cannot find #{fei}" }
984
774
 
985
- raw_expression.new_environment
986
- raw_expression.store_itself
775
+ return
776
+ end
987
777
 
988
- [
989
- "sequence", {}, [
990
- [ "sleep", sleep_atts, [] ],
991
- raw_expression.fei
992
- ]
993
- ]
778
+ check_if_paused(exp)
994
779
 
995
- elsif ocron or oevery
780
+ workitem.fei = exp.fei if direction == :apply
996
781
 
997
- fei.expression_name = "cron"
782
+ onotify(direction, exp, workitem)
998
783
 
999
- cron_atts = if ocron
1000
- { "tab" => ocron }
1001
- else #oevery
1002
- { "every" => oevery }
1003
- end
1004
- cron_atts["name"] = "//cron_launch__#{fei.wfid}"
1005
- cron_atts["scheduler-tags"] = "scheduled-launch, #{fei.wfid}"
784
+ exp.send(direction, workitem)
1006
785
 
1007
- template = raw_expression.raw_representation
1008
- remove raw_expression
786
+ rescue Exception => e
1009
787
 
1010
- [ "cron", cron_atts, [ template ] ]
788
+ handle_error(e, fei, direction, workitem)
789
+ end
790
+ end
1011
791
 
1012
- else
792
+ #
793
+ # Will raise an exception if the expression belongs to a paused
794
+ # process.
795
+ #
796
+ def check_if_paused (expression)
1013
797
 
1014
- nil # don't schedule at all
1015
- end
798
+ wfid = expression.fei.parent_wfid
799
+
800
+ raise PausedError.new(wfid) if @paused_instances[wfid]
801
+ end
802
+
803
+ #
804
+ # if the launch method is called with a schedule option
805
+ # (like :at, :in, :cron and :every), this method takes care of
806
+ # wrapping the process with a sleep or a cron.
807
+ #
808
+ def wrap_in_schedule (raw_expression, options)
1016
809
 
1017
- if template
810
+ oat = options[:at]
811
+ oin = options[:in]
812
+ ocron = options[:cron]
813
+ oevery = options[:every]
1018
814
 
1019
- raw_exp = RawExpression.new_raw(
1020
- fei, nil, nil, @application_context, template)
815
+ fei = new_fei(
816
+ :workflow_instance_id => get_wfid_generator.generate(nil),
817
+ :workflow_definition_name => 'schedlaunch',
818
+ :expression_name => 'sequence')
1021
819
 
1022
- raw_exp.store_itself
820
+ # not very happy with this code, it builds custom
821
+ # wrapping processes manually, maybe there is
822
+ # a more elegant way, but for now, it's ok.
1023
823
 
1024
- raw_exp
1025
- else
824
+ template = if oat or oin
1026
825
 
1027
- raw_expression
826
+ sleep_atts = if oat
827
+ { 'until' => oat }
828
+ else #oin
829
+ { 'for' => oin }
1028
830
  end
1029
- end
831
+ sleep_atts['scheduler-tags'] = "scheduled-launch, #{fei.wfid}"
1030
832
 
1031
- #
1032
- # Removes an environment, especially takes care of unbinding
1033
- # any special value it may contain.
1034
- #
1035
- def remove_environment (environment_id)
833
+ raw_expression.new_environment
834
+ raw_expression.store_itself
1036
835
 
1037
- ldebug { "remove_environment() #{environment_id.to_debug_s}" }
836
+ [
837
+ 'sequence', {}, [
838
+ [ 'sleep', sleep_atts, [] ],
839
+ raw_expression.fei
840
+ ]
841
+ ]
1038
842
 
1039
- env, fei = fetch(environment_id)
843
+ elsif ocron or oevery
1040
844
 
1041
- return unless env
1042
- #
1043
- # env already unbound and removed
845
+ fei.expression_name = 'cron'
1044
846
 
1045
- env.unbind
847
+ cron_atts = if ocron
848
+ { 'tab' => ocron }
849
+ else #oevery
850
+ { 'every' => oevery }
851
+ end
852
+ cron_atts['name'] = "//cron_launch__#{fei.wfid}"
853
+ cron_atts['scheduler-tags'] = "scheduled-launch, #{fei.wfid}"
854
+
855
+ template = raw_expression.raw_representation
856
+ remove(raw_expression)
1046
857
 
1047
- #get_expression_storage().delete(environment_id)
858
+ [ 'cron', cron_atts, [ template ] ]
859
+
860
+ else
1048
861
 
1049
- onotify :remove, environment_id
862
+ nil # don't schedule at all
1050
863
  end
1051
864
 
1052
- #
1053
- # Prepares a new instance of InFlowWorkItem from a LaunchItem
1054
- # instance.
1055
- #
1056
- def build_workitem (launchitem)
865
+ if template
1057
866
 
1058
- wi = InFlowWorkItem.new
867
+ raw_exp = RawExpression.new_raw(
868
+ fei, nil, nil, @application_context, template)
1059
869
 
1060
- wi.attributes = launchitem.attributes.dup
870
+ #raw_exp.store_itself
871
+ raw_exp.new_environment
872
+
873
+ raw_exp
874
+ else
1061
875
 
1062
- wi
876
+ raw_expression
1063
877
  end
878
+ end
1064
879
 
1065
- #
1066
- # Builds a FlowExpressionId instance for a process being
1067
- # launched.
1068
- #
1069
- def new_fei (launchitem, flow_name, flow_revision, exp_name)
880
+ #
881
+ # Removes an environment, especially takes care of unbinding
882
+ # any special value it may contain.
883
+ #
884
+ def remove_environment (environment_id)
1070
885
 
1071
- url = if launchitem
1072
- launchitem.workflow_definition_url
1073
- else
1074
- "no-url"
1075
- end
886
+ #ldebug { "remove_environment() #{environment_id.to_debug_s}" }
1076
887
 
1077
- fei = FlowExpressionId.new
888
+ env, fei = fetch(environment_id)
1078
889
 
1079
- fei.owfe_version = OPENWFERU_VERSION
1080
- fei.engine_id = OpenWFE::stu get_engine.service_name.to_s
1081
- fei.initial_engine_id = OpenWFE::stu fei.engine_id
1082
- fei.workflow_definition_url = OpenWFE::stu url
1083
- fei.workflow_definition_name = OpenWFE::stu flow_name
1084
- fei.workflow_definition_revision = OpenWFE::stu flow_revision
1085
- fei.wfid = get_wfid_generator.generate launchitem
1086
- fei.expression_id = "0"
1087
- fei.expression_name = exp_name
890
+ return unless env
891
+ #
892
+ # env already unbound and removed
1088
893
 
1089
- fei
1090
- end
894
+ env.unbind
1091
895
 
1092
- #
1093
- # Builds the RawExpression instance at the root of the flow
1094
- # being launched.
1095
- #
1096
- # The param can be a template or a definition (anything
1097
- # accepted by the determine_representation() method).
1098
- #
1099
- def build_raw_expression (launchitem, param)
896
+ onotify(:remove, environment_id)
897
+ end
1100
898
 
1101
- procdef = determine_rep param
899
+ #
900
+ # Builds a FlowExpressionId instance for a process being
901
+ # launched.
902
+ #
903
+ def new_fei (h)
1102
904
 
1103
- atts = procdef[1]
1104
- flow_name = atts['name'] || "noname"
1105
- flow_revision = atts['revision'] || "0"
1106
- exp_name = procdef.first
905
+ h[:engine_id] = OpenWFE::stu(get_engine.engine_name)
1107
906
 
1108
- fei = new_fei launchitem, flow_name, flow_revision, exp_name
907
+ %w{ url name revision }.each { |k| stu(h, k) }
1109
908
 
1110
- RawExpression.new_raw(
1111
- fei, nil, nil, @application_context, procdef)
1112
- end
909
+ FlowExpressionId.new_fei(h)
910
+ end
1113
911
 
1114
- #
1115
- # Given a [replying] child flow expression, will update its parent
1116
- # raw expression if the child raw_expression changed.
1117
- #
1118
- # This is used to keep track of in-flight modification to running
1119
- # process instances.
1120
- #
1121
- def track_child_raw_representation (fexp)
912
+ def stu (h, key)
1122
913
 
1123
- return unless fexp.raw_rep_updated == true
914
+ key = "workflow_definition_#{key}".intern
915
+ v = h[key]
916
+ h[key] = OpenWFE::stu(v.to_s) if v
917
+ end
918
+
919
+ #
920
+ # Given a [replying] child flow expression, will update its parent
921
+ # raw expression if the child raw_expression changed.
922
+ #
923
+ # This is used to keep track of in-flight modification to running
924
+ # process instances.
925
+ #
926
+ def track_child_raw_representation (fexp)
1124
927
 
1125
- parent = fetch_expression fexp.parent_id
928
+ return unless fexp.raw_rep_updated == true
1126
929
 
1127
- return if parent.class.uses_template?
930
+ parent = fetch_expression(fexp.parent_id)
1128
931
 
1129
- parent.raw_children[fexp.fei.child_id.to_i] =
1130
- fexp.raw_representation
932
+ #p [ :storing, fexp.raw_representation, fexp.fei.to_short_s ]
1131
933
 
1132
- parent.store_itself
1133
- end
934
+ parent.raw_children[fexp.fei.child_id.to_i] = fexp.raw_representation
935
+
936
+ parent.store_itself
937
+ end
1134
938
  end
1135
939
 
1136
940
  end