Refactor logging in CustomerSyncJob to use a centralized log method; enhance consistency and readability of log messages

This commit is contained in:
2026-02-27 22:32:42 -05:00
parent 9c0f153518
commit a1cbf9a0a9

View File

@@ -16,7 +16,7 @@ class CustomerSyncJob < ApplicationJob
qbo = Qbo.first qbo = Qbo.first
return unless qbo return unless qbo
logger.info "[CustomerSyncJob] Starting #{full_sync ? 'full' : 'incremental'} sync..." log "Starting #{full_sync ? 'full' : 'incremental'} sync..."
qbo = Qbo.first qbo = Qbo.first
qbo.perform_authenticated_request do |access_token| qbo.perform_authenticated_request do |access_token|
@@ -36,11 +36,12 @@ class CustomerSyncJob < ApplicationJob
break if entries.size < 1000 break if entries.size < 1000
end end
logger.info "[CustomerSyncJob] Completed sync." log "Completed sync."
Qbo.update_time_stamp
end end
rescue => e rescue => e
logger.error "[CustomerSyncJob] Fatal error: #{e.message}" log "Fatal error: #{e.message}"
logger.error e.backtrace.join("\n") log e.backtrace.join("\n")
raise # allows retry raise # allows retry
end end
@@ -62,13 +63,13 @@ class CustomerSyncJob < ApplicationJob
SQL SQL
end end
rescue => e rescue => e
logger.error "[CustomerSyncJob] Failed to fetch page #{page}: #{e.message}" log "Failed to fetch page #{page}: #{e.message}"
nil nil
end end
# Sync a single customer record # Sync a single customer record
def sync_customer(c) def sync_customer(c)
logger.info "[CustomerSyncJob] Processing customer #{c.id} / #{c.display_name} (active=#{c.active?})" log "Processing customer #{c.id} / #{c.display_name} (active=#{c.active?})"
customer = Customer.find_or_initialize_by(id: c.id) customer = Customer.find_or_initialize_by(id: c.id)
@@ -79,15 +80,21 @@ class CustomerSyncJob < ApplicationJob
if customer.changed? if customer.changed?
customer.save_without_push customer.save_without_push
logger.info "[CustomerSyncJob] Updated customer #{c.id}" log "Updated customer #{c.id}"
end end
else else
if customer.persisted? && customer.active? if customer.persisted? && customer.active?
customer.destroy customer.destroy
logger.info "[CustomerSyncJob] Deleted customer #{c.id}" log "Deleted customer #{c.id}"
end end
end end
rescue => e rescue => e
logger.error "[CustomerSyncJob] Failed to sync customer #{c.id}: #{e.message}" log "Failed to sync customer #{c.id}: #{e.message}"
end
private
def log(msg)
Rails.logger.info "[CustomerSyncJob] #{msg}"
end end
end end