Class: Ci::RetentionPolicies::ProjectsCleanupQueue
- Inherits:
-
Object
- Object
- Ci::RetentionPolicies::ProjectsCleanupQueue
- Includes:
- Singleton
- Defined in:
- lib/ci/retention_policies/projects_cleanup_queue.rb
Constant Summary collapse
- LAST_QUEUED_KEY =
'ci_old_pipelines_removal_last_processed_project_id{}'- REDIS_EXPIRATION_TIME =
2.hours.to_i
- QUEUE_KEY =
'ci_old_pipelines_removal_project_ids_queue{}'- PROJECTS_LIMIT =
2_500
Instance Method Summary collapse
- #enqueue!(project) ⇒ Object
- #enqueue_projects! ⇒ Object
- #fetch_next_project_id! ⇒ Object
- #last_queued_project_id ⇒ Object
- #list_all ⇒ Object
- #max_size ⇒ Object
- #size ⇒ Object
Instance Method Details
#enqueue!(project) ⇒ Object
35 36 37 38 39 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 35 def enqueue!(project) with_redis do |redis| redis.rpush(QUEUE_KEY, [project.id]) end end |
#enqueue_projects! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 23 def enqueue_projects! fetch_limit = max_size - size return unless fetch_limit > 0 project_ids = fetch_next_project_ids(fetch_limit) enqueue_and_track_last!(project_ids) # Since we order projects by ID and we take the next N projects, # if we reach the end of the list we start again. restart! if project_ids.empty? || project_ids.size < fetch_limit end |
#fetch_next_project_id! ⇒ Object
41 42 43 44 45 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 41 def fetch_next_project_id! with_redis do |redis| redis.lpop(QUEUE_KEY).to_i end end |
#last_queued_project_id ⇒ Object
47 48 49 50 51 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 47 def last_queued_project_id with_redis do |redis| redis.get(LAST_QUEUED_KEY).to_i end end |
#list_all ⇒ Object
53 54 55 56 57 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 53 def list_all with_redis do |redis| redis.lrange(QUEUE_KEY, 0, -1) end end |
#max_size ⇒ Object
19 20 21 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 19 def max_size PROJECTS_LIMIT end |
#size ⇒ Object
13 14 15 16 17 |
# File 'lib/ci/retention_policies/projects_cleanup_queue.rb', line 13 def size with_redis do |redis| redis.llen(QUEUE_KEY).to_i end end |