# frozen_string_literal: true
require_dependency "#{Rails.root}/app/services/update_course_stats"

class CourseDataUpdateWorker
  THIRTY_DAYS = 60 * 60 * 24 * 30
  include Sidekiq::Worker
  sidekiq_options lock: :until_executed,
                  lock_ttl: THIRTY_DAYS,
                  retry: 0 # Move job to the 'dead' queue if it fails

  def self.update_course(course_id:, queue:)
    CourseDataUpdateWorker.set(queue: queue).perform_async(course_id)
  end

  def perform(course_id)
    course = Course.find(course_id)
    UpdateCourseStats.new(course)
  rescue StandardError => e
    Sentry.capture_exception e
  end
end

# frozen_string_literal: true
require_dependency "#{Rails.root}/app/services/update_course_stats"

class CourseDataUpdateWorker
  THIRTY_DAYS = 60 * 60 * 24 * 30
  include Sidekiq::Worker
  sidekiq_options lock: :until_executed,
                  lock_ttl: THIRTY_DAYS,
                  retry: 0 # Move job to the 'dead' queue if it fails

  def self.update_course(course_id:, queue:)
    CourseDataUpdateWorker.set(queue: queue).perform_async(course_id)
  end

  def perform(course_id)
    course = Course.find(course_id)
    logger.info "Updating course: #{course.slug}"
    UpdateCourseStats.new(course)
  rescue StandardError => e
    Sentry.capture_exception e
  end
end

Add logging to pin down which course(s) are causing OOM problems
Add logging to pin down which course(s) are causing OOM problems

Sidekiq logs can be monitored in realtime via Nomad, so this should let me see which course updates are causing the Nomad jobs to be killed for OOM, so I can either optimize memory usage or find some other solution.
