Class: Datafusion::DbExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/datafusion/db_executor.rb

Constant Summary collapse

TAG =
"DBEXECUTOR"

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ DbExecutor

Returns a new instance of DbExecutor.



7
8
9
# File 'lib/datafusion/db_executor.rb', line 7

def initialize(conn)
  @db = Sequel.connect(conn)
end

Instance Method Details

#exec(schedule) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datafusion/db_executor.rb', line 10

def exec(schedule)
  #
  # TODO use refresh [..] concurrently
  #
  # This means we also need to define a unique index per materialized
  # view so that PG will know how to use MVCC.
  #
  # This needs some code to detect:
  # 1. At setup time - when an index is already there, don't add it.
  # 2. At refresh time - if a table doesn't have any data, it cannot be
  # refreshed with concurrently - it needs a normal refresh first.
  #
  # For now we refresh and block.
  #
  run = rand(36**5).to_s(36)

  Datafusion.log.info("#{TAG}: starting run id:#{run} for #{schedule}")
  refresh_sql = "REFRESH materialized view #{schedule['name']}"
  @db[refresh_sql].each do |r|
    Datafusion.log.info("#{TAG}: out: #{r}")
  end
  Datafusion.log.info("#{TAG}: finished run id:#{run}")
end