flor 0.0.1 → 0.9.0

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 (84) hide show
  1. data/CHANGELOG.md +13 -0
  2. data/LICENSE.txt +1 -1
  3. data/Makefile +66 -0
  4. data/README.md +57 -0
  5. data/fail.txt +7 -0
  6. data/flor.gemspec +12 -9
  7. data/intercepted.txt +123 -0
  8. data/lib/flor/colours.rb +140 -0
  9. data/lib/flor/conf.rb +88 -0
  10. data/lib/flor/core/executor.rb +473 -0
  11. data/lib/flor/core/node.rb +397 -0
  12. data/lib/flor/core/procedure.rb +600 -0
  13. data/lib/flor/core/texecutor.rb +209 -0
  14. data/lib/flor/core.rb +93 -0
  15. data/lib/flor/dollar.rb +248 -0
  16. data/lib/flor/errors.rb +36 -0
  17. data/lib/flor/flor.rb +556 -0
  18. data/lib/flor/log.rb +336 -0
  19. data/lib/flor/migrations/0001_tables.rb +122 -0
  20. data/lib/flor/parser.rb +414 -0
  21. data/lib/flor/pcore/_arr.rb +49 -0
  22. data/lib/flor/pcore/_atom.rb +43 -0
  23. data/lib/flor/pcore/_att.rb +160 -0
  24. data/lib/flor/pcore/_dump.rb +60 -0
  25. data/lib/flor/pcore/_err.rb +30 -0
  26. data/lib/flor/pcore/_happly.rb +73 -0
  27. data/lib/flor/pcore/_obj.rb +65 -0
  28. data/lib/flor/pcore/_skip.rb +63 -0
  29. data/lib/flor/pcore/apply.rb +60 -0
  30. data/lib/flor/pcore/arith.rb +46 -0
  31. data/lib/flor/pcore/break.rb +71 -0
  32. data/lib/flor/pcore/cmp.rb +72 -0
  33. data/lib/flor/pcore/cond.rb +57 -0
  34. data/lib/flor/pcore/cursor.rb +223 -0
  35. data/lib/flor/pcore/define.rb +96 -0
  36. data/lib/flor/pcore/fail.rb +45 -0
  37. data/lib/flor/pcore/ife.rb +56 -0
  38. data/lib/flor/pcore/loop.rb +53 -0
  39. data/lib/flor/pcore/map.rb +75 -0
  40. data/lib/flor/pcore/match.rb +70 -0
  41. data/lib/flor/pcore/move.rb +65 -0
  42. data/lib/flor/pcore/noeval.rb +46 -0
  43. data/lib/flor/pcore/noret.rb +47 -0
  44. data/lib/flor/pcore/push.rb +69 -0
  45. data/lib/flor/pcore/sequence.rb +39 -0
  46. data/lib/flor/pcore/set.rb +76 -0
  47. data/lib/flor/pcore/stall.rb +35 -0
  48. data/lib/flor/pcore/until.rb +122 -0
  49. data/lib/flor/pcore/val.rb +40 -0
  50. data/lib/flor/punit/cancel.rb +69 -0
  51. data/lib/flor/punit/cmap.rb +76 -0
  52. data/lib/flor/punit/concurrence.rb +149 -0
  53. data/lib/flor/punit/every.rb +46 -0
  54. data/lib/flor/punit/on.rb +81 -0
  55. data/lib/flor/punit/schedule.rb +68 -0
  56. data/lib/flor/punit/signal.rb +47 -0
  57. data/lib/flor/punit/sleep.rb +53 -0
  58. data/lib/flor/punit/task.rb +109 -0
  59. data/lib/flor/punit/trace.rb +51 -0
  60. data/lib/flor/punit/trap.rb +100 -0
  61. data/lib/flor/to_string.rb +81 -0
  62. data/lib/flor/tools/env.rb +103 -0
  63. data/lib/flor/tools/repl.rb +231 -0
  64. data/lib/flor/unit/executor.rb +260 -0
  65. data/lib/flor/unit/hooker.rb +186 -0
  66. data/lib/flor/unit/journal.rb +52 -0
  67. data/lib/flor/unit/loader.rb +181 -0
  68. data/lib/flor/unit/logger.rb +181 -0
  69. data/lib/flor/unit/models/execution.rb +105 -0
  70. data/lib/flor/unit/models/pointer.rb +31 -0
  71. data/lib/flor/unit/models/timer.rb +52 -0
  72. data/lib/flor/unit/models/trace.rb +31 -0
  73. data/lib/flor/unit/models/trap.rb +130 -0
  74. data/lib/flor/unit/models.rb +106 -0
  75. data/lib/flor/unit/scheduler.rb +419 -0
  76. data/lib/flor/unit/storage.rb +633 -0
  77. data/lib/flor/unit/tasker.rb +191 -0
  78. data/lib/flor/unit/waiter.rb +146 -0
  79. data/lib/flor/unit/wlist.rb +77 -0
  80. data/lib/flor/unit.rb +50 -0
  81. data/lib/flor.rb +40 -3
  82. metadata +152 -22
  83. checksums.yaml +0 -7
  84. data/Rakefile +0 -52
