Module: Datafusion

Defined in:
lib/datafusion.rb,
lib/datafusion/version.rb,
lib/datafusion/db_executor.rb,
lib/datafusion/integrations.rb,
lib/datafusion/debug_executor.rb,
lib/datafusion/snippet_renderer.rb

Defined Under Namespace

Classes: DbExecutor, DebugExecutor, Integrations, SnippetRenderer

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.fuse(file, executor, opts) ⇒ Object



20
21
22
23
# File 'lib/datafusion.rb', line 20

def self.fuse(file, executor, opts)
  out = Integrations.render(file, opts)
  executor.execute(out, "integrations")
end

.logObject



11
12
13
14
# File 'lib/datafusion.rb', line 11

def self.log
  @log ||= Logger.new(STDOUT)
  @log
end

.log=(logger) ⇒ Object



16
17
18
# File 'lib/datafusion.rb', line 16

def self.log=(logger)
  @log = logger
end

.refresh(file, executor, opts) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/datafusion.rb', line 25

def self.refresh(file, executor, opts)
  schedules = Integrations.schedules(file)
  Datafusion.log.info("Discovered #{schedules.size} schedule(s).")
  
  scheduler = Rufus::Scheduler.new
  schedules.each do |schedule|
    scheduler.every(schedule["refresh"]) do
      #
      # 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.
      #
      refresh_sql = "REFRESH materialized view #{schedule['name']}"
      
      executor.execute(refresh_sql, "schedule: #{schedule}")
    end
  end
  def scheduler.on_error(job, error)
    Datafusion.log.error("SCHEDULER: intercepted error in #{job.id}: #{error.message}")
  end
  scheduler
end