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:) ⇒ 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_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:) ⇒ Object
15 16 17 18 19 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 15 def self.compute_max_sessions_count_with_min(server_running_count:, max_thread_count:, multiplier:) min = ENV.fetch('WAITING_ROOM_MIN_SESSIONS_COUNT', '5').to_i max = server_running_count * max_thread_count * multiplier / 100 [max, min].max end |
Instance Method Details
#document ⇒ Object
44 45 46 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 44 def document @document ||= firestore.col('metadata').doc('system') end |
#firestore ⇒ Object
48 49 50 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 48 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_with_min ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 21 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 ) end |
#max_thread_count ⇒ Object
35 36 37 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 35 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
40 41 42 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 40 def multiplier document_data[:multiplier]&.to_i || ENV.fetch('WAITING_ROOM_MULTIPLIER', '150').to_i end |
#server_running_count ⇒ Object
firebase metadata
31 32 33 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 31 def server_running_count document_data[:server_running_count]&.to_i || ENV.fetch('WAITING_ROOM_SERVERS_COUNT', '2').to_i end |
#service_account ⇒ Object
52 53 54 |
# File 'app/services/spree_cm_commissioner/waiting_room_system_metadata_fetcher.rb', line 52 def service_account @service_account ||= Rails.application.credentials.cloud_firestore_service_account end |