Class: VendorsService::GoogleReserve::AvailabilityFeeds::UploaderService

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(restaurant_ids, shard_number, generation_timestamp, retry_count = 0) ⇒ UploaderService

Returns a new instance of UploaderService.

Parameters:

  • restaurant_ids (Array<Integer>, Integer)

    Restaurant IDs that belong to this shard (array) or single restaurant ID (integer) - REQUIRED

  • shard_number (Integer)

    The shard number this worker is processing - REQUIRED

  • generation_timestamp (String)

    Timestamp for feed generation consistency across shards - REQUIRED

  • retry_count (Integer) (defaults to: 0)

    Current retry attempt (default: 0, max: 4, rare parameter)



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, generation_timestamp, 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 = generation_timestamp
  @shard_paths = nil # Will store paths for this specific shard
end

Instance Method Details

#callObject

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.message)

  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.message,
  }

  log_error('Failed to upload shard', error_context)
  raise e
end