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_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, 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 admin_bot = ::Users::Internal.admin_bot return unless admin_bot notified_inactive_projects = Gitlab::InactiveProjectsDeletionWarningTracker.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.inactive.without_deleted inactive_projects.each do |project| if over_time? save_last_processed_project_id(project.id) raise TimeoutError end with_context(project: project, user: admin_bot) do deletion_warning_email_sent_on = notified_inactive_projects["project:#{project.id}"] if send_deletion_warning_email?(deletion_warning_email_sent_on, project) send_notification(project, admin_bot) elsif deletion_warning_email_sent_on && delete_due_to_inactivity?(deletion_warning_email_sent_on) Gitlab::InactiveProjectsDeletionWarningTracker.new(project.id).reset delete_project(project, admin_bot) end end end end reset_last_processed_project_id rescue TimeoutError # no-op end |