myreplicator 1.1.41 → 1.1.42
Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,9 @@ class CreateMyreplicatorExports < ActiveRecord::Migration
|
|
25
25
|
t.datetime :transfer_finished_at, :default => nil
|
26
26
|
t.timestamps
|
27
27
|
t.boolean :analyze_constraints, :default => false
|
28
|
-
t.boolean :
|
28
|
+
t.boolean :nightly_refresh, :default => false
|
29
|
+
t.integer :nightly_refresh_frequency, :default => nil
|
30
|
+
t.datetime :nightly_refresh_last_run, :default => nil
|
29
31
|
end
|
30
32
|
add_index :myreplicator_exports, [:source_schema, :destination_schema, :table_name], :unique => true, :name => "unique_index"
|
31
33
|
end
|
data/lib/loader/loader.rb
CHANGED
@@ -18,10 +18,27 @@ module Myreplicator
|
|
18
18
|
# Main method provided for resque
|
19
19
|
# Reconnection provided for resque workers
|
20
20
|
##
|
21
|
-
def self.perform
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def self.perform *args
|
22
|
+
options = args.extract_options!
|
23
|
+
id = options[:id]
|
24
|
+
if id.blank?
|
25
|
+
ActiveRecord::Base.verify_active_connections!
|
26
|
+
ActiveRecord::Base.connection.reconnect!
|
27
|
+
load # Kick off the load process
|
28
|
+
else
|
29
|
+
ActiveRecord::Base.verify_active_connections!
|
30
|
+
ActiveRecord::Base.connection.reconnect!
|
31
|
+
load_id(id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Running loader for 1 export object
|
37
|
+
##
|
38
|
+
def load_id id
|
39
|
+
|
40
|
+
#Resque.enqueue(Myreplicator::Loader, id)
|
41
|
+
#Resque.enqueue(Myreplicator::Export,342)
|
25
42
|
end
|
26
43
|
|
27
44
|
##
|
@@ -135,6 +135,7 @@ module Myreplicator
|
|
135
135
|
:export_id => options[:export_id],
|
136
136
|
:filepath => options[:filepath]
|
137
137
|
}
|
138
|
+
exp = Myreplicator::Export.find(metadata.export_id)
|
138
139
|
if schema_check[:new]
|
139
140
|
create_table(ops)
|
140
141
|
#LOAD DATA IN
|
@@ -148,14 +149,23 @@ module Myreplicator
|
|
148
149
|
Loader.cleanup metadata #Remove incremental file
|
149
150
|
Kernel.p "===== Remove incremental file ====="
|
150
151
|
end
|
152
|
+
elsif exp.nightly_refresh && (exp.nightly_refresh_frequency != 0)
|
153
|
+
if (Time.now() - Time.parse(exp.nightly_refresh_last_run)) >= exp.nightly_refresh_frequency.minute
|
154
|
+
Loader.clear_older_files metadata # clear old incremental files
|
155
|
+
exp.nightly_refresh_last_run = Time.now().change(:min => 0)
|
156
|
+
exp.save!
|
157
|
+
sql = "TRUNCATE TABLE #{options[:db]}.#{options[:destination_schema]}.#{options[:table_name]};"
|
158
|
+
Myreplicator::DB.exec_sql("vertica",sql)
|
159
|
+
# run the export. The next time loader runs, it will load the file
|
160
|
+
exp.export
|
161
|
+
end
|
151
162
|
elsif get_analyze_constraints(ops) > 0 # check for primary key/unique keys violations
|
152
|
-
exp = Export.find(metadata.export_id)
|
153
163
|
Kernel.p "===== DROP CURRENT TABLE ====="
|
154
164
|
sql = "DROP TABLE IF EXISTS #{options[:db]}.#{options[:destination_schema]}.#{options[:table_name]} CASCADE;"
|
155
165
|
Myreplicator::DB.exec_sql("vertica",sql)
|
156
166
|
# run the export. The next time loader runs, it will load the file
|
157
167
|
exp.export
|
158
|
-
else
|
168
|
+
else # incremental load
|
159
169
|
temp_table = create_temp_table ops
|
160
170
|
options[:table] = temp_table
|
161
171
|
Kernel.p "===== COPY TO TEMP TABLE #{temp_table} ====="
|
data/lib/myreplicator/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.42
|
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-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -298,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
298
298
|
version: '0'
|
299
299
|
segments:
|
300
300
|
- 0
|
301
|
-
hash:
|
301
|
+
hash: -3185513387659635905
|
302
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
303
303
|
none: false
|
304
304
|
requirements:
|
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
307
|
version: '0'
|
308
308
|
segments:
|
309
309
|
- 0
|
310
|
-
hash:
|
310
|
+
hash: -3185513387659635905
|
311
311
|
requirements: []
|
312
312
|
rubyforge_project:
|
313
313
|
rubygems_version: 1.8.24
|