Fixes #3787 - UploadCacheCleanupJob does not execute.

This commit is contained in:
Rolf Schmidt 2021-10-05 17:18:31 +02:00 committed by Thorsten Eckel
parent b33bca9910
commit 3df384c758
3 changed files with 50 additions and 30 deletions

View file

@ -3,6 +3,7 @@
class UploadCacheCleanupJob < ApplicationJob
def perform
taskbar_form_ids = Taskbar.with_form_id.filter_map(&:persisted_form_id)
return if store_object_id.blank?
Store.where(store_object_id: store_object_id).where('created_at < ?', 1.month.ago).where.not(o_id: taskbar_form_ids).find_each do |store|
Store.remove_item(store.id)
@ -12,6 +13,6 @@ class UploadCacheCleanupJob < ApplicationJob
private
def store_object_id
Store::Object.lookup(name: 'UploadCache').id
Store::Object.lookup(name: 'UploadCache')&.id
end
end

View file

@ -0,0 +1,11 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class Issue3787FixJob < ActiveRecord::Migration[6.0]
def change
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
Scheduler.find_by(name: 'Delete old upload cache entries.').update(error_message: nil, status: nil, active: true)
end
end

View file

@ -3,6 +3,7 @@
require 'rails_helper'
RSpec.describe UploadCacheCleanupJob, type: :job do
context 'when upload cache exists' do
let(:upload_cache) { UploadCache.new(1337) }
before do
@ -44,4 +45,11 @@ RSpec.describe UploadCacheCleanupJob, type: :job do
it 'cleanup the store items which are expired with job' do
expect { described_class.perform_now }.to change(Store, :count).by(-3)
end
end
context 'when upload cache does not exist' do
it 'does not crash' do
expect { described_class.perform_now }.not_to raise_error
end
end
end