Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/graphql/types/action_status_configuration_endpoint_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Types
class ActionStatusConfigurationEndpointType < Types::BaseObject
description 'Detailed information about an action status'

authorize :read_runtime

field :endpoint, String, null: true, description: 'The endpoint URL of the action'
field :flow_type_identifiers, [String],
null: false,
description: 'The flow type identifiers handled by this configuration'

id_field ActionStatusConfiguration
timestamps
end
end
33 changes: 33 additions & 0 deletions app/graphql/types/action_status_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Types
class ActionStatusType < Types::BaseObject
description 'An action status information entry'

authorize :read_runtime

field :configurations, Types::RuntimeStatusConfigurationType.connection_type,
null: false,
description: 'The detailed configuration entries for this action status',
method: :action_status_configurations
field :identifier, String,
null: false,
description: 'The unique identifier for this action status'
field :last_heartbeat, Types::TimeType,
null: true,
description: 'The timestamp of the last heartbeat received from the runtime'
field :status, Types::RuntimeStatusStatusEnum,
null: false,
description: 'The current action status'
field :type, Types::RuntimeStatusTypeEnum,
null: false,
description: 'The type of runtime status information'

def type
:action
end

id_field ActionStatus
timestamps
end
end
33 changes: 33 additions & 0 deletions app/graphql/types/adapter_runtime_status_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Types
class AdapterRuntimeStatusType < Types::BaseObject
description 'An adapter runtime status information entry'

authorize :read_runtime

field :configurations, Types::RuntimeStatusConfigurationType.connection_type,
null: false,
description: 'The detailed configuration entries for this adapter status',
method: :adapter_status_configurations
field :identifier, String,
null: false,
description: 'The unique identifier for this adapter status'
field :last_heartbeat, Types::TimeType,
null: true,
description: 'The timestamp of the last heartbeat received from the runtime'
field :status, Types::RuntimeStatusStatusEnum,
null: false,
description: 'The current adapter status'
field :type, Types::RuntimeStatusTypeEnum,
null: false,
description: 'The type of runtime status information'

def type
:adapter
end

id_field AdapterRuntimeStatus
timestamps
end
end
17 changes: 17 additions & 0 deletions app/graphql/types/adapter_status_configuration_endpoint_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Types
class AdapterStatusConfigurationEndpointType < Types::BaseObject
description 'Detailed information about an adapter status'

authorize :read_runtime

field :endpoint, String, null: true, description: 'The endpoint URL of the adapter'
field :flow_type_identifiers, [String],
null: false,
description: 'The flow type identifiers handled by this configuration'

id_field ::AdapterStatusConfiguration
timestamps
end
end
29 changes: 29 additions & 0 deletions app/graphql/types/execution_runtime_status_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Types
class ExecutionRuntimeStatusType < Types::BaseObject
description 'An execution runtime status information entry'

authorize :read_runtime

field :identifier, String,
null: false,
description: 'The unique identifier for this execution status'
field :last_heartbeat, Types::TimeType,
null: true,
description: 'The timestamp of the last heartbeat received from the runtime'
field :status, Types::RuntimeStatusStatusEnum,
null: false,
description: 'The current execution status'
field :type, Types::RuntimeStatusTypeEnum,
null: false,
description: 'The type of runtime status information'

def type
:execution
end

id_field ExecutionRuntimeStatus
timestamps
end
end
14 changes: 0 additions & 14 deletions app/graphql/types/runtime_status_configuration_endpoint_type.rb

This file was deleted.

5 changes: 3 additions & 2 deletions app/graphql/types/runtime_status_configuration_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ module Types
class RuntimeStatusConfigurationType < Types::BaseUnion
description 'Detailed configuration about a runtime status, either: endpoint, ...'

possible_types Types::RuntimeStatusConfigurationEndpointType
possible_types Types::ActionStatusConfigurationEndpointType, Types::AdapterStatusConfigurationEndpointType

def self.resolve_type(object, _context)
return Types::RuntimeStatusConfigurationEndpointType if object.endpoint.present?
return Types::AdapterStatusConfigurationEndpointType if object.is_a?(AdapterStatusConfiguration)
return Types::ActionStatusConfigurationEndpointType if object.is_a?(ActionStatusConfiguration)

raise "Unknown RuntimeStatusInformation type: #{object.class.name}"
end
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/runtime_status_status_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Types
class RuntimeStatusStatusEnum < Types::BaseEnum
description 'The enum status of the detailed status'

value :UNKNOWN, 'The runtime status is unknown', value: 'unknown'
value :NOT_RESPONDING, 'The runtime is not responding to heartbeats', value: 'not_responding'
value :NOT_READY, 'The runtime is not ready to compute stuff', value: 'not_ready'
value :RUNNING, 'The runtime is running and healthy', value: 'running'
Expand Down
36 changes: 14 additions & 22 deletions app/graphql/types/runtime_status_type.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
# frozen_string_literal: true

module Types
class RuntimeStatusType < Types::BaseObject
class RuntimeStatusType < Types::BaseUnion
description 'A runtime status information entry'

