Class: VendorsService::GoogleReserve::AvailabilityFeeds::UploaderService
- Inherits:
-
Object
- Object
- VendorsService::GoogleReserve::AvailabilityFeeds::UploaderService
- Includes:
- ElasticAPM::SpanHelpers, Concerns::FeedUploader
- Defined in:
- app/services/vendors_service/google_reserve/availability_feeds/uploader_service.rb
Overview
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
Constant Summary collapse
- MAX_RETRIES =
12- MAX_FEED_SIZE_MB =
Google's maximum feed size limit in MB
190- UPLOAD_RESCHEDULE_DELAY_MINUTES =
Delay before rescheduling upload retry
15
Instance Method Summary collapse
-
#call ⇒ Object
Aggregates fragments for this specific shard and uploads to Google SFTP.
-
#initialize(restaurant_ids, shard_number, generation_timestamp, retry_count = 0) ⇒ UploaderService
constructor
A new instance of UploaderService.
Constructor Details
#initialize(restaurant_ids, shard_number, generation_timestamp, retry_count = 0) ⇒ UploaderService
Returns a new instance of UploaderService.
28 29 30 31 32 33 34 35 |
# File 'app/services/vendors_service/google_reserve/availability_feeds/uploader_service.rb', line 28 def initialize(restaurant_ids, shard_number, , retry_count = 0) # Convert single restaurant_id to array for consistent handling @restaurant_ids = Array(restaurant_ids) @shard_number = shard_number @retry_count = retry_count || 0 @generation_timestamp = @shard_paths = nil # Will store paths for this specific shard end |
Instance Method Details
#call ⇒ Object
Aggregates fragments for this specific shard and uploads to Google SFTP. Validates each fragment and final feed with gzip -t before upload.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/services/vendors_service/google_reserve/availability_feeds/uploader_service.rb', line 40 def call setup_business_context if all_shard_processing_complete? construct_shard_feed upload_shard_to_google cleanup_local_files mark_shard_upload_complete BUSINESS_LOGGER.info('Successfully completed shard upload', shard_number: shard_number, restaurants_processed: restaurant_ids.count) else reschedule_upload end rescue StandardError => e # Cleanup corrupted files and mark as failed before propagating error cleanup_corrupted_feeds mark_shard_upload_failed(e.) error_context = { service: self.class.name, operation: 'call', shard_number: shard_number, restaurants_count: restaurant_ids.count, retry_count: retry_count, error_class: e.class.name, error_message: e., } log_error('Failed to upload shard', error_context) raise e end |