Skip to content

Commit 9ea8184

Browse files
Merge pull request #2 from actionforge/exec-nodes
Add execution ports to random-stream random-number and stream-cache
2 parents 5ac0a97 + 8f1cf3e commit 9ea8184

15 files changed

Lines changed: 482 additions & 256 deletions

node_interfaces/interface_core_random-number_v1.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_interfaces/interface_core_random-stream_v1.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_interfaces/interface_core_stream-cache_v1.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodes/random-number@v1.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ var randomNumberNodeDefinition string
1414

1515
type RandomNumberNode struct {
1616
core.NodeBaseComponent
17+
core.Executions
1718
core.Inputs
1819
core.Outputs
1920

2021
randGenLock sync.Mutex
2122
randGen *rand.Rand
2223
}
2324

24-
func (n *RandomNumberNode) OutputValueById(c *core.ExecutionState, outputId core.OutputId) (any, error) {
25+
func (n *RandomNumberNode) ExecuteImpl(c *core.ExecutionState, inputId core.InputId, prevError error) error {
2526
min, err := core.InputValueById[float64](c, n, ni.Core_random_number_v1_Input_min)
2627
if err != nil {
27-
return nil, err
28+
return err
2829
}
2930
max, err := core.InputValueById[float64](c, n, ni.Core_random_number_v1_Input_max)
3031
if err != nil {
31-
return nil, err
32+
return err
3233
}
3334
seed, err := core.InputValueById[int64](c, n, ni.Core_random_number_v1_Input_seed)
3435
if err != nil {
35-
return nil, err
36+
return err
3637
}
3738

3839
if seed == -1 {
@@ -48,7 +49,13 @@ func (n *RandomNumberNode) OutputValueById(c *core.ExecutionState, outputId core
4849
n.randGenLock.Unlock()
4950

5051
randomNumber := min + f*(max-min)
51-
return randomNumber, nil
52+
53+
err = n.SetOutputValue(c, ni.Core_random_number_v1_Output_number, randomNumber, core.SetOutputValueOpts{})
54+
if err != nil {
55+
return err
56+
}
57+
58+
return n.Execute(ni.Core_random_number_v1_Output_exec_success, c, nil)
5259
}
5360

5461
func init() {

nodes/random-number@v1.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,37 @@ style:
1212
background: "#7c6652"
1313
short_desc: Generates a random number based on user-defined range and seed. Can be used as well for boolean values by setting the minimum and maximum values to 0 and 1 respectively.
1414
outputs:
15+
exec-success:
16+
name: ''
17+
exec: true
18+
index: 0
19+
desc: Triggered when the random number is generated.
1520
number:
1621
type: number
1722
name: Random Number
1823
desc: The generated random number
19-
index: 0
24+
index: 1
2025
inputs:
26+
exec:
27+
exec: true
28+
index: 0
29+
name: ''
30+
desc: Triggers the generation of the random number.
2131
min:
2232
type: number
2333
name: Minimum Value
2434
desc: The minimum value of the random number
25-
index: 0
35+
index: 1
2636
initial: 0.0
2737
max:
2838
type: number
2939
name: Maximum Value
3040
desc: The maximum value of the random number
31-
index: 1
41+
index: 2
3242
initial: 1.0
3343
seed:
3444
type: number
3545
name: Seed
3646
desc: The seed for the random number generator (-1 for true randomness)
37-
index: 2
38-
initial: -1
47+
index: 3
48+
initial: -1

nodes/random-stream@v1.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var randomStreamNodeDefinition string
1818

1919
type RandomStreamNode struct {
2020
core.NodeBaseComponent
21+
core.Executions
2122
core.Inputs
2223
core.Outputs
2324
}
@@ -93,37 +94,44 @@ func (r *RandomStreamReader) Read(p []byte) (n int, err error) {
9394
return len(p), nil
9495
}
9596

96-
func (n *RandomStreamNode) OutputValueById(c *core.ExecutionState, outputId core.OutputId) (any, error) {
97+
func (n *RandomStreamNode) ExecuteImpl(c *core.ExecutionState, inputId core.InputId, prevError error) error {
9798
length, err := core.InputValueById[int](c, n, ni.Core_random_stream_v1_Input_length)
9899
if err != nil {
99-
return nil, err
100+
return err
100101
}
101102
includeNumbers, err := core.InputValueById[bool](c, n, ni.Core_random_stream_v1_Input_include_numbers)
102103
if err != nil {
103-
return nil, err
104+
return err
104105
}
105106
includeCharacters, err := core.InputValueById[bool](c, n, ni.Core_random_stream_v1_Input_include_characters)
106107
if err != nil {
107-
return nil, err
108+
return err
108109
}
109110
includeUppercase, err := core.InputValueById[bool](c, n, ni.Core_random_stream_v1_Input_include_uppercase)
110111
if err != nil {
111-
return nil, err
112+
return err
112113
}
113114
includeSpecial, err := core.InputValueById[bool](c, n, ni.Core_random_stream_v1_Input_include_special)
114115
if err != nil {
115-
return nil, err
116+
return err
116117
}
117118
seed, err := core.InputValueById[int64](c, n, ni.Core_random_stream_v1_Input_seed)
118119
if err != nil {
119-
return nil, err
120+
return err
120121
}
121122

122123
reader := NewRandomStringReader(length, includeNumbers, includeCharacters, includeUppercase, includeSpecial, seed)
123-
return core.DataStreamFactory{
124+
outputStream := core.DataStreamFactory{
124125
Reader: reader,
125126
Length: core.GetReaderLength(reader),
126-
}, nil
127+
}
128+
129+
err = n.SetOutputValue(c, ni.Core_random_stream_v1_Output_stream, outputStream, core.SetOutputValueOpts{})
130+
if err != nil {
131+
return err
132+
}
133+
134+
return n.Execute(ni.Core_random_stream_v1_Output_exec_success, c, nil)
127135
}
128136

129137
func init() {

nodes/random-stream@v1.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,51 @@ style:
1212
background: "#7c6652"
1313
short_desc: Creates a random stream based on user-defined character set preferences.
1414
outputs:
15+
exec-success:
16+
name: ''
17+
exec: true
18+
index: 0
19+
desc: Triggered when the stream is successfully created.
1520
stream:
1621
type: stream
1722
name: Random Stream
1823
desc: The generated random stream
19-
index: 0
24+
index: 1
2025
inputs:
26+
exec:
27+
exec: true
28+
index: 0
29+
name: ''
30+
desc: Triggers the generation of the stream.
2131
length:
2232
type: number
2333
name: Length
2434
desc: The length of the stream.
25-
index: 0
35+
index: 1
2636
initial: 10
2737
include_numbers:
2838
type: bool
2939
name: Numbers
3040
desc: Include numbers (0-9) in the stream.
31-
index: 1
41+
index: 2
3242
include_characters:
3343
type: bool
3444
name: Characters
3545
desc: Include lower-case characters (a-z) in the stream.
36-
index: 2
46+
index: 3
3747
initial: true
3848
include_uppercase:
3949
type: bool
4050
name: Upper-case Characters
4151
desc: Include upper-case characters (A-Z) in the stream.
42-
index: 3
52+
index: 4
4353
include_special:
4454
type: bool
4555
name: Special Characters
4656
desc: Include special characters (!@#$%^&*() etc.) in the stream.
47-
index: 4
57+
index: 5
4858
seed:
4959
type: number
5060
name: Seed
5161
desc: The seed for the random number generator (-1 for true randomness)
52-
index: 5
62+
index: 6

nodes/stream-cache@v1.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,34 @@ var streamCacheNodeDefinition string
1414

1515
type StreamCacheNode struct {
1616
core.NodeBaseComponent
17+
core.Executions
1718
core.Inputs
1819
core.Outputs
1920
}
2021

21-
func (n *StreamCacheNode) OutputValueById(c *core.ExecutionState, outputId core.OutputId) (any, error) {
22+
func (n *StreamCacheNode) ExecuteImpl(c *core.ExecutionState, inputId core.InputId, prevError error) error {
2223
inputStream, err := core.InputValueById[io.Reader](c, n, ni.Core_stream_cache_v1_Input_stream)
2324
if err != nil {
24-
return nil, err
25+
return err
2526
}
2627

2728
buffer := new(bytes.Buffer)
2829
_, err = io.Copy(buffer, inputStream)
2930
if err != nil {
30-
return nil, core.CreateErr(c, err, "failed to read input stream")
31+
return core.CreateErr(c, err, "failed to read input stream")
3132
}
3233

33-
return buffer.String(), nil
34+
err = n.SetOutputValue(c, ni.Core_stream_cache_v1_Output_result, buffer.String(), core.SetOutputValueOpts{})
35+
if err != nil {
36+
return err
37+
}
38+
39+
err = n.Execute(ni.Core_stream_cache_v1_Output_exec_success, c, nil)
40+
if err != nil {
41+
return err
42+
}
43+
44+
return nil
3445
}
3546

3647
func init() {

nodes/stream-cache@v1.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ style:
1414
short_desc: Cache a stream and output it as a string.
1515
long_desc: Like the [File Read](./../file-read/v1.md) node, some streams are readable only by a single consumer. This node caches the stream and outputs it as a string, which can be used by multiple consumers.
1616
outputs:
17+
exec-success:
18+
name:
19+
exec: true
20+
index: 0
1721
result:
1822
type: string
1923
desc: The cached stream as a string.
20-
index: 0
24+
index: 1
2125
inputs:
26+
exec:
27+
exec: true
28+
index: 0
2229
stream:
2330
type: stream
2431
desc: The input stream to be cached.
25-
index: 0
32+
index: 1
2633
required: true

0 commit comments

Comments
 (0)