inst_data_shipper 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc59b5931e2a448fa9a687147b848800fd4478da037762eb3075f3e9955706d3
4
- data.tar.gz: 13382736ae30290d0997af560ce0c6b0e5445dbb6ddbbf832368fd495e467dca
3
+ metadata.gz: d2f09c00768c10bfc79fb35c689131740739a8889c81ee02186f4bd9e70b446b
4
+ data.tar.gz: 9550a780011a5fa988fff785429a637175a16634911186e7bb7625e80ac09141
5
5
  SHA512:
6
- metadata.gz: 3a118fc9c812be9b61c4ddfd7506a8f4c6b0c1d1ab0ef7deef3d45e13ee35631f110283eca1d95c2ce2c817e2c8144735d716380d9bbaf07e00516913d73ec31
7
- data.tar.gz: c103956f29f5a27c6039c4eb8381d9a42a0fe54bd1c9df8e0b86daff32f7f768c61f255ab8819b1b0e197b895becc0fbf9ce55a3be8072f69e6597aef4416e6b
6
+ metadata.gz: f5f4fd607175698b654476ed4ef50d600be06b380071469e9fda824433d3d7014bacbecc53cb25238a5ade8d1ce5b302192bc7aa8f48c922e0ae029b56d4fcac
7
+ data.tar.gz: 6d069aa519374716b5690ba2428f6f4ec2000ae36b716921e36aab9160d126dc53a4db1f8d7614d97d82849d62138d7464ffd4f719c39ee226f7becad7b50514
@@ -1,7 +1,5 @@
1
1
  module InstDataShipper
2
2
  class DumpBatch < ApplicationRecord
3
- serialize :job_arguments, Array
4
-
5
3
  ERROR_STATUS = "error".freeze
6
4
  SUCCESS_STATUS = "success".freeze
7
5
  ENQUEUED_STATUS = "enqueued".freeze
@@ -11,8 +11,6 @@ class CreateInstDataShipperDumpBatches < CanvasSync::MiscHelper::MigrationClass
11
11
 
12
12
  t.string :exception
13
13
  t.text :backtrace
14
- # t.text :metadata
15
- # t.text :job_arguments
16
14
 
17
15
  t.timestamps
18
16
  end
@@ -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!(kwargs[:schema_name], report_name)
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
 
@@ -97,19 +101,51 @@ module InstDataShipper
97
101
  end
98
102
 
99
103
  def _process_canvas_report(report:, schema_name: nil)
100
- table_def = lookup_table_schema!(schema_name, report[:report])
104
+ file_path = "#{working_dir}/temp_report"
105
+ IO.copy_stream(URI.parse(report['attachment']['url']).open, file_path)
101
106
 
102
- IO.copy_stream(URI.parse(report['attachment']['url']).open, "#{working_dir}/temp_report.csv")
107
+ if report['attachment']['content-type'] == 'application/zip'
108
+ unzipped_file_path = "#{file_path}_unzipped"
103
109
 
104
- inner_block = ->(file) {
105
- CSV.foreach("#{working_dir}/temp_report.csv", headers: true) do |m|
106
- file << table_def[:columns].map do |c|
107
- instance_exec(m, &c[:block])
110
+ Zip::File.open(file_path) do |zip_file|
111
+ zip_file.each do |f|
112
+ f_path = File.join(unzipped_file_path, f.name)
113
+ FileUtils.mkdir_p(File.dirname(f_path))
114
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
108
115
  end
109
116
  end
110
- }
111
117
 
112
- upload_data(table_def, extra: report['id'], &inner_block)
118
+ Dir[unzipped_file_path + "/*.csv"].sort.each do |file_path|
119
+ file_name = file_path.split("/").last.split(".").first
120
+
121
+ # If a schema_name Hash is provided, only process files that are explictly mapped
122
+ next if schema_name && !schema_name[file_name]
123
+
124
+ table_def = lookup_table_schema!(schema_name&.[](file_name), report[:report])
125
+
126
+ inner_block = ->(file) {
127
+ CSV.foreach(file_path, headers: true) do |m|
128
+ file << table_def[:columns].map do |c|
129
+ instance_exec(m, &c[:block])
130
+ end
131
+ end
132
+ }
133
+
134
+ upload_data(table_def, extra: report['id'], &inner_block)
135
+ end
136
+ else
137
+ table_def = lookup_table_schema!(schema_name, report[:report])
138
+
139
+ inner_block = ->(file) {
140
+ CSV.foreach(file_path, headers: true) do |m|
141
+ file << table_def[:columns].map do |c|
142
+ instance_exec(m, &c[:block])
143
+ end
144
+ end
145
+ }
146
+
147
+ upload_data(table_def, extra: report['id'], &inner_block)
148
+ end
113
149
  end
114
150
 
115
151
  def _resolve_report_incremenal_parameters(table_def, params)
@@ -1,3 +1,3 @@
1
1
  module InstDataShipper
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
@@ -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.3
4
+ version: 0.2.4
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-27 00:00:00.000000000 Z
11
+ date: 2024-10-02 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