Skip to content

Commit cc69334

Browse files
committed
Add specs and implement more runtime status stuff
1 parent da47926 commit cc69334

11 files changed

Lines changed: 84 additions & 36 deletions

File tree

Gemfile.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
PATH
2-
remote: ../tucana/build/ruby
3-
specs:
4-
tucana (0.0.0)
5-
grpc (~> 1.64)
6-
71
GEM
82
remote: https://rubygems.org/
93
specs:

app/graphql/types/runtime_status_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class RuntimeStatusType < Types::BaseObject
88
null: false,
99
description: 'The detailed configuration entries for this runtime status (only for adapters)',
1010
method: :runtime_status_configurations
11-
field :feature_set, [String], null: false, description: 'The set of features supported by the runtime'
11+
field :features, [String], null: false, description: 'The set of features supported by the runtime'
1212
field :identifier, String, null: false, description: 'The unique identifier for this runtime status'
1313
field :last_heartbeat, Types::TimeType, null: true,
1414
description: 'The timestamp of the last heartbeat received from the runtime'

app/graphql/types/runtime_type.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ class RuntimeType < Types::BaseObject
1717
field :projects, Types::NamespaceProjectType.connection_type, null: false,
1818
description: 'Projects associated with the runtime'
1919
field :status, Types::RuntimeStatusType, null: false, description: 'The status of the runtime'
20-
21-
field :token, String, null: true, description: 'Token belonging to the runtime, only present on creation'
22-
2320
field :status, Types::RuntimeStatusStatusEnum,
2421
null: false,
2522
description: 'Wheater the last heartbeat was recent enough to consider the runtime as connected'
23+
2624
field :statuses, Types::RuntimeStatusType.connection_type, null: false,
2725
description: 'Statuses of the runtime',
2826
method: :runtime_statuses
27+
field :token, String, null: true, description: 'Token belonging to the runtime, only present on creation'
2928

3029
expose_abilities %i[
3130
delete_runtime

app/grpc/flow_handler.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class FlowHandler < Tucana::Sagittarius::FlowService::Service
88
grpc_stream :update
99

1010
def self.update_runtime(runtime)
11+
runtime.last_heartbeat = Time.zone.now
12+
runtime.save!
13+
1114
flows = []
1215
runtime.project_assignments.compatible.each do |assignment|
1316
assignment.namespace_project.flows.each do |flow|

app/grpc/runtime_status_handler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def update(request, _call)
88
current_runtime = Runtime.find(Code0::ZeroTrack::Context.current[:runtime][:id])
99

1010
response = Runtimes::Grpc::RuntimeStatusUpdateService.new(
11-
current_runtime,
12-
request.status
11+
runtime: current_runtime,
12+
status_info: request.send(request.status)
1313
).execute
1414

1515
logger.debug("RuntimeFunctionHandler#update response: #{response.inspect}")

app/services/error_code.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def self.error_codes
8989
invalid_node_parameter: { description: 'The node parameter is invalid' },
9090
invalid_node_function: { description: 'The node function is invalid' },
9191
invalid_runtime_status: { description: 'The runtime status is invalid because of active model errors' },
92+
invalid_runtime_status_configuration: { description: 'The runtime status configuration is invalid because of active model errors' },
9293

9394
primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
9495
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },

app/services/runtimes/grpc/runtime_status_update_service.rb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Runtimes
44
module Grpc
55
class RuntimeStatusUpdateService
66
include Sagittarius::Database::Transactional
7+
include Code0::ZeroTrack::Loggable
78

89
attr_reader :runtime, :status_info
910

@@ -24,45 +25,37 @@ def execute
2425
)
2526
end
2627

27-
db_status = RuntimeStatus.find_or_initialize_by(runtime: current_runtime,
28+
db_status = RuntimeStatus.find_or_initialize_by(runtime: runtime,
2829
identifier: status_info.identifier)
2930

30-
db_status.last_heartbeat = Time.zone.at(status_info.last_heartbeat.seconds)
31+
db_status.last_heartbeat = Time.zone.at(status_info.timestamp.to_i)
3132
db_status.status_type = if status_info.is_a?(Tucana::Shared::AdapterRuntimeStatus)
3233
:adapter
3334
else
3435
:execution
3536
end
36-
db_status.feature_set = status_info.feature_set.to_a
37+
db_status.features = status_info.features.to_a
3738

38-
case status_info.status
39-
when Tucana::Shared::Status::NOT_RESPONDING
40-
db_status.status = :not_responding
41-
when Tucana::Shared::Status::NOT_READY
42-
db_status.status = :not_ready
43-
when Tucana::Shared::Status::RUNNING
44-
db_status.status = :running
45-
when Tucana::Shared::Status::STOPPED
46-
db_status.status = :stopped
47-
else
48-
logger.error("Unknown status received: #{status_info.status}")
49-
t.rollback_and_return ServiceResponse.error(
50-
message: 'Unknown status received',
51-
error_code: :invalid_runtime_status,
52-
details: { status: status_info.status }
53-
)
54-
end
39+
db_status.status = status_info.status.downcase
5540

5641
db_configs = db_status.runtime_status_configurations.first(status_info.configurations.size)
5742

5843
status_info.configurations.each_with_index do |config, index|
5944
db_configs[index] ||= db_status.runtime_status_configurations.build
6045

6146
db_configs[index].endpoint = config.endpoint
47+
48+
next if db_configs[index].save
49+
50+
t.rollback_and_return! ServiceResponse.error(
51+
message: 'Failed to save runtime status configuration',
52+
error_code: :invalid_runtime_status_configuration,
53+
details: db_configs.errors
54+
)
6255
end
6356

6457
unless db_status.save
65-
t.rollback_and_return ServiceResponse.error(
58+
t.rollback_and_return! ServiceResponse.error(
6659
message: 'Failed to save runtime status',
6760
error_code: :invalid_runtime_status,
6861
details: db_status.errors

db/migrate/20251216161818_add_detailed_runtime_status.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def change
1111
t.integer :status_type, null: false, default: 0
1212
t.datetime_with_timezone :last_heartbeat
1313
t.text :identifier, null: false
14-
t.text :feature_set, array: true, default: [], null: false
14+
t.text :features, array: true, default: [], null: false
1515

1616
t.timestamps_with_timezone
1717
end

db/structure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ CREATE TABLE runtime_statuses (
750750
status_type integer DEFAULT 0 NOT NULL,
751751
last_heartbeat timestamp with time zone,
752752
identifier text NOT NULL,
753-
feature_set text[] DEFAULT '{}'::text[] NOT NULL,
753+
features text[] DEFAULT '{}'::text[] NOT NULL,
754754
created_at timestamp with time zone NOT NULL,
755755
updated_at timestamp with time zone NOT NULL
756756
);

spec/factories/runtime_status.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
last_heartbeat { Time.zone.today }
77
status_type { :adapter }
88
identifier { SecureRandom.uuid }
9-
feature_set { [] }
9+
features { [] }
1010
runtime
1111
end
1212
end

0 commit comments

Comments
 (0)