-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write first version of ImageCleaner for #1502
Write to file and add worker
- Loading branch information
1 parent
d0d30dc
commit 043ea2c
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) 2012-2016, Fairmondo eG. This file is | ||
# licensed under the GNU Affero General Public License version 3 or later. | ||
# See the COPYRIGHT file for details. | ||
|
||
class ImageCleaner | ||
def initialize | ||
end | ||
|
||
def show(range) | ||
files_found = 0 | ||
|
||
File.open('image_cleaner.txt', 'w') do |file| | ||
for id in range | ||
path = path(id) | ||
|
||
begin | ||
img = Image.find(id) | ||
file.puts("#{path}: #{img.image_file_name}") | ||
rescue ActiveRecord::RecordNotFound | ||
if File.exist?(path) | ||
files_found += 1 | ||
file.puts("#{path}: no image") | ||
end | ||
end | ||
end | ||
|
||
file.puts("Extranous files total: #{files_found}") | ||
end | ||
end | ||
|
||
def path(id) | ||
id_str = padded_id(id) | ||
Rails.root.join('public', 'system', 'images', id_str[0..2], id_str[3..5], id_str[6..8]) | ||
end | ||
|
||
def padded_id(id) | ||
sprintf('%09d', id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2012-2016, Fairmondo eG. This file is | ||
# licensed under the GNU Affero General Public License version 3 or later. | ||
# See the COPYRIGHT file for details. | ||
|
||
class ImageCleanerWorker | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :default, | ||
retry: 20, | ||
backtrace: true | ||
|
||
def perform(range) | ||
cleaner = ImageCleaner.new | ||
cleaner.show(range) | ||
end | ||
end |