Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from https://github.com/mastodon/mastodon, unmodified.
79 lines
2.4 KiB
Ruby
79 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Scheduler::SelfDestructScheduler
|
|
include Sidekiq::Worker
|
|
include SelfDestructHelper
|
|
|
|
MAX_ENQUEUED = 10_000
|
|
MAX_REDIS_MEM_USAGE = 0.5
|
|
MAX_ACCOUNT_DELETIONS_PER_JOB = 50
|
|
|
|
sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 1.day.to_i
|
|
|
|
def perform
|
|
return unless self_destruct?
|
|
return if sidekiq_overwhelmed?
|
|
|
|
delete_accounts!
|
|
end
|
|
|
|
private
|
|
|
|
def sidekiq_overwhelmed?
|
|
redis_mem_info = Sidekiq.default_configuration.redis_info
|
|
maxmemory = [redis_mem_info['maxmemory'].to_f, redis_mem_info['total_system_memory'].to_f].filter(&:positive?).min
|
|
|
|
Sidekiq::Stats.new.enqueued > MAX_ENQUEUED || redis_mem_info['used_memory'].to_f > maxmemory * MAX_REDIS_MEM_USAGE
|
|
end
|
|
|
|
def delete_accounts!
|
|
# We currently do not distinguish between deleted accounts and suspended
|
|
# accounts, and we do not want to remove the records in this scheduler, as
|
|
# we still rely on it for account delivery and don't want to perform
|
|
# needless work when the database can be outright dropped after the
|
|
# self-destruct.
|
|
# Deleted accounts are suspended accounts that do not have a pending
|
|
# deletion request.
|
|
|
|
# This targets accounts that have not been deleted nor marked for deletion yet
|
|
Account.local.without_requested_deletion.reorder(id: :asc).take(MAX_ACCOUNT_DELETIONS_PER_JOB).each do |account|
|
|
delete_account!(account)
|
|
end
|
|
|
|
return if sidekiq_overwhelmed?
|
|
|
|
# This targets accounts that have been marked for deletion but have not been
|
|
# deleted yet
|
|
Account.local.joins(:deletion_request).take(MAX_ACCOUNT_DELETIONS_PER_JOB).each do |account|
|
|
delete_account!(account)
|
|
end
|
|
end
|
|
|
|
def inboxes
|
|
@inboxes ||= Account.inboxes
|
|
end
|
|
|
|
def delete_account!(account)
|
|
json = ActivityPub::LinkedDataSignature
|
|
.new(deletion_payload(account))
|
|
.sign!(account)
|
|
.to_json
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url|
|
|
[json, account.id, inbox_url]
|
|
end
|
|
|
|
# Do not call `Account#mark_deleted!` because we don't want to issue a deletion request
|
|
account.update!(requested_deletion_at: Time.now.utc)
|
|
account.deletion_request&.destroy
|
|
end
|
|
|
|
def deletion_payload(account)
|
|
ActiveModelSerializers::SerializableResource.new(
|
|
account,
|
|
serializer: ActivityPub::DeleteActorSerializer,
|
|
adapter: ActivityPub::Adapter
|
|
).as_json
|
|
end
|
|
end
|