# typed: strict
class Tasks::EnqueueDuePostFileJobsTask < EnqueueJobBase
  extend T::Sig
  include HasColorLogger

  sig { override.returns(String) }
  def progress_key
    "task-enqueue-due-post-file-jobs"
  end

  sig { override.void }
  def start_enqueuing
    Domain::PostFile
      .where(state: "ok", last_status_code: nil, log_entry_id: nil)
      .find_each(batch_size: 10) do |post_file|
        enqueue do
          logger.tagged(
            make_arg_tag(post_file.post),
            make_arg_tag(post_file),
          ) do
            logger.info("enqueuing post file")
            Job::PostFileJob.perform_later(post_file:)
          end
        end
      end
  end

  sig { override.returns(Integer) }
  def queue_size
    GoodJob::Job.where(
      job_class: "Job::PostFileJob",
      performed_at: nil,
      error: nil,
    ).count
  end
end
