eitje_s3 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 230fdba2a8fd9f8de892d021ab35594b8a84970ff0a7c518b16d01716a698df0
|
4
|
+
data.tar.gz: d70670f7249f28fc27dbd92b44670cd46cd9b768b836ea9321deb18743d2197e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e697501276a0a4921e2fd48e5daa5e697b5bae4a1554414deb910dceb1e2866e9770fb8fc489036e9299e341251efea4bf1faea96b91e07abeb28b3564c073c7
|
7
|
+
data.tar.gz: 7c1d4880cd61c4fffbe6df19f47b89d79012d74ab48f974e9e46023436d40a8af99a34a25b9ee7fe332ed76a1a17e1b8dea98f90f79919e4ba7c771f323261cb
|
@@ -34,6 +34,8 @@ module S3::OldDeletedRecordsService
|
|
34
34
|
@file_name = file_name
|
35
35
|
@file = request_object
|
36
36
|
|
37
|
+
next unless @file
|
38
|
+
|
37
39
|
case @db_table
|
38
40
|
when 'users'
|
39
41
|
filter_users_table_by_env
|
@@ -43,7 +45,7 @@ module S3::OldDeletedRecordsService
|
|
43
45
|
filter_file_by_env
|
44
46
|
end
|
45
47
|
|
46
|
-
end.flatten
|
48
|
+
end.flatten.compact
|
47
49
|
end
|
48
50
|
|
49
51
|
# filter methods
|
@@ -93,14 +95,24 @@ module S3::OldDeletedRecordsService
|
|
93
95
|
folder = "verlofverzoeks" if @db_table == "verlof_verzoeken"
|
94
96
|
|
95
97
|
s3 = Aws::S3::Client.new
|
96
|
-
|
97
|
-
|
98
|
+
|
99
|
+
objects = []
|
100
|
+
|
101
|
+
# Pagination: AWS returns 1000 items at max
|
102
|
+
s3.list_objects(bucket: 'eitje-backups', prefix: folder).each do |response|
|
103
|
+
objects += response.contents
|
104
|
+
end
|
105
|
+
|
106
|
+
names = objects.collect &:key
|
98
107
|
end
|
99
108
|
|
100
109
|
def request_object
|
101
110
|
s3 = Aws::S3::Client.new
|
102
111
|
object = s3.get_object(bucket: 'eitje-backups', key: @file_name)
|
103
|
-
|
112
|
+
body = object.body.read.as_json
|
113
|
+
json = JSON.parse(body).map(&:symbolize_keys)
|
114
|
+
rescue JSON::ParserError => e
|
115
|
+
puts "Invalid file... skip this file"
|
104
116
|
end
|
105
117
|
|
106
118
|
end
|
@@ -32,7 +32,12 @@ module S3::TransformDeletedFilesService
|
|
32
32
|
if table == 'topics'
|
33
33
|
env_ids = json.map {|row| row[:environment_ids]}.flatten.compact.uniq
|
34
34
|
else
|
35
|
-
|
35
|
+
puts "new table logic...?"
|
36
|
+
env_ids = json.map { _1[:environment_id] }.compact.uniq
|
37
|
+
|
38
|
+
unless env_ids.present?
|
39
|
+
env_ids = json.map {|row| row[:env]}.uniq.map { |name| Environment.find_by(naam: name)&.id }
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
envs_to_migrate << env_ids
|
@@ -55,6 +60,11 @@ module S3::TransformDeletedFilesService
|
|
55
60
|
@table = table
|
56
61
|
compose_file
|
57
62
|
end
|
63
|
+
|
64
|
+
rescue ActiveRecord::RecordNotFound => e
|
65
|
+
|
66
|
+
rescue => e
|
67
|
+
binding.pry
|
58
68
|
end
|
59
69
|
|
60
70
|
def migrate_files_multi_env(environment_ids, start_date: Date.yesterday)
|
@@ -105,6 +115,7 @@ module S3::TransformDeletedFilesService
|
|
105
115
|
@existing_records = JSON.parse(object.body.read.as_json).map(&:symbolize_keys)
|
106
116
|
|
107
117
|
rescue Aws::S3::Errors::NoSuchKey => e
|
118
|
+
binding.pry
|
108
119
|
@existing_records = nil
|
109
120
|
end
|
110
121
|
|
@@ -115,11 +126,13 @@ module S3::TransformDeletedFilesService
|
|
115
126
|
|
116
127
|
@records = (@records | @existing_records) if @existing_records
|
117
128
|
set_json
|
129
|
+
puts "completed successfully! new total: #{@records&.count}, old total: #{@existing_records&.count}"
|
118
130
|
upload_file
|
119
131
|
|
120
132
|
rescue => e
|
121
133
|
message = "Error for env #{@env.naam} (##{@env.id}) with table '#{@table}' => #{e.class}: #{e.message}.\n\nBacktrace:#{e.backtrace}\n"
|
122
134
|
puts message
|
135
|
+
binding.pry
|
123
136
|
@logger.error message
|
124
137
|
end
|
125
138
|
|
data/lib/s3/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eitje_s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurriaan Schrofer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07
|
11
|
+
date: 2022-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|