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.8"

Class Method Summary collapse

Class Method Details

.fuse(file, executor, opts) ⇒ Object



27
28
29
30
# File 'lib/datafusion.rb', line 27

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

.logObject



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

def self.log
  unless @log
    @log = Logger.new($stdout)
    $stdout.sync = true
  end
  @log
end

.log=(logger) ⇒ Object



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

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

.refresh(file, executor, opts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/datafusion.rb', line 32

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

.remove!(executor) ⇒ Object



23
24
25
# File 'lib/datafusion.rb', line 23

def self.remove!(executor)
  executor.remove!
end