2014-02-22 08:41:01 +08:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class BackupChunksMerger < Jobs::Base
|
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
filename = args[:filename]
|
|
|
|
identifier = args[:identifier]
|
|
|
|
chunks = args[:chunks].to_i
|
|
|
|
|
2014-03-19 08:05:47 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:filename) if filename.blank?
|
2014-02-22 08:41:01 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:identifier) if identifier.blank?
|
2014-03-19 08:05:47 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:chunks) if chunks <= 0
|
2014-02-22 08:41:01 +08:00
|
|
|
|
2014-03-19 08:05:47 +08:00
|
|
|
backup_path = "#{Backup.base_directory}/#{filename}"
|
|
|
|
tmp_backup_path = "#{backup_path}.tmp"
|
2014-05-28 04:14:37 +08:00
|
|
|
# path to tmp directory
|
2014-03-19 08:05:47 +08:00
|
|
|
tmp_directory = File.dirname(Backup.chunk_path(identifier, filename, 0))
|
2014-05-28 04:14:37 +08:00
|
|
|
|
|
|
|
# merge all chunks
|
|
|
|
HandleChunkUpload.merge_chunks(chunks, upload_path: backup_path, tmp_upload_path: tmp_backup_path, model: Backup, identifier: identifier, filename: filename, tmp_directory: tmp_directory)
|
2014-02-22 08:41:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|