Skip to content

Commit f4e5a3e

Browse files
committed
feat: removed runtime status impl
1 parent 3420ced commit f4e5a3e

40 files changed

Lines changed: 157 additions & 320 deletions

app/graphql/types/runtime_module_status_type.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/graphql/types/runtime_module_type.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class RuntimeModuleType < Types::BaseObject
1414
field :data_types, Types::DataTypeType.connection_type, null: false, description: 'Data types of the runtime module'
1515
field :definitions, Types::RuntimeModuleDefinitionType.connection_type,
1616
null: false,
17-
description: 'Endpoint definitions of the runtime module',
17+
description: 'Definitions of the runtime module',
1818
method: :runtime_module_definitions
1919
field :descriptions, [Types::TranslationType], null: true, description: 'Descriptions of the runtime module'
2020
field :documentation, String, null: false, description: 'Documentation URL of the runtime module'
@@ -29,10 +29,6 @@ class RuntimeModuleType < Types::BaseObject
2929
field :runtime_flow_types, Types::RuntimeFlowTypeType.connection_type,
3030
null: false,
3131
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!
3632
# rubocop:disable GraphQL/ExtractType
3733
field :runtime_function_definitions, Types::RuntimeFunctionDefinitionType.connection_type,
3834
null: false,

app/graphql/types/runtime_status_status_enum.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ 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'
87
value :NOT_RESPONDING, 'The runtime is not responding to heartbeats', value: 'not_responding'
98
value :NOT_READY, 'The runtime is not ready to compute stuff', value: 'not_ready'
109
value :RUNNING, 'The runtime is running and healthy', value: 'running'

app/graphql/types/runtime_status_type.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ class RuntimeStatusType < Types::BaseObject
55
description 'A runtime status information entry'
66

77
authorize :read_runtime
8-
8+
field :configurations, Types::RuntimeStatusConfigurationType.connection_type,
9+
null: false,
10+
description: 'The detailed configuration entries for this runtime status (only for adapters)',
11+
method: :runtime_status_configurations
12+
field :identifier, String,
13+
null: false,
14+
description: 'The unique identifier for this runtime status'
915
field :last_heartbeat, Types::TimeType,
1016
null: true,
1117
description: 'The timestamp of the last heartbeat received from the runtime'
1218
field :status, Types::RuntimeStatusStatusEnum,
1319
null: false,
1420
description: 'The current status of the runtime',
1521
method: :current_status
16-
field :uptime, Float,
17-
null: false,
18-
description: 'Current uptime percentage for the runtime'
19-
field :uptimes, [Float],
22+
field :type, RuntimeStatusTypeEnum,
2023
null: false,
21-
description: 'Uptime percentages for the last 14 days'
24+
description: 'Type of the runtime status',
25+
method: :status_type
2226

2327
id_field RuntimeStatus
2428
timestamps

app/graphql/types/runtime_type.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ 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::RuntimeStatusType, null: false, description: 'The status of the runtime',
17-
method: :ensure_runtime_status!
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
1821
field :token, String, null: true, description: 'Token belonging to the runtime, only present on creation'
1922

2023
expose_abilities %i[
@@ -26,6 +29,17 @@ class RuntimeType < Types::BaseObject
2629
id_field Runtime
2730
timestamps
2831

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+
2943
def token
3044
object.token if object.token_previously_changed?
3145
end

app/grpc/runtime_status_handler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class RuntimeStatusHandler < Tucana::Sagittarius::RuntimeStatusService::Service
44
include Code0::ZeroTrack::Loggable
55
include GrpcHandler
66

7-
def update(request, _call)
7+
# TODO: Implement in #1018
8+
def update_disabled(request, _call)
89
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])
910
status_info = request.status
1011
return Tucana::Sagittarius::RuntimeStatusUpdateResponse.new(success: false) if status_info.nil?

app/models/runtime.rb

Lines changed: 1 addition & 16 deletions
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_one :runtime_status, inverse_of: :runtime
10+
has_many :runtime_statuses, 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,26 +33,11 @@ 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
4436

4537
private
4638

4739
def strip_whitespace
4840
name&.strip!
4941
description&.strip!
5042
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
5843
end

app/models/runtime_module.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class RuntimeModule < ApplicationRecord
1212
has_many :function_definitions, inverse_of: :runtime_module
1313
has_many :module_configuration_definitions, inverse_of: :runtime_module
1414
has_many :runtime_module_definitions, inverse_of: :runtime_module
15-
has_one :runtime_module_status, inverse_of: :runtime_module
1615

1716
has_translation :names, purpose: :name
1817
has_translation :descriptions, purpose: :description
@@ -26,10 +25,6 @@ class RuntimeModule < ApplicationRecord
2625

2726
validate :validate_version
2827

29-
def ensure_runtime_module_status!
30-
runtime_module_status || create_runtime_module_status!(status: :unknown)
31-
end
32-
3328
def validate_version
3429
return errors.add(:version, :blank) if version.blank?
3530

app/models/runtime_module_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ class RuntimeModuleDefinition < ApplicationRecord
44
belongs_to :runtime_module, inverse_of: :runtime_module_definitions
55

66
validates :host, :endpoint, presence: true
7-
validates :port, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
7+
validates :port, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 65_535 }
88
end

app/models/runtime_module_status.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)