Skip to content

Commit 371f81e

Browse files
authored
Merge pull request #780 from code0-tech/615-last-seen-online-field-for-runtime
Detailed statuses for runtimes
2 parents 0aa9865 + 4cf34f1 commit 371f81e

49 files changed

Lines changed: 788 additions & 30 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeConnectionStatusEnum < BaseEnum
5+
description 'Represent all available aquila statuses'
6+
7+
value :CONNECTED, 'No problem with the connection to aquila', value: :connected
8+
value :DISCONNECTED, 'The runtime is disconnected, cause unknown', value: :disconnected
9+
end
10+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeFeatureType < Types::BaseObject
5+
description 'Represents a runtime feature'
6+
7+
authorize :read_runtime
8+
9+
field :runtime_status, Types::RuntimeStatusType,
10+
null: false, description: 'The runtime status this feature belongs to'
11+
12+
field :descriptions, [Types::TranslationType], null: true, description: 'Description of the function'
13+
field :names, [Types::TranslationType], null: true, description: 'Name of the function'
14+
15+
id_field RuntimeFeature
16+
timestamps
17+
end
18+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeStatusConfigurationEndpointType < Types::BaseObject
5+
description 'Detailed information about a runtime status'
6+
7+
authorize :read_runtime
8+
9+
field :endpoint, String, null: false, description: 'The endpoint URL of the runtime'
10+
11+
id_field ::RuntimeStatusConfiguration
12+
timestamps
13+
end
14+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeStatusConfigurationType < Types::BaseUnion
5+
description 'Detailed configuration about a runtime status, either: endpoint, ...'
6+
7+
possible_types Types::RuntimeStatusConfigurationEndpointType
8+
9+
def self.resolve_type(object, _context)
10+
return Types::RuntimeStatusConfigurationEndpointType if object.endpoint.present?
11+
12+
raise "Unknown RuntimeStatusInformation type: #{object.class.name}"
13+
end
14+
end
15+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeStatusStatusEnum < Types::BaseEnum
5+
description 'The enum status of the detailed status'
6+
7+
value :NOT_RESPONDING, 'The runtime is not responding to heartbeats', value: 'not_responding'
8+
value :NOT_READY, 'The runtime is not ready to compute stuff', value: 'not_ready'
9+
value :RUNNING, 'The runtime is running and healthy', value: 'running'
10+
value :STOPPED, 'The runtime has been stopped', value: 'stopped'
11+
end
12+
end
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
# frozen_string_literal: true
22

33
module Types
4-
class RuntimeStatusType < BaseEnum
5-
description 'Represent all available types of statuses of a runtime'
4+
class RuntimeStatusType < Types::BaseObject
5+
description 'A runtime status information entry'
66

7-
value :CONNECTED, 'No problem with connection, everything works as expected', value: 'connected'
8-
value :DISCONNECTED, 'The runtime is disconnected, cause unknown', value: 'disconnected'
7+
authorize :read_runtime
8+
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'
16+
field :last_heartbeat, Types::TimeType,
17+
null: true,
18+
description: 'The timestamp of the last heartbeat received from the runtime'
19+
field :runtime_features, [Types::RuntimeFeatureType],
20+
null: false,
21+
description: 'The set of features supported by the runtime'
22+
field :status, Types::RuntimeStatusStatusEnum,
23+
null: false,
24+
description: 'The current status of the runtime (e.g. running, stopped)'
25+
field :type, Types::RuntimeStatusTypeEnum,
26+
null: false,
27+
description: 'The type of runtime status information (e.g. adapter, execution)',
28+
method: :status_type
29+
30+
id_field RuntimeStatus
31+
timestamps
932
end
1033
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class RuntimeStatusTypeEnum < Types::BaseEnum
5+
description 'The type of runtime status'
6+
7+
value :ADAPTER, 'Indicates that the runtime status is related to an adapter.', value: 'adapter'
8+
value :EXECUTION, 'Indicates that the runtime status is related to an execution.', value: 'execution'
9+
end
10+
end

app/graphql/types/runtime_type.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class RuntimeType < Types::BaseObject
1616
field :namespace, Types::NamespaceType, null: true, description: 'The parent namespace for the runtime'
1717
field :projects, Types::NamespaceProjectType.connection_type, null: false,
1818
description: 'Projects associated with the runtime'
19-
field :status, Types::RuntimeStatusType, null: false, description: 'The status of the runtime'
19+
field :status, Types::RuntimeConnectionStatusEnum, null: false, description: 'The status of the runtime'
2020

21+
field :statuses, Types::RuntimeStatusType.connection_type, null: false,
22+
description: 'Statuses of the runtime',
23+
method: :runtime_statuses
2124
field :token, String, null: true, description: 'Token belonging to the runtime, only present on creation'
2225

2326
expose_abilities %i[
@@ -29,6 +32,17 @@ class RuntimeType < Types::BaseObject
2932
id_field Runtime
3033
timestamps
3134

35+
# If the last heartbeat was within the last 10 minutes, consider the runtime as 'running'
36+
def status
37+
last_heartbeat = object.last_heartbeat
38+
39+
if last_heartbeat && last_heartbeat >= 10.minutes.ago
40+
:connected
41+
else
42+
:disconnected
43+
end
44+
end
45+
3246
def token
3347
object.token if object.token_previously_changed?
3448
end

app/grpc/concerns/grpc_stream_handler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def create_enumerator(clazz, method, runtime_id, _call)
8686

8787
begin
8888
y << item
89+
Runtime.update(runtime_id, last_heartbeat: Time.zone.now)
8990
rescue GRPC::Core::CallError
9091
logger.info(message: 'Stream was closed from client side (probably)')
9192
clazz.try("#{method}_died", runtime_id)

app/grpc/flow_handler.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ def self.update_runtime(runtime)
2626
end
2727

2828
def self.update_started(runtime_id)
29-
runtime = Runtime.find(runtime_id)
30-
runtime.connected!
31-
runtime.save
29+
runtime = Runtime.find_by(id: runtime_id)
30+
return if runtime.nil?
3231

3332
logger.info(message: 'Runtime connected', runtime_id: runtime.id)
3433

3534
update_runtime(runtime)
3635
end
3736

38-
def self.update_died(runtime_id)
39-
runtime = Runtime.find(runtime_id)
40-
runtime.disconnected!
41-
runtime.save
42-
end
43-
4437
def self.encoders = { update: ->(grpc_object) { Tucana::Sagittarius::FlowResponse.encode(grpc_object) } }
4538

4639
def self.decoders = { update: ->(string) { Tucana::Sagittarius::FlowResponse.decode(string) } }

0 commit comments

Comments
 (0)