class CleanupExpiredSessionsJob
  include Sidekiq::Job

  def perform
    StreamSession.where(status: %w[connecting reconnecting])
                 .where("updated_at < ?", 6.hours.ago)
                 .find_each do |session|
      session.fail! if session.may_fail?
      Mediamtx::Client.new.delete_path(session)
    end
  end
end
