Skip to content

Commit a399ab1

Browse files
committed
Make runtime status timeout configurable
1 parent 02160bf commit a399ab1

8 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/graphql/mutations/application_settings/update.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Update < BaseMutation
2525
argument :privacy_url, String,
2626
required: false,
2727
description: 'Set the URL to the privacy policy page.'
28+
argument :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int,
29+
required: false,
30+
description: 'Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat'
2831
argument :terms_and_conditions_url, String,
2932
required: false,
3033
description: 'Set the URL to the terms and conditions page.'

app/graphql/types/application_settings_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ class ApplicationSettingsType < Types::BaseObject
3232
field :identity_providers, Types::IdentityProviderType.connection_type,
3333
null: false,
3434
description: 'List of configured identity providers'
35+
36+
field :runtime_max_heartbeat_interval_minutes, GraphQL::Types::Int,
37+
null: false,
38+
description: 'The maximum amount of minutes a runtime is shown as connected after the last heartbeat'
3539
end
3640
end

app/graphql/types/runtime_type.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class RuntimeType < Types::BaseObject
3333
def status
3434
last_heartbeat = object.last_heartbeat
3535

36-
if last_heartbeat && last_heartbeat >= 10.minutes.ago
36+
max_heartbeat_interval = ApplicationSetting.current[:runtime_max_heartbeat_interval_minutes]
37+
if last_heartbeat && last_heartbeat >= max_heartbeat_interval.minutes.ago
3738
:connected
3839
else
3940
:disconnected

app/models/application_setting.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class MissingApplicationSettings < StandardError
1818
terms_and_conditions_url: 5,
1919
privacy_url: 6,
2020
legal_notice_url: 7,
21+
runtime_max_heartbeat_interval_minutes: 8,
2122
}.with_indifferent_access
2223

2324
BOOLEAN_OPTIONS = %i[user_registration_enabled organization_creation_restricted admin_status_visible].freeze
2425
URL_OPTIONS = %i[terms_and_conditions_url privacy_url legal_notice_url].freeze
26+
NUMBER_OPTIONS = %i[runtime_max_heartbeat_interval_minutes].freeze
2527

2628
enum :setting, SETTINGS
2729

@@ -46,6 +48,10 @@ class MissingApplicationSettings < StandardError
4648
if: :"#{option}?"
4749
end
4850

51+
NUMBER_OPTIONS.each do |option|
52+
validates :value, numericality: true, if: :"#{option}?"
53+
end
54+
4955
def validate_value
5056
return if URL_OPTIONS.map(&:to_s).include?(setting) && value.nil?
5157

db/fixtures/01_application_settings.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@
3434
s.setting = :legal_notice_url
3535
s.value = nil
3636
end
37+
38+
ApplicationSetting.seed_once :setting do |s|
39+
s.setting = :runtime_max_heartbeat_interval_minutes
40+
s.value = 10
41+
end

docs/graphql/mutation/applicationsettingsupdate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Update application settings.
1414
| `legalNoticeUrl` | [`String`](../scalar/string.md) | Set the URL to the legal notice page. |
1515
| `organizationCreationRestricted` | [`Boolean`](../scalar/boolean.md) | Set if organization creation is restricted to administrators. |
1616
| `privacyUrl` | [`String`](../scalar/string.md) | Set the URL to the privacy policy page. |
17+
| `runtimeMaxHeartbeatIntervalMinutes` | [`Int`](../scalar/int.md) | Set the maximum amount of minutes a runtime is shown as connected after the last heartbeat |
1718
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | Set the URL to the terms and conditions page. |
1819
| `userRegistrationEnabled` | [`Boolean`](../scalar/boolean.md) | Set if user registration is enabled. |
1920

docs/graphql/object/applicationsettings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Represents the application settings
1313
| `legalNoticeUrl` | [`String`](../scalar/string.md) | URL to the legal notice page |
1414
| `organizationCreationRestricted` | [`Boolean!`](../scalar/boolean.md) | Shows if organization creation is restricted to administrators |
1515
| `privacyUrl` | [`String`](../scalar/string.md) | URL to the privacy policy page |
16+
| `runtimeMaxHeartbeatIntervalMinutes` | [`Int!`](../scalar/int.md) | The maximum amount of minutes a runtime is shown as connected after the last heartbeat |
1617
| `termsAndConditionsUrl` | [`String`](../scalar/string.md) | URL to the terms and conditions page |
1718
| `userRegistrationEnabled` | [`Boolean!`](../scalar/boolean.md) | Shows if user registration is enabled |

spec/graphql/types/application_settings_type_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
termsAndConditionsUrl
1313
privacyUrl
1414
legalNoticeUrl
15+
runtimeMaxHeartbeatIntervalMinutes
1516
]
1617
end
1718

0 commit comments

Comments
 (0)