Class: CallRecordSwitchvoxImporterCloudStorage
- Inherits:
-
Object
- Object
- CallRecordSwitchvoxImporterCloudStorage
- Defined in:
- app/services/call_record_switchvox_importer_cloud_storage.rb
Overview
Imports Switchvox call recordings from R2/S3-compatible object storage.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#object_store ⇒ Object
readonly
Returns the value of attribute object_store.
Instance Method Summary collapse
- #import_file(key) ⇒ Object
- #import_new_records(limit = nil) ⇒ Object
-
#initialize(options = {}) ⇒ CallRecordSwitchvoxImporterCloudStorage
constructor
A new instance of CallRecordSwitchvoxImporterCloudStorage.
Constructor Details
#initialize(options = {}) ⇒ CallRecordSwitchvoxImporterCloudStorage
Returns a new instance of CallRecordSwitchvoxImporterCloudStorage.
10 11 12 13 14 |
# File 'app/services/call_record_switchvox_importer_cloud_storage.rb', line 10 def initialize( = {}) @options = @logger = [:logger] || Rails.logger @object_store = [:object_store] || CallRecordSwitchvoxObjectStore.from_configuration end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'app/services/call_record_switchvox_importer_cloud_storage.rb', line 8 def logger @logger end |
#object_store ⇒ Object (readonly)
Returns the value of attribute object_store.
8 9 10 |
# File 'app/services/call_record_switchvox_importer_cloud_storage.rb', line 8 def object_store @object_store end |
Instance Method Details
#import_file(key) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/call_record_switchvox_importer_cloud_storage.rb', line 34 def import_file(key) normalized_key = key.delete_prefix('r2://') xml_key = normalized_key.sub(/\.wav\z/i, '.xml') logger.info "Processing object-store call recording #{normalized_key}" with_workspace do |tmpdir| local_wav_path = download_import_pair(normalized_key, xml_key, tmpdir) result = import_downloaded_file(tmpdir, local_wav_path, normalized_key) archive_import(normalized_key, xml_key, result) result end end |
#import_new_records(limit = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/call_record_switchvox_importer_cloud_storage.rb', line 16 def import_new_records(limit = nil) limit ||= @options[:limit] logger.info 'Retrieving object-store call-recording keys to process' file_keys = object_store.importable_wav_keys logger.info "Detected #{file_keys.length} object-store record(s) to process. File limit set to #{limit}" file_keys.each_with_index do |key, i| break if limit.present? && i >= limit if immediate_import?(limit) import_file(key) else enqueue_import(key) end end end |