Welcome to mirror list, hosted at ThFree Co, Russian Federation.

inactive_projects_deletion_warning_tracker.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3f8e774b4b662fd2fc36871fe20311660f26d4d (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Gitlab
  class InactiveProjectsDeletionWarningTracker
    attr_reader :project_id

    DELETION_TRACKING_REDIS_KEY = 'inactive_projects_deletion_warning_email_notified'

    # Redis key 'inactive_projects_deletion_warning_email_notified' is a hash. It stores the date when the
    # deletion warning notification email was sent for an inactive project. The fields and values look like:
    # {"project:1"=>"2022-04-22", "project:5"=>"2022-04-22", "project:7"=>"2022-04-25"}
    # @return [Hash]
    def self.notified_projects
      Gitlab::Redis::SharedState.with do |redis|
        redis.hgetall(DELETION_TRACKING_REDIS_KEY)
      end
    end

    def self.reset_all
      Gitlab::Redis::SharedState.with do |redis|
        redis.del(DELETION_TRACKING_REDIS_KEY)
      end
    end

    def initialize(project_id)
      @project_id = project_id
    end

    def notified?
      Gitlab::Redis::SharedState.with do |redis|
        redis.hexists(DELETION_TRACKING_REDIS_KEY, "project:#{project_id}")
      end
    end

    def mark_notified
      Gitlab::Redis::SharedState.with do |redis|
        redis.hset(DELETION_TRACKING_REDIS_KEY, "project:#{project_id}", Date.current)
      end
    end

    def reset
      Gitlab::Redis::SharedState.with do |redis|
        redis.hdel(DELETION_TRACKING_REDIS_KEY, "project:#{project_id}")
      end
    end
  end
end