Class: PricingMenuPrioritySyncService

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/services/pricing_menu_priority_sync_service.rb

Overview

Service to sync pricing menu priorities from hh-menu API This ensures that the priority values stored in hh_package_pricing_menus are always up-to-date with the current priorities in the hh-menu service.

Usage:

PricingMenuPrioritySyncService.new(package).call

Instance Method Summary collapse

Constructor Details

#initialize(package) ⇒ PricingMenuPrioritySyncService

Returns a new instance of PricingMenuPrioritySyncService.



13
14
15
# File 'app/services/pricing_menu_priority_sync_service.rb', line 13

def initialize(package)
  @package = package
end

Instance Method Details

#callBoolean

Sync pricing menu priorities from hh-menu API

Returns:

  • (Boolean)

    true if sync was successful, false otherwise



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/pricing_menu_priority_sync_service.rb', line 19

def call
  return false unless diy_package?
  return false unless menu_group_id.present?

  sections_with_priority = fetch_sections_from_api
  return false if sections_with_priority.empty?

  sync_priorities(sections_with_priority)
  true
rescue StandardError => e
  HH_LOGGER.error('Error in PricingMenuPrioritySyncService#call', {
                    error: e.message,
                    package_id: @package.id,
                    menu_group_id: menu_group_id,
                  })
  APMErrorHandler.report(e, context: {
                           package_id: @package.id,
                           menu_group_id: menu_group_id,
                         })
  false
end