Class: Jobs::BackupChunksMerger

Inherits:
Base
  • Object
show all
Defined in:
app/jobs/regular/backup_chunks_merger.rb

Instance Method Summary collapse

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/jobs/regular/backup_chunks_merger.rb', line 7

def execute(args)
  filename = args[:filename]
  identifier = args[:identifier]
  chunks = args[:chunks].to_i

  raise Discourse::InvalidParameters.new(:filename) if filename.blank?
  raise Discourse::InvalidParameters.new(:identifier) if identifier.blank?
  raise Discourse::InvalidParameters.new(:chunks) if chunks <= 0

  backup_path = "#{BackupRestore::LocalBackupStore.base_directory}/#{filename}"
  tmp_backup_path = "#{backup_path}.tmp"
  # path to tmp directory
  tmp_directory =
    File.dirname(BackupRestore::LocalBackupStore.chunk_path(identifier, filename, 0))

  # merge all chunks
  HandleChunkUpload.merge_chunks(
    chunks,
    upload_path: backup_path,
    tmp_upload_path: tmp_backup_path,
    identifier: identifier,
    filename: filename,
    tmp_directory: tmp_directory,
  )

  # push an updated list to the clients
  store = BackupRestore::BackupStore.create
  data =
    ActiveModel::ArraySerializer.new(store.files, each_serializer: BackupFileSerializer).as_json
  MessageBus.publish("/admin/backups", data, group_ids: [Group::AUTO_GROUPS[:staff]])
end