Class: PartnerService::LoyaltyChangeDetectorService
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- PartnerService::LoyaltyChangeDetectorService
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/services/partner_service/loyalty_change_detector_service.rb
Overview
Service for detecting loyalty level changes and triggering batch sync operations to maintain data consistency across reservation summaries.
This service is designed to be called from loyalty transition callbacks to ensure all reservation summaries reflect the user's current loyalty status.
Constant Summary collapse
- MAX_BATCH_SIZE =
Maximum number of reservations to process in a single batch job This prevents memory issues and job timeouts for users with many reservations
100- DEFAULT_BATCH_DELAY =
Default delay between batch jobs (in seconds) to prevent overwhelming the queue
2
Instance Attribute Summary collapse
- #transition ⇒ UserLoyalty, ... readonly
- #user ⇒ UserLoyalty, ... readonly
- #user_loyalty ⇒ UserLoyalty, ... readonly
Attributes inherited from ApplicationService
Class Method Summary collapse
-
.trigger_batch_sync(user_id, date_range_days = nil) ⇒ void
Class method for direct batch sync triggering.
Instance Method Summary collapse
-
#execute ⇒ void
Execute loyalty change detection and trigger batch sync if needed.
-
#initialize(user_loyalty, transition = nil) ⇒ LoyaltyChangeDetectorService
constructor
Initialize the loyalty change detector service.
Methods inherited from ApplicationService
Constructor Details
#initialize(user_loyalty, transition = nil) ⇒ LoyaltyChangeDetectorService
Initialize the loyalty change detector service
33 34 35 36 37 38 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 33 def initialize(user_loyalty, transition = nil) super() @user_loyalty = user_loyalty @transition = transition @user = user_loyalty.user end |
Instance Attribute Details
#transition ⇒ UserLoyalty, ... (readonly)
27 28 29 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 27 def transition @transition end |
#user ⇒ UserLoyalty, ... (readonly)
27 28 29 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 27 def user @user end |
#user_loyalty ⇒ UserLoyalty, ... (readonly)
27 28 29 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 27 def user_loyalty @user_loyalty end |
Class Method Details
.trigger_batch_sync(user_id, date_range_days = nil) ⇒ void
This method returns an undefined value.
Class method for direct batch sync triggering
55 56 57 58 59 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 55 def self.trigger_batch_sync(user_id, date_range_days = nil) user = User.find(user_id) new_service = new(user.user_loyalty) new_service.send(:trigger_batch_sync, date_range_days) end |
Instance Method Details
#execute ⇒ void
This method returns an undefined value.
Execute loyalty change detection and trigger batch sync if needed
43 |
# File 'app/services/partner_service/loyalty_change_detector_service.rb', line 43 span_method :execute |