myreplicator 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module Myreplicator
|
|
25
25
|
:pid => Process.pid,
|
26
26
|
:hostname => Socket.gethostname,
|
27
27
|
:guid => SecureRandom.hex(5),
|
28
|
-
:thread_state => Thread.current.
|
28
|
+
:thread_state => Thread.current.to_s,
|
29
29
|
:state => "new")
|
30
30
|
|
31
31
|
log = Log.create options
|
@@ -45,7 +45,6 @@ module Myreplicator
|
|
45
45
|
|
46
46
|
ensure
|
47
47
|
log.finished_at = Time.now
|
48
|
-
log.thread_state = Thread.current.status
|
49
48
|
log.save!
|
50
49
|
end
|
51
50
|
end
|
data/lib/myreplicator/version.rb
CHANGED
@@ -34,8 +34,10 @@ module Myreplicator
|
|
34
34
|
while @queue.size > 0
|
35
35
|
if @threads.size <= @max_threads
|
36
36
|
@threads << Thread.new(@queue.pop) do |proc|
|
37
|
+
Thread.current[:thread_state] = "running"
|
37
38
|
@klass.new.instance_exec(proc[:params], &proc[:block])
|
38
|
-
|
39
|
+
Thread.current[:thread_state] = "done"
|
40
|
+
end
|
39
41
|
else
|
40
42
|
unless @manager_running
|
41
43
|
reaper = manage_threads
|
@@ -63,7 +65,9 @@ module Myreplicator
|
|
63
65
|
while(@threads.size > 0)
|
64
66
|
done = []
|
65
67
|
@threads.each do |t|
|
66
|
-
done << t if t.
|
68
|
+
done << t if t[:thread_state] == "done" || !t.status
|
69
|
+
# puts t.object_id.to_s + "--" + t.status.to_s + "--" + t.to_s
|
70
|
+
# raise "Nil Thread State" if t[:thread_state].nil?
|
67
71
|
end
|
68
72
|
done.each{|d| @threads.delete(d)} # Clear dead threads
|
69
73
|
|
@@ -72,6 +76,7 @@ module Myreplicator
|
|
72
76
|
if done?
|
73
77
|
@done = true
|
74
78
|
else
|
79
|
+
puts "Sleeping for 2"
|
75
80
|
sleep 2 # Wait for more threads to spawn
|
76
81
|
end
|
77
82
|
|
@@ -51,20 +51,19 @@ module Myreplicator
|
|
51
51
|
# Kicks off parallel download
|
52
52
|
##
|
53
53
|
def self.download export
|
54
|
-
|
55
|
-
parallel_download(export, ssh, completed_files(ssh, export))
|
54
|
+
parallel_download(export, completed_files(export))
|
56
55
|
end
|
57
56
|
|
58
57
|
##
|
59
58
|
# Gathers all files that need to be downloaded
|
60
59
|
# Gives the queue to parallelizer library to download in parallel
|
61
60
|
##
|
62
|
-
def self.parallel_download export,
|
61
|
+
def self.parallel_download export, files
|
63
62
|
p = Parallelizer.new(:klass => "Myreplicator::Transporter")
|
64
63
|
|
65
64
|
files.each do |filename|
|
66
65
|
puts filename
|
67
|
-
p.queue << {:params =>[
|
66
|
+
p.queue << {:params =>[export, filename], :block => download_file}
|
68
67
|
end
|
69
68
|
|
70
69
|
p.run
|
@@ -80,15 +79,14 @@ module Myreplicator
|
|
80
79
|
##
|
81
80
|
def self.download_file
|
82
81
|
proc = Proc.new { |params|
|
83
|
-
|
84
|
-
|
85
|
-
filename = params[2]
|
82
|
+
export = params[0]
|
83
|
+
filename = params[1]
|
86
84
|
|
87
85
|
ActiveRecord::Base.verify_active_connections!
|
88
86
|
ActiveRecord::Base.connection.reconnect!
|
89
87
|
|
90
88
|
Log.run(:job_type => "transporter", :name => "metadata_file",
|
91
|
-
:file => filename, :export_id => export.id) do |log|
|
89
|
+
:file => filename, :export_id => export.id ) do |log|
|
92
90
|
|
93
91
|
sftp = export.sftp_to_source
|
94
92
|
json_file = Transporter.remote_path(export, filename)
|
@@ -103,12 +101,10 @@ module Myreplicator
|
|
103
101
|
:file => dump_file, :export_id => export.id) do |log|
|
104
102
|
puts "Downloading #{dump_file}"
|
105
103
|
sftp.download!(dump_file, File.join(tmp_dir, dump_file.split("/").last))
|
106
|
-
Transporter.remove!(
|
104
|
+
Transporter.remove!(export, json_file, dump_file)
|
107
105
|
end
|
108
|
-
elsif Transporter.junk_file?(metadata)
|
109
|
-
Transporter.remove!(ssh, json_file, dump_file)
|
110
106
|
end #if
|
111
|
-
|
107
|
+
puts "#{Thread.current.to_s}___Exiting download..."
|
112
108
|
end
|
113
109
|
}
|
114
110
|
end
|
@@ -126,15 +122,17 @@ module Myreplicator
|
|
126
122
|
return false
|
127
123
|
end
|
128
124
|
|
129
|
-
def self.remove!
|
130
|
-
ssh.
|
131
|
-
|
125
|
+
def self.remove! export, json_file, dump_file
|
126
|
+
ssh = export.ssh_to_source
|
127
|
+
puts "rm #{json_file} #{dump_file}"
|
128
|
+
ssh.exec!("rm #{json_file} #{dump_file}")
|
132
129
|
end
|
133
130
|
|
134
131
|
##
|
135
132
|
# Gets all files ready to be exported from server
|
136
133
|
##
|
137
|
-
def self.completed_files
|
134
|
+
def self.completed_files export
|
135
|
+
ssh = export.ssh_to_source
|
138
136
|
done_files = ssh.exec!(get_done_files(export))
|
139
137
|
|
140
138
|
unless done_files.blank?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myreplicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -347,7 +347,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
347
347
|
version: '0'
|
348
348
|
segments:
|
349
349
|
- 0
|
350
|
-
hash:
|
350
|
+
hash: 1776546656484896019
|
351
351
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
352
352
|
none: false
|
353
353
|
requirements:
|
@@ -356,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
356
356
|
version: '0'
|
357
357
|
segments:
|
358
358
|
- 0
|
359
|
-
hash:
|
359
|
+
hash: 1776546656484896019
|
360
360
|
requirements: []
|
361
361
|
rubyforge_project:
|
362
362
|
rubygems_version: 1.8.23
|