Skip to content

Commit 2d74002

Browse files
committed
feat: wip function identifier change+
1 parent 575ade9 commit 2d74002

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

app/grpc/execution_handler.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ def handle_execution_result(execution_result, runtime_id)
7474
execution_identifier: execution_result.execution_identifier
7575
)
7676

77-
response = Namespaces::Projects::Flows::PersistExecutionResultService.new(execution_result).execute
77+
response = Namespaces::Projects::Flows::PersistExecutionResultService.new(
78+
execution_result,
79+
runtime_id: runtime_id
80+
).execute
7881
return if response.success?
7982

8083
logger.error(

app/services/namespaces/projects/flows/persist_execution_result_service.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ module Flows
66
class PersistExecutionResultService
77
include Code0::ZeroTrack::Loggable
88

9-
attr_reader :grpc_result
9+
attr_reader :grpc_result, :runtime_id
1010

11-
def initialize(grpc_result)
11+
def initialize(grpc_result, runtime_id: nil)
1212
@grpc_result = grpc_result
13+
@runtime_id = runtime_id
1314
end
1415

1516
def execute
@@ -56,7 +57,7 @@ def build_node_results(result)
5657
started_at: node_result.started_at,
5758
finished_at: node_result.finished_at,
5859
node_function: node_function_for(node_result),
59-
function_definition: function_definition_for(node_result)
60+
function_definition: function_definition_for(node_result, result.flow)
6061
)
6162

6263
assign_result(node_record, node_result)
@@ -79,10 +80,19 @@ def node_function_for(node_result)
7980
NodeFunction.find_by(id: node_result.node_id)
8081
end
8182

82-
def function_definition_for(node_result)
83-
return unless node_result.id == :function_id
83+
def function_definition_for(node_result, flow)
84+
return unless node_result.id == :function_identifier
8485

85-
FunctionDefinition.find_by(id: node_result.function_id)
86+
runtime = runtime_for(flow)
87+
return if runtime.nil?
88+
89+
FunctionDefinition.find_by(runtime: runtime, identifier: node_result.function_identifier)
90+
end
91+
92+
def runtime_for(flow)
93+
return Runtime.find_by(id: runtime_id) if runtime_id.present?
94+
95+
flow.project.primary_runtime || flow.flow_type.runtime
8696
end
8797

8898
def assign_result(record, grpc_record)

spec/services/namespaces/projects/flows/persist_execution_result_service_spec.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
require 'rails_helper'
44

55
RSpec.describe Namespaces::Projects::Flows::PersistExecutionResultService do
6-
subject(:service_response) { described_class.new(grpc_result).execute }
6+
subject(:service_response) { described_class.new(grpc_result, runtime_id: runtime_id).execute }
77

88
let(:flow) { create(:flow) }
99
let(:node_function) { create(:node_function, flow: flow) }
10+
let(:runtime_id) { nil }
1011
let(:started_at) { 1_780_430_000_000_000 }
1112
let(:finished_at) { 1_780_430_002_000_000 }
1213

@@ -168,6 +169,10 @@
168169

169170
context 'when a node execution result targets a function definition' do
170171
let(:function_definition) { create(:function_definition) }
172+
let!(:other_function_definition) do
173+
create(:function_definition, identifier: function_definition.identifier)
174+
end
175+
171176
let(:grpc_result) do
172177
Tucana::Shared::ExecutionResult.new(
173178
execution_identifier: 'execution-identifier',
@@ -178,7 +183,7 @@
178183
success: Tucana::Shared::Value.from_ruby('result' => true),
179184
node_execution_results: [
180185
Tucana::Shared::NodeExecutionResult.new(
181-
function_id: function_definition.id,
186+
function_identifier: function_definition.identifier,
182187
started_at: started_at,
183188
finished_at: finished_at,
184189
success: Tucana::Shared::Value.from_ruby('function' => 'ok')
@@ -187,6 +192,10 @@
187192
)
188193
end
189194

195+
before do
196+
flow.project.update!(primary_runtime: function_definition.runtime)
197+
end
198+
190199
it 'persists the function definition as the execution target' do
191200
expect(service_response).to be_success
192201

@@ -196,6 +205,18 @@
196205
success: { 'function' => 'ok' }
197206
)
198207
end
208+
209+
context 'when a runtime id is provided' do
210+
let(:runtime_id) { other_function_definition.runtime_id }
211+
212+
it 'looks up the function definition in the connected runtime' do
213+
expect(service_response).to be_success
214+
215+
expect(service_response.payload.node_results.sole).to have_attributes(
216+
function_definition: other_function_definition
217+
)
218+
end
219+
end
199220
end
200221

201222
context 'when the result is an error' do

0 commit comments

Comments
 (0)