Class: Gitlab::InactiveProjectsDeletionWarningTracker

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/inactive_projects_deletion_warning_tracker.rb

Constant Summary collapse

DELETION_TRACKING_REDIS_KEY =
'inactive_projects_deletion_warning_email_notified'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id) ⇒ InactiveProjectsDeletionWarningTracker

Returns a new instance of InactiveProjectsDeletionWarningTracker.



27
28
29
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 27

def initialize(project_id)
  @project_id = project_id
end

Instance Attribute Details

#project_idObject (readonly)

Returns the value of attribute project_id.



7
8
9
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 7

def project_id
  @project_id
end

Class Method Details

.notified_projectsHash

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:5”=>“2022-04-22”, “project:7”=>“2022-04-25”

Returns:

  • (Hash)


15
16
17
18
19
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 15

def self.notified_projects
  Gitlab::Redis::SharedState.with do |redis|
    redis.hgetall(DELETION_TRACKING_REDIS_KEY)
  end
end

.reset_allObject



21
22
23
24
25
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 21

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

Instance Method Details

#mark_notifiedObject



37
38
39
40
41
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 37

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

#notification_dateObject



43
44
45
46
47
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 43

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

#notified?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 31

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

#resetObject



57
58
59
60
61
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 57

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

#scheduled_deletion_dateObject



49
50
51
52
53
54
55
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 49

def scheduled_deletion_date
  if notification_date.present?
    (notification_date.to_date + grace_period_after_notification).to_s
  else
    grace_period_after_notification.from_now.to_date.to_s
  end
end