backups: add stub backup service.

This commit is contained in:
evazion
2017-05-05 21:45:14 -05:00
parent b6e1958917
commit 30a1f204e9
4 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
class BackupService
def backup(file_path, options = {})
raise NotImplementedError.new("#{self.class}.backup not implemented")
end
end

View File

@@ -0,0 +1,5 @@
class NullBackupService
def backup(file_path, options = {})
# do nothing
end
end

View File

@@ -23,6 +23,7 @@ class Post < ActiveRecord::Base
before_save :set_tag_counts
before_save :set_pool_category_pseudo_tags
before_create :autoban
after_save :queue_backup, if: :md5_changed?
after_save :create_version
after_save :update_parent_on_save
after_save :apply_post_metatags
@@ -229,6 +230,23 @@ class Post < ActiveRecord::Base
end
end
module BackupMethods
extend ActiveSupport::Concern
def queue_backup
Post.delay(queue: "default", priority: -1).backup_file(file_path, id: id, type: :original)
Post.delay(queue: "default", priority: -1).backup_file(large_file_path, id: id, type: :large) if has_large?
Post.delay(queue: "default", priority: -1).backup_file(preview_file_path, id: id, type: :preview) if has_preview?
end
module ClassMethods
def backup_file(file_path, options = {})
backup_service = Danbooru.config.backup_service
backup_service.backup(file_path, options)
end
end
end
module ImageMethods
def device_scale
if large_image_width > 320
@@ -1701,6 +1719,7 @@ class Post < ActiveRecord::Base
end
include FileMethods
include BackupMethods
include ImageMethods
include ApprovalMethods
include PresenterMethods

View File

@@ -90,6 +90,10 @@ module Danbooru
true
end
def backup_service
NullBackupService.new
end
# What method to use to store images.
# local_flat: Store every image in one directory.
# local_hierarchy: Store every image in a hierarchical directory, based on the post's MD5 hash. On some file systems this may be faster.
@@ -477,6 +481,7 @@ module Danbooru
false
end
# Used for backing up images to S3. Must be changed to your own S3 bucket.
def aws_s3_bucket_name
"danbooru"
end