water_wheel 0.1.0 → 0.2.0

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: '0518601af3c35d322c7f14602f5dd469f8de55bb0c5da665aac785e2e347fc6f'
4
- data.tar.gz: 568716059678669010c4f1013a6a65e65d42212e502a27e5b5175b53d3ac7a34
3
+ metadata.gz: d75be9afccde503215262b32fc3bcdbae69ae6653d249a58a37eb206e897a3b7
4
+ data.tar.gz: 0dcb13d9a9185e697156b6ad0acaa5d3bcc97d7472e420562709993d3b93b3e1
5
5
  SHA512:
6
- metadata.gz: 04f6b8c096ffcc76dabf5fe8b4a6de5dde617832afe7199577f5b378b37b8324ea48e2aa364f2a9430f5cc0772f625580b5fb0f8fc32e20cdb9d9c85ee29be94
7
- data.tar.gz: 6eb77d7fff319bd40f1aebae07e65404a46ef22b191285c94de530d7b1731ad50c39de500ae95d00fa990cd54eba4f0a657c49149647f2c6b78aff0c83c527e4
6
+ metadata.gz: 871aad2fc9a25bfc8911525930eb1cbcceb20605e041f520061fa7f78650a28e9e879fe83ff0719f11b155f1a78e40d0d322c1e95f0660c18eef7bf68902cdc3
7
+ data.tar.gz: d6a35db07b29eaa57f057aa0c56e4f5b6dd13fdeccebbac143d2b8aeb68db20ca1612966de6a3b0072f18b7b194a0ef03a1725ce905716b70fb088a21b2869c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
+ * None
2
3
 
3
- ## [0.1.0] - 2021-12-30
4
+ ## [0.2.0] - 2022-01-29
5
+ ### Added
6
+ - Introduced `parallel_count` setting, which can be used to set the number of parallel threads to use.
4
7
 
5
- - Initial release
8
+ ### Changed
9
+ - Changed retry range from not only upload section to but also pre-upload section.
10
+
11
+ ## [0.1.0] - 2022-01-22
12
+ ### Added
13
+ - Initial release.
14
+ - Using `water_wheel` gem, you can backup your local files or directories to AWS S3.
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- water_wheel (0.1.0)
4
+ water_wheel (0.2.0)
5
5
  fog-aws (~> 3.0)
6
+ parallel (~> 1.21)
6
7
  retriable (~> 3.1)
7
8
 
8
9
  GEM
@@ -11,7 +12,7 @@ GEM
11
12
  ast (2.4.2)
12
13
  builder (3.2.4)
13
14
  diff-lcs (1.5.0)
14
- excon (0.89.0)
15
+ excon (0.90.0)
15
16
  fog-aws (3.12.0)
16
17
  fog-core (~> 2.1)
17
18
  fog-json (~> 1.1)
@@ -32,11 +33,11 @@ GEM
32
33
  ipaddress (0.8.3)
33
34
  mime-types (3.4.1)
34
35
  mime-types-data (~> 3.2015)
35
- mime-types-data (3.2021.1115)
36
+ mime-types-data (3.2022.0105)
36
37
  multi_json (1.15.0)
37
- nokogiri (1.12.5-x86_64-darwin)
38
+ nokogiri (1.13.1-x86_64-darwin)
38
39
  racc (~> 1.4)
39
- nokogiri (1.12.5-x86_64-linux)
40
+ nokogiri (1.13.1-x86_64-linux)
40
41
  racc (~> 1.4)
41
42
  parallel (1.21.0)
42
43
  parser (3.0.3.2)
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # WaterWheel
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/water_wheel.svg)](https://badge.fury.io/rb/water_wheel)
3
4
  [![RSpec](https://github.com/shoutatani/water_wheel/actions/workflows/main.yml/badge.svg)](https://github.com/shoutatani/water_wheel/actions/workflows/main.yml)
4
5
 
5
6
  Backup your local files or directories into cloud storages.
@@ -11,7 +12,7 @@ Now AWS S3 (Simple Storage Service) is only available.
11
12
  Add this line to your application's Gemfile:
12
13
 
13
14
  ```ruby
14
- gem 'water_wheel'
15
+ gem "water_wheel"
15
16
  ```
16
17
 
17
18
  And then execute:
@@ -26,13 +27,13 @@ Or install it yourself as:
26
27
 
27
28
  1. Create a new S3 bucket for backup.
28
29
 
29
- 1. add `require 'water_wheel'` to your application or ruby script.
30
+ 1. add `require "water_wheel"` to your application or ruby script.
30
31
 
31
32
  1. Setting water_wheel gem with your AWS credential.
32
33
 
33
34
  ```ruby
34
35
  WaterWheel.configure do |config|
35
- config.provider = 'AWS'
36
+ config.provider = "AWS"
36
37
  config.aws_access_key_id = "your_access_key_id"
37
38
  config.aws_secret_access_key = "your_secret_access_key"
38
39
  config.aws_region = "your_region"
@@ -40,14 +41,15 @@ Or install it yourself as:
40
41
  config.absolute_path_on_files = ["/path/to/your/files", "/path/to/your/other/files"]
41
42
  config.absolute_path_on_directories = ["/path/to/your/directories", "/path/to/your/other/directories"]
42
43
  config.ordered_omit_path_prefixes = ["/path/prefix/to/omit"]
43
- config.storage_class = 'STANDARD' # STANDARD, REDUCED_REDUNDANCY, STANDARD_IA...
44
+ config.storage_class = "STANDARD" # STANDARD, REDUCED_REDUNDANCY, STANDARD_IA...
45
+ config.parallel_count = 3
44
46
  config.dry_run = false
45
47
  end
46
48
  ```
47
49
 
50
+ * You can change upload parallel thread count by `parallel_count` setting. Default is 3.
48
51
  * if you'd like to do a dry run, set `config.dry_run = true`
49
52
 
50
-
51
53
  1. Run, and you will see the result.
52
54
 
53
55
  ```ruby
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "fog/aws"
4
4
  require "retriable"
5
+ require "parallel"
5
6
 
6
7
  module WaterWheel
7
8
  class Backup
@@ -61,7 +62,7 @@ module WaterWheel
61
62
 
62
63
  def upload_directory(absolute_directory_path)
63
64
  included_files = Dir.glob(File.join(absolute_directory_path, "**", "*"))
64
- included_files.each do |included_file|
65
+ Parallel.each(included_files, in_threads: configuration.parallel_count) do |included_file|
65
66
  next if File.directory?(included_file)
66
67
 
67
68
  upload_file(included_file)
@@ -71,14 +72,14 @@ module WaterWheel
71
72
  def upload_file(absolute_file_path)
72
73
  bucket_file_key = create_bucket_key(absolute_file_path)
73
74
 
74
- return unless shouldUploadFile?(bucket_file_key, absolute_file_path)
75
+ begin
76
+ return unless shouldUploadFile?(bucket_file_key, absolute_file_path)
75
77
 
76
- if configuration.dry_run
77
- WaterWheel.logger.info "Dry run: Uploading #{absolute_file_path} to #{bucket_file_key}"
78
- return
79
- end
78
+ if configuration.dry_run
79
+ WaterWheel.logger.info "Dry run: Uploading #{absolute_file_path} to #{bucket_file_key}"
80
+ return
81
+ end
80
82
 
81
- begin
82
83
  Retriable.retriable do
83
84
  bucket.files.create(
84
85
  key: bucket_file_key,
@@ -103,7 +104,7 @@ module WaterWheel
103
104
  bucket_file_key = absolute_file_path
104
105
  configuration.ordered_omit_path_prefixes.each do |prefix|
105
106
  if absolute_file_path.start_with?(prefix)
106
- bucket_file_key = absolute_file_path.sub(prefix, '')
107
+ bucket_file_key = absolute_file_path.sub(prefix, "")
107
108
  break
108
109
  end
109
110
  end
@@ -11,6 +11,7 @@ module WaterWheel
11
11
  :absolute_path_on_directories,
12
12
  :ordered_omit_path_prefixes,
13
13
  :storage_class,
14
+ :parallel_count,
14
15
  :dry_run
15
16
 
16
17
  def initialize
@@ -23,6 +24,7 @@ module WaterWheel
23
24
  @absolute_path_on_directories = []
24
25
  @ordered_omit_path_prefixes = ["/"]
25
26
  @storage_class = "STANDARD"
27
+ @parallel_count = 3
26
28
  @dry_run = false
27
29
  end
28
30
 
@@ -41,6 +43,7 @@ module WaterWheel
41
43
  def validate!
42
44
  validate_aws_configuration if provider == "AWS"
43
45
  validate_backup_target
46
+ validate_parallel_count
44
47
  end
45
48
 
46
49
  private
@@ -51,19 +54,20 @@ module WaterWheel
51
54
  aws_region
52
55
  aws_bucket_name
53
56
  ).each do |key|
54
- if self.public_send(key).nil? || self.public_send(key).empty?
55
- error_message = <<~ERROR
56
- WaterWheel configuration #{key} is missing.
57
- Please set it as
58
- `WaterWheel.configure do |config|
59
- config.#{key} = "value"
60
- end`
61
- ERROR
62
- raise error_message
63
- end
64
- end
57
+ if self.public_send(key).nil? || self.public_send(key).empty?
58
+ error_message = <<~ERROR
59
+ WaterWheel configuration #{key} is missing.
60
+ Please set it as
61
+ `WaterWheel.configure do |config|
62
+ config.#{key} = "value"
63
+ end`
64
+ ERROR
65
+ raise error_message
66
+ end
67
+ end
68
+ end
65
69
 
66
- def validate_backup_target
70
+ def validate_backup_target
67
71
  both_upload_target_are_not_set = %i(absolute_path_on_files absolute_path_on_directories).all? do |key|
68
72
  self.public_send(key).nil? || self.public_send(key).empty?
69
73
  end
@@ -78,7 +82,19 @@ module WaterWheel
78
82
  ERROR
79
83
  raise error_message
80
84
  end
81
- end
85
+ end
86
+
87
+ def validate_parallel_count
88
+ if parallel_count.nil? || parallel_count < 1
89
+ error_message = <<~ERROR
90
+ WaterWheel parallel count is invalid.
91
+ Please set it as
92
+ `WaterWheel.configure do |config|
93
+ config.parallel_count = 10
94
+ end`
95
+ ERROR
96
+ raise error_message
97
+ end
82
98
  end
83
99
  end
84
100
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WaterWheel
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/water_wheel.gemspec CHANGED
@@ -29,14 +29,12 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- # Uncomment to register a new dependency of your gem
33
32
  spec.add_dependency "fog-aws", "~> 3.0"
34
33
  spec.add_dependency "retriable", "~> 3.1"
34
+ spec.add_dependency "parallel", "~> 1.21"
35
35
 
36
36
  spec.add_development_dependency "rake", "~> 13.0"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  spec.add_development_dependency "rubocop", "~> 1.21"
39
39
 
40
- # For more information and examples about making a new gem, check out our
41
- # guide at: https://bundler.io/guides/creating_gem.html
42
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: water_wheel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shoutatani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-22 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-aws
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.21'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.21'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement