Class: MigrationUploadSnapshot
Instance Attribute Summary
#upload
Instance Method Summary
collapse
checksum_compare, #filenames, find_by_filename, #snapshot_deletions, #snapshot_modifications, #uri
Instance Method Details
#complete?(s3_file) ⇒ Boolean
39
40
41
42
|
# File 'app/models/migration_upload_snapshot.rb', line 39
def complete?(s3_file)
index = find_complete_file(s3_file.filename, s3_file.checksum)
!index.nil?
end
|
#existing_files ⇒ Object
53
54
55
|
# File 'app/models/migration_upload_snapshot.rb', line 53
def existing_files
super.select { |file| file["migrate_status"].nil? || file["migrate_status"] == "complete" }
end
|
#finalize_migration ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/models/migration_upload_snapshot.rb', line 57
def finalize_migration
migration_start = WorkActivity.activities_for_work(work.id, [WorkActivity::MIGRATION_START]).order(created_at: :desc)
if migration_start.count == 0
Honeybadger.notify("Finalized a migration with no start! Work: #{work.id} Migration Snapshot: #{id}")
WorkActivity.add_work_activity(work.id, { migration_id: id, message: "Migration from Dataspace is complete." }.to_json,
nil, activity_type: WorkActivity::MIGRATION_COMPLETE)
else
migration = migration_start.first
data = JSON.parse(migration.message)
message = "#{data['file_count']} #{'file'.pluralize(data['file_count'])} and #{data['directory_count']} #{'directory'.pluralize(data['directory_count'])} have migrated from Dataspace."
WorkActivity.add_work_activity(work.id, { migration_id: id, message: }.to_json,
migration.created_by_user_id, activity_type: WorkActivity::MIGRATION_COMPLETE)
end
end
|
#mark_complete(s3_file) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/migration_upload_snapshot.rb', line 23
def mark_complete(s3_file)
index = find_file(s3_file.filename)
if index.present?
files[index]["migrate_status"] = "complete"
files[index].delete("migrate_error")
updated = s3_file.s3_query_service.get_s3_object_attributes(key: s3_file.filename)
updated_checksum = updated[:etag]
files[index]["checksum"] = updated_checksum
finalize_migration if migration_complete?
end
end
|
#mark_error(s3_file, error_message) ⇒ Object
8
9
10
11
12
13
14
|
# File 'app/models/migration_upload_snapshot.rb', line 8
def mark_error(s3_file, error_message)
index = find_file(s3_file.filename_display)
if index.present?
files[index]["migrate_status"] = "error"
files[index]["migrate_error"] = error_message
end
end
|
#migration_complete? ⇒ Boolean
44
45
46
|
# File 'app/models/migration_upload_snapshot.rb', line 44
def migration_complete?
files.select { |file| file.keys.include?("migrate_status") }.map { |file| file["migrate_status"] }.uniq == ["complete"]
end
|
#migration_complete_with_errors? ⇒ Boolean
48
49
50
51
|
# File 'app/models/migration_upload_snapshot.rb', line 48
def migration_complete_with_errors?
return false if migration_complete?
files.select { |file| file.keys.include?("migrate_status") }.map { |file| file["migrate_status"] }.uniq.exclude?("started")
end
|
#rename(old_filename, new_filename) ⇒ Object
17
18
19
20
21
|
# File 'app/models/migration_upload_snapshot.rb', line 17
def rename(old_filename, new_filename)
index = find_file(old_filename)
files[index]["original_filename"] = old_filename
files[index]["filename"] = new_filename
end
|
#store_files(s3_files, pre_existing_files: []) ⇒ Object
3
4
5
6
|
# File 'app/models/migration_upload_snapshot.rb', line 3
def store_files(s3_files, pre_existing_files: [])
self.files = s3_files.map { |file| { "filename" => file.filename_display, "checksum" => file.checksum, "migrate_status" => "started" } }
files.concat pre_existing_files if pre_existing_files.present?
end
|