Skip to content

Commit 3420ced

Browse files
committed
feat: runtime status & function identifer for node executions
1 parent 99ee0fd commit 3420ced

56 files changed

Lines changed: 624 additions & 166 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/graphql/types/execution_node_result_type.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class ExecutionNodeResultType < Types::BaseObject
1212
field :finished_at, Types::BigIntType,
1313
null: false,
1414
description: 'Unix epoch time in microseconds when this node execution finished'
15+
field :function_definition, Types::FunctionDefinitionType,
16+
null: true,
17+
description: 'Function definition associated with this sub-flow result'
1518
field :node_function, Types::NodeFunctionType, null: true, description: 'Node function associated with this result'
1619
field :parameter_results, [Types::ExecutionParameterResultType],
1720
null: false,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeModuleDefinitionType < Types::BaseObject
5+
description 'A runtime module definition endpoint'
6+
7+
authorize :read_runtime_module
8+
9+
field :endpoint, String, null: false, description: 'Endpoint path of the module definition'
10+
field :host, String, null: false, description: 'Host of the module definition endpoint'
11+
field :port, Types::BigIntType, null: false, description: 'Port of the module definition endpoint'
12+
13+
id_field RuntimeModuleDefinition
14+
timestamps
15+
end
16+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeModuleStatusType < Types::BaseObject
5+
description 'A runtime module status information entry'
6+
7+
authorize :read_runtime_module
8+
9+
field :last_heartbeat, Types::TimeType,
10+
null: true,
11+
description: 'The timestamp of the last heartbeat received from the runtime module'
12+
field :status, Types::RuntimeStatusStatusEnum,
13+
null: false,
14+
description: 'The current status of the runtime module',
15+
method: :current_status
16+
field :uptime, Float,
17+
null: false,
18+
description: 'Current uptime percentage for the runtime module'
19+
field :uptimes, [Float],
20+
null: false,
21+
description: 'Uptime percentages for the last 14 days'
22+
23+
id_field RuntimeModuleStatus
24+
timestamps
25+
end
26+
end

app/graphql/types/runtime_module_type.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class RuntimeModuleType < Types::BaseObject
1212
description: 'Configuration definitions of the runtime module',
1313
method: :module_configuration_definitions
1414
field :data_types, Types::DataTypeType.connection_type, null: false, description: 'Data types of the runtime module'
15+
field :definitions, Types::RuntimeModuleDefinitionType.connection_type,
16+
null: false,
17+
description: 'Endpoint definitions of the runtime module',
18+
method: :runtime_module_definitions
1519
field :descriptions, [Types::TranslationType], null: true, description: 'Descriptions of the runtime module'
1620
field :documentation, String, null: false, description: 'Documentation URL of the runtime module'
1721
field :flow_types, Types::FlowTypeType.connection_type, null: false, description: 'Flow types of the runtime module'
@@ -25,6 +29,10 @@ class RuntimeModuleType < Types::BaseObject
2529
field :runtime_flow_types, Types::RuntimeFlowTypeType.connection_type,
2630
null: false,
2731
description: 'Runtime flow types of the runtime module'
32+
field :status, Types::RuntimeModuleStatusType,
33+
null: false,
34+
description: 'The status of the runtime module',
35+
method: :ensure_runtime_module_status!
2836
# rubocop:disable GraphQL/ExtractType
2937
field :runtime_function_definitions, Types::RuntimeFunctionDefinitionType.connection_type,
3038
null: false,

app/graphql/types/runtime_status_status_enum.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Types
44
class RuntimeStatusStatusEnum < Types::BaseEnum
55
description 'The enum status of the detailed status'
66

7+
value :UNKNOWN, 'The runtime status is unknown', value: 'unknown'
78
value :NOT_RESPONDING, 'The runtime is not responding to heartbeats', value: 'not_responding'
89
value :NOT_READY, 'The runtime is not ready to compute stuff', value: 'not_ready'
910
value :RUNNING, 'The runtime is running and healthy', value: 'running'

app/graphql/types/runtime_status_type.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@ class RuntimeStatusType < Types::BaseObject
66

77
authorize :read_runtime
88

9-
field :configurations, Types::RuntimeStatusConfigurationType.connection_type,
10-
null: false,
11-
description: 'The detailed configuration entries for this runtime status (only for adapters)',
12-
method: :runtime_status_configurations
13-
field :identifier, String,
14-
null: false,
15-
description: 'The unique identifier for this runtime status'
169
field :last_heartbeat, Types::TimeType,
1710
null: true,
1811
description: 'The timestamp of the last heartbeat received from the runtime'
1912
field :status, Types::RuntimeStatusStatusEnum,
2013
null: false,
21-
description: 'The current status of the runtime (e.g. running, stopped)'
22-
field :type, Types::RuntimeStatusTypeEnum,
14+
description: 'The current status of the runtime',
15+
method: :current_status
16+
field :uptime, Float,
17+
null: false,
18+
description: 'Current uptime percentage for the runtime'
19+
field :uptimes, [Float],
2320
null: false,
24-
description: 'The type of runtime status information (e.g. adapter, execution)',
25-
method: :status_type
21+
description: 'Uptime percentages for the last 14 days'
2622

2723
id_field RuntimeStatus
2824
timestamps

app/graphql/types/runtime_type.rb

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ class RuntimeType < Types::BaseObject
1313
field :namespace, Types::NamespaceType, null: true, description: 'The parent namespace for the runtime'
1414
field :projects, Types::NamespaceProjectType.connection_type, null: false,
1515
description: 'Projects associated with the runtime'
16-
field :status, Types::RuntimeConnectionStatusEnum, null: false, description: 'The status of the runtime'
17-
18-
field :statuses, Types::RuntimeStatusType.connection_type, null: false,
19-
description: 'Statuses of the runtime',
20-
method: :runtime_statuses
16+
field :status, Types::RuntimeStatusType, null: false, description: 'The status of the runtime',
17+
method: :ensure_runtime_status!
2118
field :token, String, null: true, description: 'Token belonging to the runtime, only present on creation'
2219

2320
expose_abilities %i[
@@ -29,17 +26,6 @@ class RuntimeType < Types::BaseObject
2926
id_field Runtime
3027
timestamps
3128

32-
# If the last heartbeat was within the last 10 minutes, consider the runtime as 'running'
33-
def status
34-
last_heartbeat = object.last_heartbeat
35-
36-
if last_heartbeat && last_heartbeat >= 10.minutes.ago
37-
:connected
38-
else
39-
:disconnected
40-
end
41-
end
42-
4329
def token
4430
object.token if object.token_previously_changed?
4531
end

app/grpc/runtime_status_handler.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ class RuntimeStatusHandler < Tucana::Sagittarius::RuntimeStatusService::Service
66

77
def update(request, _call)
88
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])
9-
status_info = case request.status
10-
when :adapter_runtime_status
11-
request.adapter_runtime_status
12-
when :execution_runtime_status
13-
request.execution_runtime_status
14-
else
15-
return Tucana::Sagittarius::RuntimeStatusUpdateResponse.new(success: false)
16-
end
9+
status_info = request.status
10+
return Tucana::Sagittarius::RuntimeStatusUpdateResponse.new(success: false) if status_info.nil?
1711

1812
response = Runtimes::Grpc::RuntimeStatusUpdateService.new(
1913
runtime: current_runtime,

app/models/execution_node_result.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
class ExecutionNodeResult < ApplicationRecord
44
belongs_to :execution_result, inverse_of: :node_results
55
belongs_to :node_function, optional: true
6+
belongs_to :function_definition, optional: true
67

78
has_many :parameter_results,
89
class_name: 'ExecutionParameterResult',
910
inverse_of: :execution_node_result
1011

1112
validates :position, presence: true, numericality: { only_integer: true }
1213
validates :started_at, :finished_at, numericality: { only_integer: true }
14+
validate :only_one_execution_target_present
1315
validate :only_one_result_present
1416

1517
private
1618

19+
def only_one_execution_target_present
20+
return if [node_function.present?, function_definition.present?].count(true) == 1
21+
22+
errors.add(:base, 'Only one of node_function or function_definition must be present')
23+
end
24+
1725
def only_one_result_present
1826
return if [!success.nil?, !error.nil?].count(true) == 1
1927

app/models/runtime.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Runtime < ApplicationRecord
77

88
token_attr :token, prefix: 's_rt_', length: 48
99

10-
has_many :runtime_statuses, inverse_of: :runtime
10+
has_one :runtime_status, inverse_of: :runtime
1111

1212
has_many :project_assignments, class_name: 'NamespaceProjectRuntimeAssignment', inverse_of: :runtime
1313
has_many :projects, class_name: 'NamespaceProject', through: :project_assignments, source: :namespace_project,
@@ -33,11 +33,26 @@ class Runtime < ApplicationRecord
3333
validates :description, length: { maximum: 500 }, exclusion: { in: [nil] }
3434

3535
before_validation :strip_whitespace
36+
after_save :sync_runtime_status_heartbeat!, if: :saved_change_to_last_heartbeat?
37+
38+
def ensure_runtime_status!
39+
runtime_status || create_runtime_status!(
40+
last_heartbeat: last_heartbeat,
41+
status: RuntimeStatus.status_for_heartbeat(last_heartbeat)
42+
)
43+
end
3644

3745
private
3846

3947
def strip_whitespace
4048
name&.strip!
4149
description&.strip!
4250
end
51+
52+
def sync_runtime_status_heartbeat!
53+
ensure_runtime_status!.update!(
54+
last_heartbeat: last_heartbeat,
55+
status: RuntimeStatus.status_for_heartbeat(last_heartbeat)
56+
)
57+
end
4358
end

0 commit comments

Comments
 (0)