summaryrefslogtreecommitdiff
path: root/app/workers/personal_access_tokens/expired_notification_worker.rb
blob: 2d0ea3d3aa4dcd03319ec9ae4882750a3d4dd259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module PersonalAccessTokens
  class ExpiredNotificationWorker # rubocop:disable Scalability/IdempotentWorker
    include ApplicationWorker

    data_consistency :always

    include CronjobQueue

    feature_category :authentication_and_authorization

    def perform(*args)
      notification_service = NotificationService.new

      User.with_personal_access_tokens_expired_today.find_each do |user|
        with_context(user: user) do
          Gitlab::AppLogger.info "#{self.class}: Notifying User #{user.id} about an expired token"

          notification_service.access_token_expired(user)

          user.personal_access_tokens.without_impersonation.expired_today_and_not_notified.update_all(after_expiry_notification_delivered: true)
        end
      end
    end
  end
end