takenoko-s3 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 2608fa6041d1280ad760abd979fdc662cb9e7fae
4
- data.tar.gz: 2d6c23a967ca61e9207c1dcd96dea44f17c06c42
3
+ metadata.gz: f6922c02010745f12516ecedde82d5d58b28528d
4
+ data.tar.gz: 0d21656bde5a035f48bc594f634179325d20020d
5
5
  SHA512:
6
- metadata.gz: 4c3f7e50d0d258e788191f24c7e9ad93b0a0181d8ef483d22f8bb01c559bb4331d4d1d60d2edfca25295dbee6c3db542e5d5ddb95fc1f2d5fcfc6afdcf52afcf
7
- data.tar.gz: 07381f5976287f85c37bdda04d9209f188bd3880a2942f760c1aeb02f8742687f85b773188129fc80cfc4442c377a77634b2d7def9a02ef2775b5a32eeafbd05
6
+ metadata.gz: e7682d01f2a68bb3f78292495dd552494df603c43afad03780514882bec670c168c6663fc08754922145e0d89df04c5c6622c5c975c81119438884174c74e29c
7
+ data.tar.gz: 826600fc19787eb2ab050b9bf3fbb833d2fcba077e95ea0112dc10abb9818b7c4a3f7760cb696c5043c9b042f064565deb5d7cfdf3d1adb0cffa7e9d2d30cd31
@@ -2,29 +2,50 @@ module Takenoko
2
2
  module AttachHelper
3
3
  extend self
4
4
  def upload_to_s3(table_data)
5
+ errors = []
5
6
  return false unless table_data[:to_s3].present?
6
7
  raise 'bucket must be set' if table_data[:bucket].blank?
7
8
  raise 'attach_files empty' if table_data[:attach_files].blank?
8
9
  raise "Bucket not found:#{table_data[:bucket]}" unless bucket = Takenoko.s3.client.bucket(table_data[:bucket])
9
10
 
11
+ table_name = table_data[:table_name]
12
+ takelog = "#{Takenoko.log_folder}/#{table_name}_log.yml"
13
+ log_data = (File.exist?(takelog) && YAML.load_file(takelog)) || {}
14
+
10
15
  table_data[:attach_files].each do |col|
11
16
  next unless col[:to_s3].present?
12
17
  table_data[:rows].each do |row|
13
18
  next if row[col[:column_name]].blank?
14
19
  file_path = col[:download_location] + '/' + File.basename(row[col[:column_name]])
15
20
  unless File.file?(file_path)
16
- raise "File not found: #{file_path}, download first or use download_and_upload_to_s3"
21
+ errors << "Table[#{table_data[:table_name]}]File not found: #{file_path}"
22
+ next
17
23
  end
24
+
18
25
  file = File.open(file_path)
19
26
  s3_path = col[:s3_folder]+ "/" + File.basename(row[col[:column_name]])
27
+
28
+ find_val = row[table_data[:find_column]]
29
+
30
+ if log_data[find_val].present? && (f = bucket.files.get(s3_path))
31
+ next if log_data[find_val][:s3_last_upload] && log_data[find_val][:s3_last_upload] >= file.mtime.to_i
32
+ end
33
+
20
34
  Rails.logger.info "Uploading to s3: #{file_path} -> #{s3_path}"
21
- bucket.files.create({
35
+ f = bucket.files.create({
22
36
  key: s3_path,
23
37
  body: file,
24
- public: col[:s3_public]
38
+ public: col[:s3_public],
25
39
  })
40
+
41
+ log_data[find_val] ||= {}
42
+ log_data[find_val][:s3_last_upload] = file.mtime.to_i
26
43
  end
27
44
  end
45
+
46
+ File.open(takelog, 'w') {|f| f.write log_data.to_yaml }
47
+
48
+ raise errors.join("\n") unless errors.empty?
28
49
  return true
29
50
  end
30
51
  end
@@ -11,10 +11,16 @@ module Takenoko
11
11
  end
12
12
 
13
13
  def upload_all_to_s3
14
+ errors = []
14
15
  mapping_config[:tables].each do |table,conf|
15
16
  next if conf[:attach_files].blank?
16
- upload_table_to_s3 table
17
+ begin
18
+ upload_table_to_s3 table
19
+ rescue Exception => e
20
+ errors << e.to_s
21
+ end
17
22
  end
23
+ raise errors.join("\n") unless errors.empty?
18
24
  return true
19
25
  end
20
26
 
@@ -26,10 +32,16 @@ module Takenoko
26
32
  end
27
33
 
28
34
  def download_and_upload_all_to_s3
35
+ errors = []
29
36
  mapping_config[:tables].each do |table,conf|
30
37
  next if conf[:attach_files].blank?
31
- download_and_upload_table_to_s3 table
38
+ begin
39
+ download_and_upload_table_to_s3 table
40
+ rescue Exception => e
41
+ errors << e.to_s
42
+ end
32
43
  end
44
+ raise errors.join("\n") unless errors.empty?
33
45
  return true
34
46
  end
35
47
  end
@@ -1,5 +1,5 @@
1
1
  module Takenoko
2
2
  module S3
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
data/takenoko-s3.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{S3 Uploader plugin for takenoko}
13
13
  spec.description = %q{S3 Uploader plugin for takenoko}
14
- spec.homepage = "https://github.com/khiemns54/takenoko-s3/tree/release/0.0.5"
14
+ spec.homepage = "https://github.com/khiemns54/takenoko-s3/tree/release/0.0.6"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.12"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
- spec.add_dependency "takenoko", "~> 0.2.3"
25
+ spec.add_dependency "takenoko", "~> 0.2.5"
26
26
  spec.add_dependency "fog-aws"
27
27
 
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takenoko-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - KhiemNS
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.3
61
+ version: 0.2.5
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.3
68
+ version: 0.2.5
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fog-aws
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,7 @@ files:
104
104
  - lib/takenoko/s3/tasks/takenoko.rake
105
105
  - lib/takenoko/s3/version.rb
106
106
  - takenoko-s3.gemspec
107
- homepage: https://github.com/khiemns54/takenoko-s3/tree/release/0.0.5
107
+ homepage: https://github.com/khiemns54/takenoko-s3/tree/release/0.0.6
108
108
  licenses:
109
109
  - MIT
110
110
  metadata: {}