Class: VendorsService::GoogleReserve::AvailabilityFeeds::ProcessorService

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper, ElasticAPM::SpanHelpers, Concerns::FeedUploader, Concerns::PackageUtils
Defined in:
app/services/vendors_service/google_reserve/availability_feeds/processor_service.rb

Overview

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Constant Summary collapse

AGENDA_CALCULATION_TIMEOUT =

Timeout constants for operations with strict time limits These prevent runaway operations and ensure worker reliability

30
INVENTORY_FETCH_TIMEOUT =

seconds - for calculating available times per date

60

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_id) ⇒ ProcessorService

Initializes the processor service with a restaurant ID

Parameters:

  • restaurant_id (Integer)

    The ID of the restaurant to process



29
30
31
32
33
34
35
36
37
# File 'app/services/vendors_service/google_reserve/availability_feeds/processor_service.rb', line 29

def initialize(restaurant_id)
  @restaurant_id = restaurant_id
  @temp_file_path = nil
  @records_count = 0
  @json_file_handle = nil
  @json_buffer = nil
  @buffer_size = 0
  @fragment_paths = nil
end

Instance Method Details

#callObject

Main processing method with comprehensive error handling and monitoring This method coordinates the entire processing workflow for a restaurant



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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/services/vendors_service/google_reserve/availability_feeds/processor_service.rb', line 42

def call
  setup_business_context
  restaurant = load_and_validate_restaurant
  log_error('Restaurant is not found or not eligible') unless restaurant

  @temp_file_path = initialize_temp_file

  process_with_file_streaming(restaurant)
  store_fragment_data(restaurant)
  BUSINESS_LOGGER.info('Successfully processed restaurant for availability feed')
rescue Timeout::Error => e
  # Timeout errors - CRITICAL: Worker must fail immediately
  # Timeouts indicate operations exceeded acceptable limits
  # Do not allow partial processing or retries to continue
  error_context = build_error_context(restaurant, e)
  error_context[:timeout_type] = identify_timeout_location(e)

  # Log and mark fragment as failed
  error_message = "TIMEOUT: Operation exceeded time limit - #{e.message}"
  BUSINESS_LOGGER.error(error_message, error_context.merge(
                                         exception: e,
                                         error_class: e.class.name,
                                         backtrace: e.backtrace.first(10),
                                       ))
  APMErrorHandler.report(error_message, context: error_context)
  mark_fragment_failed(error_message)

  # Re-raise to ensure Sidekiq job fails and does not retry
  raise e
rescue StandardError => e
  # All other errors - provide comprehensive debugging context
  # Worker must fail to prevent incomplete/corrupted data
  error_context = build_error_context(restaurant, e)

  error_message = "ERROR: #{e.message}"
  BUSINESS_LOGGER.error(error_message, error_context.merge(
                                         exception: e,
                                         error_class: e.class.name,
                                         backtrace: e.backtrace.first(10),
                                       ))
  APMErrorHandler.report(error_message, context: error_context)
  mark_fragment_failed(error_message)

  # Re-raise to ensure Sidekiq job fails
  raise e
ensure
  cleanup_temp_files if @temp_file_path
end