From a399ab1d54e090fe17f5b8b592a172c8b46df67c Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Fri, 3 Jul 2026 21:40:43 +0200 Subject: [PATCH] Make runtime status timeout configurable --- app/graphql/mutations/application_settings/update.rb | 3 +++ app/graphql/types/application_settings_type.rb | 4 ++++ app/graphql/types/runtime_type.rb | 3 ++- app/models/application_setting.rb | 6 ++++++ db/fixtures/01_application_settings.rb | 5 +++++ docs/graphql/mutation/applicationsettingsupdate.md | 1 + docs/graphql/object/applicationsettings.md | 1 + spec/graphql/types/application_settings_type_spec.rb | 1 + 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/graphql/mutations/application_settings/update.rb b/app/graphql/mutations/application_settings/update.rb index a3fef767..121ce51a 100644 --- a/app/graphql/mutations/application_settings/update.rb +++ b/app/graphql/mutations/application_settings/update.rb @@ -25,6 +25,9 @@ class Update < BaseMutation argument :privacy_url, String, required: false, description: 'Set the URL to the privacy policy page.' + argument :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int, + required: false, + description: 'Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat' argument :terms_and_conditions_url, String, required: false, description: 'Set the URL to the terms and conditions page.' diff --git a/app/graphql/types/application_settings_type.rb b/app/graphql/types/application_settings_type.rb index a4865ff3..8434eecf 100644 --- a/app/graphql/types/application_settings_type.rb +++ b/app/graphql/types/application_settings_type.rb @@ -32,5 +32,9 @@ class ApplicationSettingsType < Types::BaseObject field :identity_providers, Types::IdentityProviderType.connection_type, null: false, description: 'List of configured identity providers' + + field :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int, + null: false, + description: 'The maximum amount of minutes a runtime is shown as connected after the last heartbeat' end end diff --git a/app/graphql/types/runtime_type.rb b/app/graphql/types/runtime_type.rb index 02f089d5..3c2a44fc 100644 --- a/app/graphql/types/runtime_type.rb +++ b/app/graphql/types/runtime_type.rb @@ -33,7 +33,8 @@ class RuntimeType < Types::BaseObject def status last_heartbeat = object.last_heartbeat - if last_heartbeat && last_heartbeat >= 10.minutes.ago + max_heartbeat_interval = ApplicationSetting.current[:runtime_max_heartbeat_interval_minutes] + if last_heartbeat && last_heartbeat >= max_heartbeat_interval.minutes.ago :connected else :disconnected diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index c29321de..c7103253 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -18,10 +18,12 @@ class MissingApplicationSettings < StandardError terms_and_conditions_url: 5, privacy_url: 6, legal_notice_url: 7, + runtime_max_heartbeat_interval_minutes: 8, }.with_indifferent_access BOOLEAN_OPTIONS = %i[user_registration_enabled organization_creation_restricted admin_status_visible].freeze URL_OPTIONS = %i[terms_and_conditions_url privacy_url legal_notice_url].freeze + NUMBER_OPTIONS = %i[runtime_max_heartbeat_interval_minutes].freeze enum :setting, SETTINGS @@ -46,6 +48,10 @@ class MissingApplicationSettings < StandardError if: :"#{option}?" end + NUMBER_OPTIONS.each do |option| + validates :value, numericality: true, if: :"#{option}?" + end + def validate_value return if URL_OPTIONS.map(&:to_s).include?(setting) && value.nil? diff --git a/db/fixtures/01_application_settings.rb b/db/fixtures/01_application_settings.rb index 11c5213c..19c9487d 100644 --- a/db/fixtures/01_application_settings.rb +++ b/db/fixtures/01_application_settings.rb @@ -34,3 +34,8 @@ s.setting = :legal_notice_url s.value = nil end + +ApplicationSetting.seed_once :setting do |s| + s.setting = :runtime_max_heartbeat_interval_minutes + s.value = 10 +end diff --git a/docs/graphql/mutation/applicationsettingsupdate.md b/docs/graphql/mutation/applicationsettingsupdate.md index c84d54fc..b9a55f17 100644 --- a/docs/graphql/mutation/applicationsettingsupdate.md +++ b/docs/graphql/mutation/applicationsettingsupdate.md @@ -14,6 +14,7 @@ Update application settings. | `legalNoticeUrl` | [`String`](../scalar/string.md) | Set the URL to the legal notice page. | | `organizationCreationRestricted` | [`Boolean`](../scalar/boolean.md) | Set if organization creation is restricted to administrators. | | `privacyUrl` | [`String`](../scalar/string.md) | Set the URL to the privacy policy page. | +| `runtimeMaxHeartbeatIntervalMinutes` | [`Int`](../scalar/int.md) | Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat | | `termsAndConditionsUrl` | [`String`](../scalar/string.md) | Set the URL to the terms and conditions page. | | `userRegistrationEnabled` | [`Boolean`](../scalar/boolean.md) | Set if user registration is enabled. | diff --git a/docs/graphql/object/applicationsettings.md b/docs/graphql/object/applicationsettings.md index 083e81bc..78f22a52 100644 --- a/docs/graphql/object/applicationsettings.md +++ b/docs/graphql/object/applicationsettings.md @@ -13,5 +13,6 @@ Represents the application settings | `legalNoticeUrl` | [`String`](../scalar/string.md) | URL to the legal notice page | | `organizationCreationRestricted` | [`Boolean!`](../scalar/boolean.md) | Shows if organization creation is restricted to administrators | | `privacyUrl` | [`String`](../scalar/string.md) | URL to the privacy policy page | +| `runtimeMaxHeartbeatIntervalMinutes` | [`Int!`](../scalar/int.md) | The maximum amount of minutes a runtime is shown as connected after the last heartbeat | | `termsAndConditionsUrl` | [`String`](../scalar/string.md) | URL to the terms and conditions page | | `userRegistrationEnabled` | [`Boolean!`](../scalar/boolean.md) | Shows if user registration is enabled | diff --git a/spec/graphql/types/application_settings_type_spec.rb b/spec/graphql/types/application_settings_type_spec.rb index 6940aa12..c2bbe747 100644 --- a/spec/graphql/types/application_settings_type_spec.rb +++ b/spec/graphql/types/application_settings_type_spec.rb @@ -12,6 +12,7 @@ termsAndConditionsUrl privacyUrl legalNoticeUrl + runtimeMaxHeartbeatIntervalMinutes ] end