Skip to content

Commit 5cf0132

Browse files
authored
Merge pull request #497 from code0-tech/fix/grpc-flow-serialization
Fix grpc flow serialization
2 parents 0ae5f34 + a4df49c commit 5cf0132

File tree

7 files changed

+85
-11
lines changed

7 files changed

+85
-11
lines changed

app/grpc/flow_handler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def self.update_started(runtime_id)
2121
end
2222
end
2323

24+
# TODO: Add check to check for primary runtime conflicts
25+
2426
send_update(
2527
Tucana::Sagittarius::FlowResponse.new(
2628
flows: Tucana::Shared::Flows.new(

app/models/flow.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class Flow < ApplicationRecord
77
belongs_to :return_type, class_name: 'DataType', optional: true
88
belongs_to :starting_node, class_name: 'NodeFunction'
99

10-
has_many :flow_settings
10+
has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow
1111

1212
def to_grpc
1313
Tucana::Shared::Flow.new(
14-
id: id,
14+
flow_id: id,
1515
project_id: project.id,
16-
flow_type_id: flow_type.identifier,
17-
data_types: [], # TODO
18-
input_type_id: input_type&.identifier,
19-
return_type_id: return_type&.identifier,
16+
type: flow_type.identifier,
17+
data_types: [], # TODO: when data types are creatable
18+
input_type_identifier: input_type&.identifier,
19+
return_type_identifier: return_type&.identifier,
2020
settings: flow_settings.map(&:to_grpc),
2121
starting_node: starting_node.to_grpc
2222
)

app/models/flow_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def to_grpc
77
Tucana::Shared::FlowSetting.new(
88
database_id: id,
99
flow_setting_id: flow_setting_id,
10-
object: Tucana::Shared::Struct.from_ruby(object)
10+
object: Tucana::Shared::Struct.from_hash(object)
1111
)
1212
end
1313
end

app/models/node_function.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def validate_recursion
4141
end
4242

4343
def to_grpc
44-
Tucana::NodeFunction.new(
45-
data_base_id: id,
46-
runtime_function: runtime_function.to_grpc,
44+
Tucana::Shared::NodeFunction.new(
45+
database_id: id,
46+
runtime_function_id: runtime_function.runtime_name,
4747
parameters: node_parameters.map(&:to_grpc),
4848
next_node: next_node&.to_grpc
4949
)

app/models/node_parameter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NodeParameter < ApplicationRecord
1111
def to_grpc
1212
param = Tucana::Shared::NodeParameter.new(
1313
database_id: id,
14-
runtime_parameter_id: runtime_parameter&.identifier
14+
runtime_parameter_id: runtime_parameter.runtime_name
1515
)
1616

1717
if literal_value.present?

spec/factories/flows.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
project factory: %i[namespace_project]
66
flow_type
77
starting_node factory: %i[node_function]
8+
flow_settings { [] }
9+
input_type { nil }
10+
return_type { nil }
811
end
912
end

spec/models/flow_spec.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,73 @@
1414

1515
it { is_expected.to have_many(:flow_settings) }
1616
end
17+
18+
describe '#to_grpc' do
19+
let(:flow) do
20+
create(:flow,
21+
flow_settings: [
22+
create(:flow_setting,
23+
flow_setting_id: 'example_key',
24+
object: { some_key: 'some_value' })
25+
],
26+
starting_node: create(:node_function,
27+
node_parameters: [
28+
create(:node_parameter,
29+
runtime_parameter: create(:runtime_parameter_definition,
30+
data_type: create(:data_type_identifier,
31+
generic_key: 'T')))
32+
]))
33+
end
34+
35+
it 'matches the model' do
36+
grpc_object = flow.to_grpc
37+
38+
expect(grpc_object.to_h).to eq({
39+
data_types: [],
40+
flow_id: flow.id,
41+
project_id: flow.project.id,
42+
type: flow.flow_type.identifier,
43+
input_type_identifier: flow.input_type&.identifier || '',
44+
return_type_identifier: flow.return_type&.identifier || '',
45+
starting_node: {
46+
database_id: flow.starting_node.id,
47+
next_node: nil,
48+
runtime_function_id: flow.starting_node.runtime_function.runtime_name,
49+
parameters: [
50+
{
51+
database_id: flow.starting_node.node_parameters.first.id,
52+
runtime_parameter_id:
53+
flow.starting_node.node_parameters.first.runtime_parameter.runtime_name,
54+
function_value: nil,
55+
literal_value: {
56+
bool_value: false,
57+
list_value: nil,
58+
null_value: :NULL_VALUE,
59+
number_value: 0.0,
60+
string_value: flow.starting_node.node_parameters.first.literal_value,
61+
struct_value: nil,
62+
},
63+
reference_value: nil,
64+
}
65+
],
66+
},
67+
settings: [
68+
database_id: flow.flow_settings.first.id,
69+
flow_setting_id: flow.flow_settings.first.flow_setting_id,
70+
object: {
71+
fields: {
72+
'some_key' => {
73+
bool_value: false,
74+
list_value: nil,
75+
null_value: :NULL_VALUE,
76+
number_value: 0.0,
77+
string_value: flow.flow_settings.first.object['some_key'],
78+
struct_value: nil,
79+
},
80+
},
81+
}
82+
],
83+
})
84+
end
85+
end
1786
end

0 commit comments

Comments
 (0)