Class: Projects::InactiveProjectsDeletionCronWorker
- Inherits:
-
Object
- Object
- Projects::InactiveProjectsDeletionCronWorker
- Includes:
- ApplicationWorker, CronjobQueue, Gitlab::Utils::StrongMemoize
- Defined in:
- app/workers/projects/inactive_projects_deletion_cron_worker.rb
Constant Summary collapse
- MAX_RUN_TIME =
This cron worker is executed at an interval of 10 minutes. Maximum run time is kept as 4 minutes to avoid breaching maximum allowed execution latency of 5 minutes.
4.minutes
- LAST_PROCESSED_INACTIVE_PROJECT_REDIS_KEY =
'last_processed_inactive_project_id'- TimeoutError =
Class.new(StandardError)
Constants included from ApplicationWorker
ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
Constants included from WorkerAttributes
WorkerAttributes::DEFAULT_CONCURRENCY_LIMIT_PERCENTAGE_BY_URGENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES
Instance Method Summary collapse
Methods included from Gitlab::Loggable
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Method Details
#perform ⇒ Object
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 48 49 50 51 52 53 54 55 56 57 |
# File 'app/workers/projects/inactive_projects_deletion_cron_worker.rb', line 21 def perform return unless ::Gitlab::CurrentSettings.delete_inactive_projects? @start_time ||= ::Gitlab::Metrics::System.monotonic_time notified_inactive_projects = Gitlab::DormantProjectsDeletionWarningTracker.notified_projects project_id = last_processed_project_id Project.where('projects.id > ?', project_id).each_batch(of: 100) do |batch| # rubocop: disable CodeReuse/ActiveRecord inactive_projects = batch.dormant.not_aimed_for_deletion inactive_projects.each do |project| if over_time? save_last_processed_project_id(project.id) raise TimeoutError end organization_admin_bot = admin_bot_for_organization_id(project.organization_id) with_context(project: project, user: organization_admin_bot) do deletion_warning_email_sent_on = notified_inactive_projects["project:#{project.id}"] if deletion_warning_email_sent_on.blank? send_notification(project) log_audit_event(project, organization_admin_bot) elsif grace_period_is_over?(deletion_warning_email_sent_on) Gitlab::DormantProjectsDeletionWarningTracker.new(project.id).reset delete_project(project, organization_admin_bot) end end end end reset_last_processed_project_id rescue TimeoutError # no-op end |