Module: PartnerService::Reservations::Exports::ProgressTracker::PhaseManager

Defined in:
app/services/partner_service/reservations/exports/progress_tracker.rb

Overview

Phase management helpers

Instance Method Summary collapse

Instance Method Details

#complete_phase(phase, additional_metrics = {}) ⇒ Object

Complete current phase and track performance

Parameters:

  • phase (Symbol)

    Phase to complete

  • additional_metrics (Hash) (defaults to: {})

    Additional metrics to track



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'app/services/partner_service/reservations/exports/progress_tracker.rb', line 177

def complete_phase(phase, additional_metrics = {})
  return unless @phase_start_times&.key?(phase)

  start_time = @phase_start_times[phase]
  end_time = Time.current

  # Track performance
  track_phase_performance(phase, start_time, end_time, additional_metrics)

  # Update to end of phase range
  phase_range = ExportConstants::PROGRESS_PHASES[phase]
  final_progress = phase_range.max

  # Set email status when email sending phase completes
  additional_data = if phase == :sending_email
                      { email_status: Attachment::SENT_EMAIL_STATUS }
                    else
                      {}
                    end

  @export_tracker&.update_progress(phase, final_progress, "#{phase.to_s.humanize} completed", additional_data)
end

#phase_duration(phase) ⇒ Float

Get duration of current or completed phase

Parameters:

  • phase (Symbol)

    Phase to check

Returns:

  • (Float)

    Duration in seconds (nil if phase not started)



204
205
206
207
208
# File 'app/services/partner_service/reservations/exports/progress_tracker.rb', line 204

def phase_duration(phase)
  return nil unless @phase_start_times&.key?(phase)

  Time.current - @phase_start_times[phase]
end

#start_phase(phase, message = nil) ⇒ Object

Start a new export phase with timing

Parameters:

  • phase (Symbol)

    Phase to start

  • message (String) (defaults to: nil)

    Optional custom message



163
164
165
166
167
168
169
170
171
# File 'app/services/partner_service/reservations/exports/progress_tracker.rb', line 163

def start_phase(phase, message = nil)
  @phase_start_times ||= {}
  @phase_start_times[phase] = Time.current

  phase_range = ExportConstants::PROGRESS_PHASES[phase]
  initial_progress = phase_range.min

  @export_tracker&.update_progress(phase, initial_progress, message)
end