Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable pollable jobs cleanup #3980

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/jobs/runtime/pollable_job_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ module VCAP::CloudController
module Jobs
module Runtime
class PollableJobCleanup < VCAP::CloudController::Jobs::CCJob
CUTOFF_AGE_IN_DAYS = 90
attr_accessor :cutoff_age_in_days

def initialize(cutoff_age_in_days)
@cutoff_age_in_days = cutoff_age_in_days
end

def perform
old_pollable_jobs = PollableJobModel.where(Sequel.lit("created_at < CURRENT_TIMESTAMP - INTERVAL '?' DAY", CUTOFF_AGE_IN_DAYS))
old_pollable_jobs = PollableJobModel.where(Sequel.lit("created_at < CURRENT_TIMESTAMP - INTERVAL '?' DAY", cutoff_age_in_days))
logger = Steno.logger('cc.background.pollable-job-cleanup')
logger.info("Cleaning up #{old_pollable_jobs.count} Jobs rows")
old_pollable_jobs.delete
Expand Down
3 changes: 3 additions & 0 deletions config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ failed_jobs:
cutoff_age_in_days: 31
frequency_in_seconds: 144000 #4h

pollable_jobs:
cutoff_age_in_days: 90

service_operations_initial_cleanup:
frequency_in_seconds: 300

Expand Down
2 changes: 1 addition & 1 deletion lib/cloud_controller/clock/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Scheduler
{ name: 'expired_resource_cleanup', class: Jobs::Runtime::ExpiredResourceCleanup, time: '00:30' },
{ name: 'expired_orphaned_blob_cleanup', class: Jobs::Runtime::ExpiredOrphanedBlobCleanup, time: '01:00' },
{ name: 'orphaned_blobs_cleanup', class: Jobs::Runtime::OrphanedBlobsCleanup, time: '01:30', priority: Clock::MEDIUM_PRIORITY },
{ name: 'pollable_job_cleanup', class: Jobs::Runtime::PollableJobCleanup, time: '02:00' },
{ name: 'pollable_job_cleanup', class: Jobs::Runtime::PollableJobCleanup, time: '02:00', arg_from_config: %i[pollable_jobs cutoff_age_in_days] },
{ name: 'prune_completed_deployments', class: Jobs::Runtime::PruneCompletedDeployments, time: '03:00', arg_from_config: [:max_retained_deployments_per_app] },
{ name: 'prune_completed_builds', class: Jobs::Runtime::PruneCompletedBuilds, time: '03:30', arg_from_config: [:max_retained_builds_per_app] },
{ name: 'prune_excess_app_revisions', class: Jobs::Runtime::PruneExcessAppRevisions, time: '03:35', arg_from_config: [:max_retained_revisions_per_app] }
Expand Down
3 changes: 3 additions & 0 deletions lib/cloud_controller/config_schemas/base/clock_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ClockSchema < VCAP::Config
optional(:max_number_of_failed_delayed_jobs) => Integer,
frequency_in_seconds: Integer
},
pollable_jobs: {
cutoff_age_in_days: Integer
},
service_operations_initial_cleanup: {
frequency_in_seconds: Integer
},
Expand Down
7 changes: 4 additions & 3 deletions spec/unit/jobs/runtime/pollable_job_cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module VCAP::CloudController
module Jobs::Runtime
RSpec.describe PollableJobCleanup, job_context: :worker do
subject(:job) { PollableJobCleanup.new }
let!(:old_job) { PollableJobModel.create(created_at: 91.days.ago) }
let!(:new_job) { PollableJobModel.create(created_at: 1.day.ago) }
let(:cutoff_age_in_days) { 30 }
subject(:job) { PollableJobCleanup.new(cutoff_age_in_days) }
let!(:old_job) { PollableJobModel.create(created_at: (cutoff_age_in_days + 1).days.ago) }
let!(:new_job) { PollableJobModel.create(created_at: (cutoff_age_in_days - 1).day.ago) }

it { is_expected.to be_a_valid_job }

Expand Down
3 changes: 2 additions & 1 deletion spec/unit/lib/cloud_controller/clock/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module VCAP::CloudController
app_usage_events: { cutoff_age_in_days: 1 },
audit_events: { cutoff_age_in_days: 3 },
failed_jobs: { frequency_in_seconds: 400, cutoff_age_in_days: 4, max_number_of_failed_delayed_jobs: 10 },
pollable_jobs: { cutoff_age_in_days: 2 },
service_operations_initial_cleanup: { frequency_in_seconds: 600 },
service_usage_events: { cutoff_age_in_days: 5 },
completed_tasks: { cutoff_age_in_days: 6 },
Expand Down Expand Up @@ -108,7 +109,7 @@ module VCAP::CloudController

expect(clock).to receive(:schedule_daily_job) do |args, &block|
expect(args).to eql(name: 'pollable_job_cleanup', at: '02:00', priority: 0)
expect(Jobs::Runtime::PollableJobCleanup).to receive(:new).with(no_args).and_call_original
expect(Jobs::Runtime::PollableJobCleanup).to receive(:new).with(2).and_call_original
expect(block.call).to be_instance_of(Jobs::Runtime::PollableJobCleanup)
end

Expand Down