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

class CourseDataUpdateWorker
  include Sidekiq::Worker
  sidekiq_options unique: :until_executed

  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)
  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 unique: :until_executed, unique_expiration: THIRTY_DAYS

  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)
  end
end

Set unique_expiration timeout for course update workers
Set unique_expiration timeout for course update workers

By default, unique job locks expire after 30 minutes, so duplicate jobs have been accumulating on P&E Dashboard, where updating all current courses takes longer than that.
