Fixes #3787 - UploadCacheCleanupJob does not execute.
This commit is contained in:
parent
f18c0c9571
commit
4e05f0c121
3 changed files with 50 additions and 30 deletions
|
@ -3,6 +3,7 @@
|
||||||
class UploadCacheCleanupJob < ApplicationJob
|
class UploadCacheCleanupJob < ApplicationJob
|
||||||
def perform
|
def perform
|
||||||
taskbar_form_ids = Taskbar.with_form_id.filter_map(&:persisted_form_id)
|
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.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)
|
Store.remove_item(store.id)
|
||||||
|
@ -12,6 +13,6 @@ class UploadCacheCleanupJob < ApplicationJob
|
||||||
private
|
private
|
||||||
|
|
||||||
def store_object_id
|
def store_object_id
|
||||||
Store::Object.lookup(name: 'UploadCache').id
|
Store::Object.lookup(name: 'UploadCache')&.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
11
db/migrate/20211005110047_issue3787_fix_job.rb
Normal file
11
db/migrate/20211005110047_issue3787_fix_job.rb
Normal 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
|
|
@ -3,6 +3,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe UploadCacheCleanupJob, type: :job do
|
RSpec.describe UploadCacheCleanupJob, type: :job do
|
||||||
|
context 'when upload cache exists' do
|
||||||
let(:upload_cache) { UploadCache.new(1337) }
|
let(:upload_cache) { UploadCache.new(1337) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -44,4 +45,11 @@ RSpec.describe UploadCacheCleanupJob, type: :job do
|
||||||
it 'cleanup the store items which are expired with job' do
|
it 'cleanup the store items which are expired with job' do
|
||||||
expect { described_class.perform_now }.to change(Store, :count).by(-3)
|
expect { described_class.perform_now }.to change(Store, :count).by(-3)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue