From 1de303458e9cc9117d564635c619491a8e8afe88 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Thu, 18 Dec 2025 13:56:33 +0100 Subject: [PATCH] Add last execution duration to flow --- app/graphql/types/flow_type.rb | 3 +++ app/grpc/runtime_usage_handler.rb | 27 +++++++++++++++++++ ...33_add_last_execution_duration_to_flows.rb | 7 +++++ db/schema_migrations/20251217140333 | 1 + db/structure.sql | 3 ++- docs/graphql/object/flow.md | 1 + spec/graphql/types/flow_type_type_spec.rb | 1 + 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/grpc/runtime_usage_handler.rb create mode 100644 db/migrate/20251217140333_add_last_execution_duration_to_flows.rb create mode 100644 db/schema_migrations/20251217140333 diff --git a/app/graphql/types/flow_type.rb b/app/graphql/types/flow_type.rb index daff618a..e161bc47 100644 --- a/app/graphql/types/flow_type.rb +++ b/app/graphql/types/flow_type.rb @@ -11,6 +11,9 @@ class FlowType < Types::BaseObject field :input_type, Types::DataTypeType, null: true, description: 'The input data type of the flow' + field :last_execution_duration, Integer, + null: true, + description: 'The duration of the last execution of the flow in nanoseconds' field :return_type, Types::DataTypeType, null: true, description: 'The return data type of the flow' diff --git a/app/grpc/runtime_usage_handler.rb b/app/grpc/runtime_usage_handler.rb new file mode 100644 index 00000000..4901b36c --- /dev/null +++ b/app/grpc/runtime_usage_handler.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RuntimeUsageHandler < Tucana::Sagittarius::RuntimeUsageService::Service + include GrpcHandler + include Code0::ZeroTrack::Loggable + + def update(request, _call) + current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id]) + + request.runtime_usage.each do |usage_info| + flow = Flow.find_by(id: usage_info.flow_id) + + if flow.nil? || flow.project.primary_runtime != current_runtime + logger.error( + message: 'Flow not found or does not belong to current runtime', + runtime_id: current_runtime.id, + flow_id: usage_info.flow_id + ) + return Tucana::Sagittarius::RuntimeUsageResponse.new(success: false) + end + flow.last_execution_duration = usage_info.duration.to_i + flow.save! + end + + Tucana::Sagittarius::RuntimeUsageeResponse.new(success: true) + end +end diff --git a/db/migrate/20251217140333_add_last_execution_duration_to_flows.rb b/db/migrate/20251217140333_add_last_execution_duration_to_flows.rb new file mode 100644 index 00000000..64579466 --- /dev/null +++ b/db/migrate/20251217140333_add_last_execution_duration_to_flows.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddLastExecutionDurationToFlows < Code0::ZeroTrack::Database::Migration[1.0] + def change + add_column :flows, :last_execution_duration, :bigint, null: true, default: nil + end +end diff --git a/db/schema_migrations/20251217140333 b/db/schema_migrations/20251217140333 new file mode 100644 index 00000000..9f372db7 --- /dev/null +++ b/db/schema_migrations/20251217140333 @@ -0,0 +1 @@ +bc5cbc74c587f21ba1d98a76876dfd3d5e91bc2e4ef2eccd8d85129f5f740fb3 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 421fa7d5..996f95c7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -252,7 +252,8 @@ CREATE TABLE flows ( starting_node_id bigint, name text NOT NULL, created_at timestamp with time zone NOT NULL, - updated_at timestamp with time zone NOT NULL + updated_at timestamp with time zone NOT NULL, + last_execution_duration bigint ); CREATE SEQUENCE flows_id_seq diff --git a/docs/graphql/object/flow.md b/docs/graphql/object/flow.md index 060e4f43..6d630eb8 100644 --- a/docs/graphql/object/flow.md +++ b/docs/graphql/object/flow.md @@ -11,6 +11,7 @@ Represents a flow | `createdAt` | [`Time!`](../scalar/time.md) | Time when this Flow was created | | `id` | [`FlowID!`](../scalar/flowid.md) | Global ID of this Flow | | `inputType` | [`DataType`](../object/datatype.md) | The input data type of the flow | +| `lastExecutionDuration` | [`Int`](../scalar/int.md) | The duration of the last execution of the flow in nanoseconds | | `name` | [`String!`](../scalar/string.md) | Name of the flow | | `nodes` | [`NodeFunctionConnection!`](../object/nodefunctionconnection.md) | Nodes of the flow | | `returnType` | [`DataType`](../object/datatype.md) | The return data type of the flow | diff --git a/spec/graphql/types/flow_type_type_spec.rb b/spec/graphql/types/flow_type_type_spec.rb index 3571503c..c209d8ac 100644 --- a/spec/graphql/types/flow_type_type_spec.rb +++ b/spec/graphql/types/flow_type_type_spec.rb @@ -10,6 +10,7 @@ input_type return_type flow_type_settings + last_execution_duration names display_messages aliases