Class: Sq::Dbsync::RefreshRecentLoadAction
Overview
This is a terribly named class that will delete the last X days of data from a table and reload it. Useful for tables that are nearly append only but sometimes will update recent data (for instance, a failed import). The tables are too big to regularly reload in their entirety, but reloading only recent data fixes the main issues.
Constant Summary
collapse
- WINDOW =
60 * 60 * 24 * 2
Constants inherited
from LoadAction
LoadAction::EPOCH
Instance Method Summary
collapse
Methods inherited from LoadAction
#call, #do_prepare, #initialize, stages, #tag
Instance Method Details
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sq/dbsync/refresh_recent_load_action.rb', line 24
def
@metadata = registry.get(plan.table_name)
@start_time = now.call
@since = (
@metadata[:last_row_at] ||
@metadata[:last_synced_at]
) - WINDOW
@file, @last_row_at = measure(:extract) { (@since) }
self
end
|
#load_data ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/sq/dbsync/refresh_recent_load_action.rb', line 35
def load_data
measure(:load) do
tname = plan.table_name
columns = plan.columns
db.transaction do
db.delete_recent(plan, @since)
db.load_from_file(tname, columns, @file.path)
end
end
@file.close!
self
end
|
#operation ⇒ Object
13
|
# File 'lib/sq/dbsync/refresh_recent_load_action.rb', line 13
def operation; 'refresh_recent'; end
|
#post_load ⇒ Object
21
22
|
# File 'lib/sq/dbsync/refresh_recent_load_action.rb', line 21
def post_load
end
|
#prepare ⇒ Object
15
16
17
18
19
|
# File 'lib/sq/dbsync/refresh_recent_load_action.rb', line 15
def prepare
return false unless plan.refresh_recent
super
end
|