Class: SpreeCmCommissioner::WaitingRoomSystemMetadataFetcher
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::WaitingRoomSystemMetadataFetcher
- Defined in:
- app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb
Instance Attribute Summary collapse
-
#document_data ⇒ Object
readonly
Returns the value of attribute document_data.
Class Method Summary collapse
- .compute_max_sessions_count_with_min(server_running_count:, max_thread_count:, multiplier:, cap:) ⇒ Object
- .min_sessions_count ⇒ Object
Instance Method Summary collapse
- #document ⇒ Object
- #firestore ⇒ Object
-
#initialize(firestore: nil) ⇒ WaitingRoomSystemMetadataFetcher
constructor
A new instance of WaitingRoomSystemMetadataFetcher.
- #load_document_data ⇒ Object
-
#max_sessions_count_cap ⇒ Object
hard ceiling for max_sessions_count to avoid auto-scaling the system too much.
- #max_sessions_count_with_min ⇒ Object
- #max_thread_count ⇒ Object
-
#multiplier ⇒ Object
percentage.
-
#server_running_count ⇒ Object
firebase metadata.
- #service_account ⇒ Object
Constructor Details
#initialize(firestore: nil) ⇒ WaitingRoomSystemMetadataFetcher
Returns a new instance of WaitingRoomSystemMetadataFetcher.
7 8 9 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 7 def initialize(firestore: nil) @firestore = firestore if firestore.present? end |
Instance Attribute Details
#document_data ⇒ Object (readonly)
Returns the value of attribute document_data.
5 6 7 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 5 def document_data @document_data end |
Class Method Details
.compute_max_sessions_count_with_min(server_running_count:, max_thread_count:, multiplier:, cap:) ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 19 def self.compute_max_sessions_count_with_min(server_running_count:, max_thread_count:, multiplier:, cap:) min = min_sessions_count max = server_running_count * max_thread_count * multiplier / 100 # Cap the auto-scaled value so the system does not scale beyond the configured ceiling, # while ensuring the minimum always wins even if the cap is set below it. max.clamp(min, [cap, min].max) end |
.min_sessions_count ⇒ Object
15 16 17 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 15 def self.min_sessions_count ENV.fetch('WAITING_ROOM_MIN_SESSIONS_COUNT', '5').to_i end |
Instance Method Details
#document ⇒ Object
56 57 58 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 56 def document @document ||= firestore.col('metadata').doc('system') end |
#firestore ⇒ Object
60 61 62 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 60 def firestore @firestore ||= Google::Cloud::Firestore.new(project_id: service_account[:project_id], credentials: service_account) end |
#load_document_data ⇒ Object
11 12 13 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 11 def load_document_data @document_data = document.get.data end |
#max_sessions_count_cap ⇒ Object
hard ceiling for max_sessions_count to avoid auto-scaling the system too much
52 53 54 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 52 def max_sessions_count_cap document_data[:max_sessions_count_cap]&.to_i || ENV.fetch('WAITING_ROOM_MAX_SESSIONS_COUNT_CAP', '1000').to_i end |
#max_sessions_count_with_min ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 27 def max_sessions_count_with_min @max_sessions_count_with_min ||= self.class.compute_max_sessions_count_with_min( server_running_count: server_running_count, max_thread_count: max_thread_count, multiplier: multiplier, cap: max_sessions_count_cap ) end |
#max_thread_count ⇒ Object
42 43 44 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 42 def max_thread_count document_data[:max_thread_count]&.to_i || ENV.fetch('WAITING_ROOM_MAX_THREAD_COUNT', '10').to_i end |
#multiplier ⇒ Object
percentage
47 48 49 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 47 def multiplier document_data[:multiplier]&.to_i || ENV.fetch('WAITING_ROOM_MULTIPLIER', '150').to_i end |
#server_running_count ⇒ Object
firebase metadata
38 39 40 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 38 def server_running_count document_data[:server_running_count]&.to_i || ENV.fetch('WAITING_ROOM_SERVERS_COUNT', '2').to_i end |
#service_account ⇒ Object
64 65 66 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 64 def service_account @service_account ||= Rails.application.credentials.cloud_firestore_service_account end |