inst_data_shipper 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/inst_data_shipper/dump_batch.rb +0 -2
- data/db/migrate/20240301090836_create_inst_data_shipper_dump_batches.rb +0 -2
- data/lib/inst_data_shipper/data_sources/canvas_reports.rb +47 -12
- data/lib/inst_data_shipper/dumper.rb +5 -0
- data/lib/inst_data_shipper/version.rb +1 -1
- data/spec/dummy/tmp/local_secret.txt +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d40cd83e6acf9255bfae93a00c7b31d8b9f71d3691d13437244165fd89a1ddc5
|
4
|
+
data.tar.gz: 8c4c28ff0ca83b71b35c1f55686eb173ccfd7b264db7d83fe3ade5976ddb79ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6edb9ebdd4367e6601a5b9920ecd7d0df11ea93b572becb68c42fa63b2c0d78b2ddab488a88f58eb0ad3e4630a011410001d5407aa0c81ce1e8f1eb0f8276bd5
|
7
|
+
data.tar.gz: 66ed5c81ed3b8c4f688c0e6051e376ceb28b370393189aaa1507e5ae6922c36dd130efbaed46c8ae6f132895b345e9661a195803684571ccf03a434ebcbb70b3
|
@@ -28,7 +28,7 @@ module InstDataShipper
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def import_canvas_report_by_terms(*args, **kwargs)
|
31
|
-
|
31
|
+
delayed(:_import_canvas_report_by_terms, *args, **kwargs)
|
32
32
|
end
|
33
33
|
|
34
34
|
def import_existing_report(report, **kwargs)
|
@@ -42,7 +42,11 @@ module InstDataShipper
|
|
42
42
|
term.is_a?(Term) ? term.canvas_id : term
|
43
43
|
end
|
44
44
|
|
45
|
-
table_def = lookup_table_schema
|
45
|
+
table_def = lookup_table_schema(kwargs[:schema_name], report_name) || {}
|
46
|
+
if kwargs[:incremental_config]
|
47
|
+
table_def = table_def.dup
|
48
|
+
table_def[:incremental] = kwargs.delete(:incremental_config)
|
49
|
+
end
|
46
50
|
|
47
51
|
_resolve_report_incremenal_parameters(table_def, params)
|
48
52
|
|
@@ -92,24 +96,55 @@ module InstDataShipper
|
|
92
96
|
end
|
93
97
|
|
94
98
|
def _in_canvas_report_pool(mthd, *args, **kwargs)
|
95
|
-
|
96
|
-
Jobs::AsyncCaller.call_from_pool(pool, self.class, mthd, *args, **kwargs)
|
99
|
+
call_in_pool(batch_context[:report_processor_pool], mthd, *args, **kwargs)
|
97
100
|
end
|
98
101
|
|
99
102
|
def _process_canvas_report(report:, schema_name: nil)
|
100
|
-
|
103
|
+
file_path = "#{working_dir}/temp_report"
|
104
|
+
IO.copy_stream(URI.parse(report['attachment']['url']).open, file_path)
|
101
105
|
|
102
|
-
|
106
|
+
if report['attachment']['content-type'] == 'application/zip'
|
107
|
+
unzipped_file_path = "#{file_path}_unzipped"
|
103
108
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
109
|
+
Zip::File.open(file_path) do |zip_file|
|
110
|
+
zip_file.each do |f|
|
111
|
+
f_path = File.join(unzipped_file_path, f.name)
|
112
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
113
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
108
114
|
end
|
109
115
|
end
|
110
|
-
}
|
111
116
|
|
112
|
-
|
117
|
+
Dir[unzipped_file_path + "/*.csv"].sort.each do |file_path|
|
118
|
+
file_name = file_path.split("/").last.split(".").first
|
119
|
+
|
120
|
+
# If a schema_name Hash is provided, only process files that are explictly mapped
|
121
|
+
next if schema_name && !schema_name[file_name]
|
122
|
+
|
123
|
+
table_def = lookup_table_schema!(schema_name&.[](file_name), report[:report])
|
124
|
+
|
125
|
+
inner_block = ->(file) {
|
126
|
+
CSV.foreach(file_path, headers: true) do |m|
|
127
|
+
file << table_def[:columns].map do |c|
|
128
|
+
instance_exec(m, &c[:block])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
}
|
132
|
+
|
133
|
+
upload_data(table_def, extra: report['id'], &inner_block)
|
134
|
+
end
|
135
|
+
else
|
136
|
+
table_def = lookup_table_schema!(schema_name, report[:report])
|
137
|
+
|
138
|
+
inner_block = ->(file) {
|
139
|
+
CSV.foreach(file_path, headers: true) do |m|
|
140
|
+
file << table_def[:columns].map do |c|
|
141
|
+
instance_exec(m, &c[:block])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
}
|
145
|
+
|
146
|
+
upload_data(table_def, extra: report['id'], &inner_block)
|
147
|
+
end
|
113
148
|
end
|
114
149
|
|
115
150
|
def _resolve_report_incremenal_parameters(table_def, params)
|
@@ -308,6 +308,11 @@ module InstDataShipper
|
|
308
308
|
Jobs::AsyncCaller.perform_later(self.class.to_s, mthd.to_s, *args, **kwargs)
|
309
309
|
end
|
310
310
|
|
311
|
+
def call_in_pool(pool, mthd, *args, **kwargs)
|
312
|
+
pool = CanvasSync::JobBatches::Pool.from_pid(pool) if pool.is_a?(String)
|
313
|
+
Jobs::AsyncCaller.call_from_pool(pool, self.class, mthd, *args, **kwargs)
|
314
|
+
end
|
315
|
+
|
311
316
|
delegate :working_dir, to: :executor
|
312
317
|
|
313
318
|
def batch
|
@@ -0,0 +1 @@
|
|
1
|
+
6ddf19e3f9f936190c3c79bc546382849bcf6efb4205cbe13797b683ec9a3dbc02cb87e348121c3502809d9475683c26b12c92d973d571953ebb50b0c4cc3641
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst_data_shipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Instructure CustomDev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03
|
11
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -378,6 +378,7 @@ files:
|
|
378
378
|
- spec/dummy/config/routes.rb
|
379
379
|
- spec/dummy/config/secrets.yml
|
380
380
|
- spec/dummy/db/schema.rb
|
381
|
+
- spec/dummy/tmp/local_secret.txt
|
381
382
|
- spec/inst_data_shipper/destinations/hosted_data_spec.rb
|
382
383
|
- spec/inst_data_shipper/dumper_spec.rb
|
383
384
|
- spec/spec_helper.rb
|
@@ -424,6 +425,7 @@ test_files:
|
|
424
425
|
- spec/dummy/config/secrets.yml
|
425
426
|
- spec/dummy/config.ru
|
426
427
|
- spec/dummy/db/schema.rb
|
428
|
+
- spec/dummy/tmp/local_secret.txt
|
427
429
|
- spec/inst_data_shipper/destinations/hosted_data_spec.rb
|
428
430
|
- spec/inst_data_shipper/dumper_spec.rb
|
429
431
|
- spec/spec_helper.rb
|