@@ -0,0 +1,149 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Concurrence < Flor::Procedure
27
+
28
+ name 'concurrence'
29
+
30
+ def pre_execute
31
+
32
+ @node['atts'] = []
33
+ end
34
+
35
+ def receive_last_att
36
+
37
+ return reply unless children[@ncid]
38
+
39
+ (@ncid..children.size - 1)
40
+ .map { |i| execute_child(i, 0, 'payload' => payload.copy_current) }
41
+ .flatten(1)
42
+ #
43
+ # call execute for each of the (non _att) children
44
+ end
45
+
46
+ def receive_non_att
47
+
48
+ @node['receiver'] ||= determine_receiver
49
+ @node['merger'] ||= determine_merger
50
+
51
+ (@node['cnodes'] || []).delete(from)
52
+
53
+ return [] if @node['over']
54
+
55
+ over = invoke_receiver
56
+ # true: the concurrence is over, false: the concurrence is still waiting
57
+
58
+ return [] unless over
59
+
60
+ @node['over'] = true
61
+
62
+ pld = invoke_merger
63
+ # determine post-concurrence payload
64
+
65
+ cancel_remaining +
66
+ reply('payload' => pld)
67
+ end
68
+
69
+ def receive_from_child_when_closed
70
+
71
+ ms = receive
72
+
73
+ return [] if ms.empty?
74
+
75
+ pop_on_receive_last || ms
76
+ end
77
+
78
+ protected
79
+
80
+ def determine_receiver
81
+
82
+ ex = att(:expect)
83
+
84
+ return 'expect_integer_receive' if ex && ex.is_a?(Integer) && ex > 0
85
+
86
+ 'default_receive'
87
+ end
88
+
89
+ def determine_merger
90
+
91
+ 'default_merge'
92
+ end
93
+
94
+ def cancel_remaining
95
+
96
+ # remaining:
97
+ # * 'cancel' (default)
98
+ # * 'forget'
99
+ # * 'wait'
100
+
101
+ rem = att(:remaining, :rem)
102
+
103
+ return [] if rem == 'forget'
104
+
105
+ cancel_nodes(@node['cnodes'])
106
+ end
107
+
108
+ def invoke_receiver
109
+
110
+ # TODO: receiver function case
111
+
112
+ self.send(@node['receiver'])
113
+ end
114
+
115
+ def invoke_merger
116
+
117
+ # TODO: merger function case
118
+
119
+ self.send(@node['merger'])
120
+ end
121
+
122
+ def store_payload
123
+
124
+ (@node['payloads'] ||= {})[@message['from']] =
125
+ @message['payload']
126
+ end
127
+
128
+ def default_receive
129
+
130
+ store_payload
131
+
132
+ @node['payloads'].size >= non_att_children.size
133
+ end
134
+
135
+ def expect_integer_receive
136
+
137
+ store_payload
138
+
139
+ @node['payloads'].size >= att(:expect)
140
+ end
141
+
142
+ def default_merge
143
+
144
+ @node['payloads'].values
145
+ .reverse
146
+ .inject({}) { |h, pl| h.merge!(pl) }
147
+ end
148
+ end
149
+
@@ -0,0 +1,46 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Every < Flor::Macro
27
+
28
+ name 'every'
29
+
30
+ def rewrite_tree
31
+
32
+ l = tree[2]
33
+
34
+ th = [ 'schedule', [], l, *tree[3] ]
35
+ att_children.each { |ac| th[1] << Flor.dup(ac) }
36
+
37
+ td = [ 'def', [], l ]
38
+ td[1] << [ '_att', [ [ 'msg', [], l ] ], l ]
39
+ non_att_children.each { |nac| td[1] << Flor.dup(nac) }
40
+
41
+ th[1] << td
42
+
43
+ th
44
+ end
45
+ end
46
+
@@ -0,0 +1,81 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::On < Flor::Macro
27
+ #
28
+ # Traps a signal by name
29
+ #
30
+ # Turns
31
+ # ```
32
+ # on 'approve'
33
+ # task 'bob' mission: 'gather signatures'
34
+ # ```
35
+ # into
36
+ # ```
37
+ # trap point: 'signal', name: 'approve'
38
+ # set sig 'signal'
39
+ # def msg
40
+ # task 'bob' mission: 'gather signatures'
41
+ # ```
42
+ #
43
+
44
+ name 'on'
45
+
46
+ def rewrite_tree
47
+
48
+ atts = att_children
49
+ signame_i = atts.index { |at| at[1].size == 1 }
50
+
51
+ fail ArgumentError.new(
52
+ "signal name not found in #{tree.inspect}"
53
+ ) unless signame_i
54
+
55
+ tname = atts[signame_i]
56
+ tname = Flor.dup(tname[1][0])
57
+ atts.delete_at(signame_i)
58
+
59
+ l = tree[2]
60
+
61
+ th = [ 'trap', [], l, *tree[3] ]
62
+ th[1] << [ '_att', [ [ 'point', [], l ], [ '_sqs', 'signal', l ] ], l ]
63
+ th[1] << [ '_att', [ [ 'name', [], l ], tname ], l ]
64
+ th[1] << [ '_att', [ [ 'payload', [], l ], [ '_sqs', 'event', l ] ], l ]
65
+ atts.each { |ac| th[1] << Flor.dup(ac) }
66
+
67
+ th[1] << [ 'set', [
68
+ [ '_att', [ [ 'sig', [], l ] ], l ],
69
+ tname
70
+ ], l ]
71
+
72
+ td = [ 'def', [], l ]
73
+ td[1] << [ '_att', [ [ 'msg', [], l ] ], l ]
74
+ non_att_children.each { |nac| td[1] << Flor.dup(nac) }
75
+
76
+ th[1] << td
77
+
78
+ th
79
+ end
80
+ end
81
+
@@ -0,0 +1,68 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Schedule < Flor::Procedure
27
+ #
28
+ # Schedules a function
29
+ #
30
+ # ```
31
+ # schedule cron: '0 0 1 jan *' # every 1st day of the year, check systems
32
+ # def msg
33
+ # check_systems
34
+ # ```
35
+ #
36
+ # See also: cron, at, in and sleep
37
+
38
+ name 'schedule'
39
+
40
+ def pre_execute
41
+
42
+ @node['atts'] = []
43
+ end
44
+
45
+ def receive_last
46
+
47
+ fun = @fcid > 0 ? payload['ret'] : nil
48
+
49
+ fail ArgumentError.new(
50
+ "missing a function to call when the scheduler triggers"
51
+ ) unless fun
52
+
53
+ msg = apply(fun, [], tree[2], false).first.merge('noreply' => true)
54
+
55
+ type, string =
56
+ @node['atts'].find { |k, v| %w[ cron at in every ].include?(k) } ||
57
+ @node['atts'].find { |k, v| k == nil }
58
+
59
+ fail ArgumentError.new(
60
+ "missing a schedule"
61
+ ) unless string
62
+
63
+ #m = reply('point' => 'receive').first
64
+
65
+ schedule('type' => type, 'string' => string, 'message' => msg)
66
+ end
67
+ end
68
+
@@ -0,0 +1,47 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Signal < Flor::Procedure
27
+
28
+ name 'signal'
29
+
30
+ def pre_execute
31
+
32
+ @node['atts'] = []
33
+ end
34
+
35
+ def receive_last
36
+
37
+ name = att('name', nil)
38
+
39
+ return super unless name
40
+
41
+ reply(
42
+ 'point' => 'signal', 'nid' => nid, 'name' => name,
43
+ 'payload' => payload.copy_current
44
+ ) + super
45
+ end
46
+ end
47
+
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Sleep < Flor::Procedure
27
+ #
28
+ # Makes a branch of an execution sleep for a while.
29
+ #
30
+ # ```
31
+ # sleep '1y' # sleep for one year
32
+ # sleep for: '2y' # sleep for two years, with an explicit for:
33
+ # sleep '2d1m10s' # sleep for two days, one minute and ten seconds
34
+ # ```
35
+
36
+ name 'sleep'
37
+
38
+ def pre_execute
39
+
40
+ @node['atts'] = []
41
+ end
42
+
43
+ def receive_last
44
+
45
+ t = att('for', nil)
46
+ fail ArgumentError.new("missing a sleep time duration") unless t
47
+
48
+ m = reply('point' => 'receive').first
49
+
50
+ schedule('type' => 'in', 'string' => t, 'message' => m)
51
+ end
52
+ end
53
+
@@ -0,0 +1,109 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Task < Flor::Procedure
27
+
28
+ name 'task'
29
+
30
+ def pre_execute
31
+
32
+ @node['atts'] = []
33
+ end
34
+
35
+ def do_receive
36
+
37
+ return reply('payload' => determine_reply_payload) \
38
+ if point == 'receive' && from == nil
39
+
40
+ super
41
+ # which goes to #receive or #receive_when_status
42
+ end
43
+
44
+ def receive_last_att
45
+
46
+ # task 'clean up' by: 'alan'
47
+ # task 'clean up' for: 'alan'
48
+ # task 'clean up' assign: 'alan'
49
+ # task 'alan' with: 'clean up'
50
+ # clean_up assign: 'alan'
51
+ # "clean up" assign: 'alan'
52
+ # alan task: 'clean up'
53
+
54
+ #@executor.unit.tasker.has_tasker?(@executor.exid, key)
55
+
56
+ ni = att(nil)
57
+ ta = att('by', 'for', 'assign')
58
+ tn = att('with', 'task')
59
+
60
+ tasker = ta || ni
61
+
62
+ taskname = tn || ni
63
+ taskname = nil if ta == nil && tasker == ni
64
+
65
+ attl, attd = determine_atts
66
+
67
+ queue(
68
+ 'point' => 'task',
69
+ 'exid' => exid, 'nid' => nid,
70
+ 'tasker' => tasker,
71
+ 'taskname' => taskname,
72
+ 'attl' => attl, 'attd' => attd,
73
+ 'payload' => determine_payload)
74
+ #.tap { |x| pp x.first }
75
+ end
76
+
77
+ def cancel
78
+
79
+ attl, attd = determine_atts
80
+
81
+ queue(
82
+ 'point' => 'detask',
83
+ 'exid' => exid, 'nid' => nid,
84
+ 'tasker' => att(nil),
85
+ 'attl' => attl, 'attd' => attd,
86
+ 'payload' => determine_payload)
87
+ end
88
+
89
+ protected
90
+
91
+ def determine_atts
92
+
93
+ attl, attd = [], {}
94
+ @node['atts'].each { |k, v| if k.nil?; attl << v; else; attd[k] = v; end }
95
+
96
+ [ attl, attd ]
97
+ end
98
+
99
+ def determine_payload
100
+
101
+ message_or_node_payload.copy_current
102
+ end
103
+
104
+ def determine_reply_payload
105
+
106
+ payload.copy_current
107
+ end
108
+ end
109
+
@@ -0,0 +1,51 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ class Flor::Pro::Trace < Flor::Procedure
27
+
28
+ name 'trace'
29
+
30
+ def receive
31
+
32
+ if @message['point'] == 'receive'
33
+
34
+ t = lookup_tree(@message['from'])
35
+
36
+ if t.first == '_att' && t[1].size == 1
37
+ @executor.unit.storage.trace(exid, nid, 'trace', payload['ret'])
38
+ end
39
+ end
40
+
41
+ super
42
+ end
43
+
44
+ def receive_last
45
+
46
+ payload['ret'] = node_payload_ret
47
+
48
+ reply
49
+ end
50
+ end
51
+
@@ -0,0 +1,100 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@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
+ # # trap
27
+ #
28
+ # ## range:/scope:
29
+ # * subnid (default)
30
+ # * execution/exe
31
+ # * domain
32
+ # * subdomain
33
+ #
34
+ # ## bind:
35
+ # * parent (default)
36
+ # * root
37
+ #
38
+ class Flor::Pro::Trap < Flor::Procedure
39
+
40
+ name 'trap'
41
+
42
+ def pre_execute
43
+
44
+ @node['vars'] = {}
45
+ @node['atts'] = []
46
+ @node['fun'] = nil
47
+
48
+ #unatt_unkeyed_children
49
+ end
50
+
51
+ def receive_non_att
52
+
53
+ return execute_child(@ncid) if children[@ncid]
54
+
55
+ fun = @fcid > 0 ? payload['ret'] : nil
56
+
57
+ points = att_a('point', 'points', nil)
58
+ tags = att_a('tag', 'tags', nil)
59
+ heats = att_a('heat', 'heats', nil)
60
+ heaps = att_a('heap', 'heaps', nil)
61
+ names = att_a('name', 'names', nil)
62
+ pl = att('payload', 'pl') || 'trap'
63
+
64
+ points = att_a(nil, nil) unless points || tags
65
+ points = [ 'entered' ] if tags && ! points
66
+
67
+ msg =
68
+ if fun
69
+ apply(fun, [], tree[2], false).first.merge('noreply' => true)
70
+ else
71
+ reply.first
72
+ end
73
+
74
+ tra = {}
75
+ tra['bnid'] = parent || '0' # shouldn't it be [the real] root?
76
+ tra['points'] = points
77
+ tra['tags'] = tags
78
+ tra['heaps'] = heaps
79
+ tra['heats'] = heats
80
+ tra['names'] = names
81
+ tra['message'] = msg
82
+ tra['pl'] = pl
83
+
84
+ count = att('count')
85
+ count = 1 if fun == nil # blocking mode implies count: 1
86
+ tra['count'] = count if count
87
+
88
+ tra['range'] = att('range') || att('scope') || 'subnid'
89
+
90
+ reply('point' => 'trap','nid' => nid, 'trap' => tra) +
91
+ (fun ? reply : [])
92
+ end
93
+
94
+ def receive_last
95
+
96
+ #fail ArgumentError.new('trap requires a function')
97
+ receive_non_att
98
+ end
99
+ end
100
+