Class: Gitlab::InactiveProjectsDeletionWarningTracker
- Inherits:
-
Object
- Object
- Gitlab::InactiveProjectsDeletionWarningTracker
- 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
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
Class Method Summary collapse
-
.notified_projects ⇒ Hash
Redis key ‘inactive_projects_deletion_warning_email_notified’ is a hash.
- .reset_all ⇒ Object
Instance Method Summary collapse
-
#initialize(project_id) ⇒ InactiveProjectsDeletionWarningTracker
constructor
A new instance of InactiveProjectsDeletionWarningTracker.
- #mark_notified ⇒ Object
- #notification_date ⇒ Object
- #notified? ⇒ Boolean
- #reset ⇒ Object
- #scheduled_deletion_date ⇒ Object
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_id ⇒ Object (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_projects ⇒ Hash
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”
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_all ⇒ Object
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_notified ⇒ Object
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.to_s) end end |
#notification_date ⇒ Object
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
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 |
#reset ⇒ Object
58 59 60 61 62 |
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 58 def reset Gitlab::Redis::SharedState.with do |redis| redis.hdel(DELETION_TRACKING_REDIS_KEY, "project:#{project_id}") end end |
#scheduled_deletion_date ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/gitlab/inactive_projects_deletion_warning_tracker.rb', line 49 def scheduled_deletion_date notif_date = notification_date if notif_date.present? (notif_date.to_date + grace_period_after_notification).to_s else grace_period_after_notification.from_now.to_date.to_s end end |