Class: Teems::Services::SyncEngine
- Inherits:
-
Object
- Object
- Teems::Services::SyncEngine
- Includes:
- SyncPagination, SyncSerializer
- Defined in:
- lib/teems/services/sync_engine.rb
Overview
Core sync logic: fetch, merge, and write chat messages. Extracted from Commands::Sync to keep the command thin.
Constant Summary
Constants included from SyncPagination
Teems::Services::SyncPagination::API_DELAY_SECONDS, Teems::Services::SyncPagination::MAX_PAGES
Instance Method Summary collapse
-
#fetch_all_messages(chat_id, start_time) ⇒ Object
Fetch all messages from a chat since start_time with pagination.
-
#initialize(runner:, sync_store:, state:, output:) ⇒ SyncEngine
constructor
A new instance of SyncEngine.
- #merge_and_write(chat, existing_raw, new_messages) ⇒ Object
- #message_from_stored(data) ⇒ Object
Constructor Details
#initialize(runner:, sync_store:, state:, output:) ⇒ SyncEngine
Returns a new instance of SyncEngine.
130 131 132 133 134 135 |
# File 'lib/teems/services/sync_engine.rb', line 130 def initialize(runner:, sync_store:, state:, output:) @runner = runner @sync_store = sync_store @state = state @output = output end |
Instance Method Details
#fetch_all_messages(chat_id, start_time) ⇒ Object
Fetch all messages from a chat since start_time with pagination
138 139 140 141 |
# File 'lib/teems/services/sync_engine.rb', line 138 def (chat_id, start_time) = (chat_id, start_time) (, start_time) end |
#merge_and_write(chat, existing_raw, new_messages) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/teems/services/sync_engine.rb', line 143 def merge_and_write(chat, existing_raw, ) existing = existing_raw.map { |data| (data) } = (existing, ) write_chat_files(chat, ) end |