authorize :read_runtime
possible_types Types::ActionStatusType, Types::AdapterRuntimeStatusType, Types::ExecutionRuntimeStatusType

field :configurations, Types::RuntimeStatusConfigurationType.connection_type,
null: false,
description: 'The detailed configuration entries for this runtime status (only for adapters)',
method: :runtime_status_configurations
field :identifier, String,
null: false,
description: 'The unique identifier for this runtime status'
field :last_heartbeat, Types::TimeType,
null: true,
description: 'The timestamp of the last heartbeat received from the runtime'
field :status, Types::RuntimeStatusStatusEnum,
null: false,
description: 'The current status of the runtime (e.g. running, stopped)'
field :type, Types::RuntimeStatusTypeEnum,
null: false,
description: 'The type of runtime status information (e.g. adapter, execution)',
method: :status_type

id_field RuntimeStatus
timestamps
def self.resolve_type(object, _context)
case object
when ActionStatus
Types::ActionStatusType
when AdapterRuntimeStatus
Types::AdapterRuntimeStatusType
when ExecutionRuntimeStatus
Types::ExecutionRuntimeStatusType
else
raise "Unknown RuntimeStatus type: #{object.class.name}"
end
end
end
end
1 change: 1 addition & 0 deletions app/graphql/types/runtime_status_type_enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class RuntimeStatusTypeEnum < Types::BaseEnum
description 'The type of runtime status'

value :ADAPTER, 'Indicates that the runtime status is related to an adapter.', value: 'adapter'
value :ACTION, 'Indicates that the runtime status is related to an action.', value: 'action'
value :EXECUTION, 'Indicates that the runtime status is related to an execution.', value: 'execution'
end
end
3 changes: 1 addition & 2 deletions app/graphql/types/runtime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class RuntimeType < Types::BaseObject
field :status, Types::RuntimeConnectionStatusEnum, null: false, description: 'The status of the runtime'

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

expose_abilities %i[
Expand Down
4 changes: 3 additions & 1 deletion app/grpc/runtime_status_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def update(request, _call)
request.adapter_runtime_status
when :execution_runtime_status
request.execution_runtime_status
when :action_status
request.action_status
else
return Tucana::Sagittarius::RuntimeStatusUpdateResponse.new(success: false)
end
Expand All @@ -20,7 +22,7 @@ def update(request, _call)
status_info: status_info
).execute

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

Tucana::Sagittarius::RuntimeStatusUpdateResponse.new(success: response.success?)
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/action_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class ActionStatus < ApplicationRecord
include RuntimeStatusFields

has_many :action_status_configurations, inverse_of: :action_status, dependent: :destroy

def configurations
action_status_configurations
end
end
5 changes: 5 additions & 0 deletions app/models/action_status_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ActionStatusConfiguration < ApplicationRecord
belongs_to :action_status, inverse_of: :action_status_configurations
end
11 changes: 11 additions & 0 deletions app/models/adapter_runtime_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class AdapterRuntimeStatus < ApplicationRecord
include RuntimeStatusFields

has_many :adapter_status_configurations, inverse_of: :adapter_runtime_status, dependent: :destroy

def configurations
adapter_status_configurations
end
end
5 changes: 5 additions & 0 deletions app/models/adapter_status_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class AdapterStatusConfiguration < ApplicationRecord
belongs_to :adapter_runtime_status, inverse_of: :adapter_status_configurations
end
23 changes: 23 additions & 0 deletions app/models/concerns/runtime_status_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module RuntimeStatusFields
extend ActiveSupport::Concern

STATUS_TYPES = {
unknown: 0,
not_responding: 1,
not_ready: 2,
running: 3,
stopped: 4,
}.with_indifferent_access

included do
belongs_to :runtime, inverse_of: model_name.collection.to_sym

enum :status, STATUS_TYPES, default: :unknown

validates :identifier, presence: true,
allow_blank: false,
uniqueness: { case_sensitive: false, scope: :runtime_id }
end
end
5 changes: 5 additions & 0 deletions app/models/execution_runtime_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ExecutionRuntimeStatus < ApplicationRecord
include RuntimeStatusFields
end
12 changes: 11 additions & 1 deletion app/models/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ class Runtime < ApplicationRecord

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

has_many :runtime_statuses, inverse_of: :runtime
has_many :adapter_runtime_statuses, inverse_of: :runtime
has_many :execution_runtime_statuses, inverse_of: :runtime
has_many :action_statuses, inverse_of: :runtime

def statuses
[
*adapter_runtime_statuses,
*execution_runtime_statuses,
*action_statuses
].sort_by(&:created_at)
end

has_many :project_assignments, class_name: 'NamespaceProjectRuntimeAssignment', inverse_of: :runtime
has_many :projects, class_name: 'NamespaceProject', through: :project_assignments, source: :namespace_project,
Expand Down
37 changes: 0 additions & 37 deletions app/models/runtime_status.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/models/runtime_status_configuration.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/policies/action_status_configuration_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ActionStatusConfigurationPolicy < BasePolicy
delegate { subject.action_status }
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class RuntimeStatusPolicy < BasePolicy
class ActionStatusPolicy < BasePolicy
delegate { subject.runtime }
end
Loading