Commit 498e34c6 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-remove-prune-web-hook-logs-worker' into 'master'

Remove RemoveOldWebHookLogsWorker

Closes #52592

See merge request gitlab-org/gitlab-ce!23628
parents e17ccef5 d5094e7c
......@@ -10,7 +10,6 @@
- cronjob:prune_old_events
- cronjob:remove_expired_group_links
- cronjob:remove_expired_members
- cronjob:remove_old_web_hook_logs
- cronjob:remove_unreferenced_lfs_objects
- cronjob:repository_archive_cache
- cronjob:repository_check_dispatch
......
# frozen_string_literal: true
class RemoveOldWebHookLogsWorker
include ApplicationWorker
include CronjobQueue
WEB_HOOK_LOG_LIFETIME = 2.days
# rubocop: disable DestroyAll
def perform
WebHookLog.destroy_all(['created_at < ?', Time.now - WEB_HOOK_LOG_LIFETIME])
end
# rubocop: enable DestroyAll
end
---
title: Remove old webhook logs after 90 days, as documented, instead of after 2
merge_request:
author:
type: fixed
......@@ -302,10 +302,6 @@ Settings.cron_jobs['gitlab_usage_ping_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['gitlab_usage_ping_worker']['cron'] ||= Settings.__send__(:cron_for_usage_ping)
Settings.cron_jobs['gitlab_usage_ping_worker']['job_class'] = 'GitlabUsagePingWorker'
Settings.cron_jobs['remove_old_web_hook_logs_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['remove_old_web_hook_logs_worker']['cron'] ||= '40 0 * * *'
Settings.cron_jobs['remove_old_web_hook_logs_worker']['job_class'] = 'RemoveOldWebHookLogsWorker'
Settings.cron_jobs['stuck_merge_jobs_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_merge_jobs_worker']['cron'] ||= '0 */2 * * *'
Settings.cron_jobs['stuck_merge_jobs_worker']['job_class'] = 'StuckMergeJobsWorker'
......
......@@ -5,18 +5,20 @@ describe PruneWebHookLogsWorker do
before do
hook = create(:project_hook)
5.times do
create(:web_hook_log, web_hook: hook, created_at: 5.months.ago)
end
create(:web_hook_log, web_hook: hook, created_at: 4.months.ago)
create(:web_hook_log, web_hook: hook, created_at: 91.days.ago)
create(:web_hook_log, web_hook: hook, created_at: 89.days.ago)
create(:web_hook_log, web_hook: hook, created_at: 2.months.ago)
create(:web_hook_log, web_hook: hook, created_at: 1.month.ago)
create(:web_hook_log, web_hook: hook, response_status: '404')
end
it 'removes all web hook logs older than one month' do
it 'removes all web hook logs older than 90 days' do
described_class.new.perform
expect(WebHookLog.count).to eq(1)
expect(WebHookLog.first.response_status).to eq('404')
expect(WebHookLog.count).to eq(4)
expect(WebHookLog.last.response_status).to eq('404')
end
end
end
require 'spec_helper'
describe RemoveOldWebHookLogsWorker do
subject { described_class.new }
describe '#perform' do
let!(:week_old_record) { create(:web_hook_log, created_at: Time.now - 1.week) }
let!(:three_days_old_record) { create(:web_hook_log, created_at: Time.now - 3.days) }
let!(:one_day_old_record) { create(:web_hook_log, created_at: Time.now - 1.day) }
it 'removes web hook logs older than 2 days' do
subject.perform
expect(WebHookLog.all).to include(one_day_old_record)
expect(WebHookLog.all).not_to include(week_old_record, three_days_old_record)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment