cloud_files_transfer 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/cloud_files_transfer.gemspec +1 -0
- data/lib/cloud_files_transfer/client.rb +1 -1
- data/lib/cloud_files_transfer/transfer.rb +27 -5
- data/lib/cloud_files_transfer/version.rb +1 -1
- data/lib/cloud_files_transfer.rb +2 -1
- data/lib/tasks/cloud_files_assets.rake +17 -5
- metadata +15 -2
- data/lib/cloud_files_transfer/container.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f731a4bd53072ba8ae3b2a843678c7a6f37fc5f
|
4
|
+
data.tar.gz: 39ffce01aec214d12aa17a6ed6f73f49a3b9bc75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653c0a9edf5a6a4b73d965834e0001f8a4348005dfaf4b99879d46dc20435f71ad48460ef22b783cf812d15c0b34fbc98b54798e88430ca05dbd774bd4b8d7ba
|
7
|
+
data.tar.gz: 58a30b332c3607336ffe2b08764e5c1ba148e79d4fdb5f9f1884197cfd1d08bc6ad1f377427c97fa74b4aef9ef955a5ffde238caca0f50ba372498950d888727
|
data/README.md
CHANGED
@@ -36,7 +36,11 @@ destination:
|
|
36
36
|
|
37
37
|
Then launch the rake task to start the transfer. It doesn't matter where you do it from. It could be faster though if done from a Rackspace instance using service net (snet).
|
38
38
|
|
39
|
-
$ rake
|
39
|
+
$ rake cloudfiles:transfer
|
40
|
+
|
41
|
+
By default, it will create 4 threads to transfer simultaneously. You can specify the amount of threads like so:
|
42
|
+
|
43
|
+
$ rake cloudfiles:transfer jobs=8
|
40
44
|
|
41
45
|
## Contributing
|
42
46
|
|
@@ -10,27 +10,49 @@ module CloudFilesTransfer
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.copy!(origin, destination, path, args={})
|
13
|
-
return puts("#{path} skipped.") if destination.object_exists?(path)
|
13
|
+
return puts("#{path} skipped.".colorize(:light_blue)) if (destination.object_exists?(path) rescue false)
|
14
14
|
new(origin, destination, path, args).copy
|
15
15
|
end
|
16
16
|
|
17
17
|
def copy
|
18
18
|
retries = 0
|
19
|
-
puts "Saving #{path}"
|
20
19
|
begin
|
21
20
|
origin_object = origin.object(path)
|
22
21
|
desintation_object = destination.create_object(path)
|
23
22
|
desintation_object.write(origin_object.data)
|
23
|
+
success("#{path} saved")
|
24
24
|
rescue Exception
|
25
25
|
retries = retries + 1
|
26
|
-
unless retries >
|
27
|
-
|
26
|
+
unless retries > 2
|
27
|
+
warn("#{path} failed. Retry")
|
28
28
|
retry
|
29
29
|
else
|
30
|
-
|
30
|
+
fail("#{path} failed.")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
private
|
36
|
+
|
37
|
+
def info message
|
38
|
+
colored_print(message, :light_blue)
|
39
|
+
end
|
40
|
+
|
41
|
+
def warn message
|
42
|
+
colored_print(message, :yellow)
|
43
|
+
end
|
44
|
+
|
45
|
+
def success message
|
46
|
+
colored_print(message, :green)
|
47
|
+
end
|
48
|
+
|
49
|
+
def fail message
|
50
|
+
colored_print(message, :red)
|
51
|
+
end
|
52
|
+
|
53
|
+
def colored_print message, color
|
54
|
+
puts(message.colorize(color))
|
55
|
+
end
|
56
|
+
|
35
57
|
end
|
36
58
|
end
|
data/lib/cloud_files_transfer.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'cloudfiles'
|
2
|
+
require 'colorize'
|
2
3
|
require 'yaml'
|
3
4
|
require "cloud_files_transfer/version"
|
4
5
|
require 'cloud_files_transfer/client'
|
5
|
-
require 'cloud_files_transfer/container'
|
6
6
|
require 'cloud_files_transfer/transfer'
|
7
7
|
|
8
8
|
module CloudFilesTransfer
|
9
|
+
|
9
10
|
class Railtie < Rails::Railtie
|
10
11
|
|
11
12
|
rake_tasks do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
namespace :
|
1
|
+
namespace :cloudfiles do
|
2
2
|
|
3
3
|
desc "Copy assets from one container to another container"
|
4
4
|
task transfer: :environment do
|
@@ -29,14 +29,26 @@ namespace :cloud_files_assets do
|
|
29
29
|
)
|
30
30
|
|
31
31
|
@container_from = @client_from.container
|
32
|
-
@container_to =
|
32
|
+
@container_to = @client_to.container
|
33
33
|
@assets = @container_from.objects
|
34
34
|
|
35
|
-
|
35
|
+
jobs_count = ENV['jobs'].try(:to_i) || 4
|
36
36
|
|
37
|
-
@assets.
|
38
|
-
|
37
|
+
puts "#{@assets.size} files to copy."
|
38
|
+
puts "Transfering #{jobs_count} files at a time. Here we go!"
|
39
|
+
|
40
|
+
@assets = @assets.in_groups(jobs_count)
|
41
|
+
|
42
|
+
Thread.abort_on_exception=true
|
43
|
+
|
44
|
+
threads = jobs_count.times.map do |i|
|
45
|
+
Thread.new(i) do |i|
|
46
|
+
@assets[i].each do |path|
|
47
|
+
CloudFilesTransfer::Transfer.copy!(@container_from, @container_to, path)
|
48
|
+
end
|
49
|
+
end
|
39
50
|
end
|
51
|
+
threads.each {|t| t.join}
|
40
52
|
|
41
53
|
puts "Done."
|
42
54
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_files_transfer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathieu Gagné
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Transfer Rackspace Cloud Files assets from one container to another or
|
28
42
|
from account to another.
|
29
43
|
email:
|
@@ -40,7 +54,6 @@ files:
|
|
40
54
|
- cloud_files_transfer.gemspec
|
41
55
|
- lib/cloud_files_transfer.rb
|
42
56
|
- lib/cloud_files_transfer/client.rb
|
43
|
-
- lib/cloud_files_transfer/container.rb
|
44
57
|
- lib/cloud_files_transfer/transfer.rb
|
45
58
|
- lib/cloud_files_transfer/version.rb
|
46
59
|
- lib/tasks/cloud_files_assets.rake
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module CloudFilesTransfer
|
2
|
-
class Container
|
3
|
-
|
4
|
-
attr_accessor :container, :skip_existing_object
|
5
|
-
|
6
|
-
delegate :object_exists?, :create_object, to: :container
|
7
|
-
|
8
|
-
def initialize(container, args={})
|
9
|
-
@container = container
|
10
|
-
@skip_existing_object = args.fetch(:skip_existing_object, true)
|
11
|
-
end
|
12
|
-
|
13
|
-
def transfer(object)
|
14
|
-
return skip_message(object.name) if skip_existing_object and object_exists?(object.name)
|
15
|
-
retries = 0
|
16
|
-
puts "Saving #{object.name}"
|
17
|
-
begin
|
18
|
-
copy = create_object(object.name)
|
19
|
-
copy.write(object.data)
|
20
|
-
rescue Exception
|
21
|
-
retries = retries + 1
|
22
|
-
unless retries > 5
|
23
|
-
puts "#{object.name} failed. Retry"
|
24
|
-
retry
|
25
|
-
else
|
26
|
-
puts "#{object.name} failed."
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def skip_message(object_name)
|
34
|
-
puts "#{object_name} skipped."
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|