Module: Hekenga

Defined in:
lib/hekenga.rb,
lib/hekenga/dsl.rb,
lib/hekenga/log.rb,
lib/hekenga/config.rb,
lib/hekenga/context.rb,
lib/hekenga/failure.rb,
lib/hekenga/invalid.rb,
lib/hekenga/version.rb,
lib/hekenga/iterator.rb,
lib/hekenga/scaffold.rb,
lib/hekenga/migration.rb,
lib/hekenga/base_error.rb,
lib/hekenga/simple_task.rb,
lib/hekenga/irreversible.rb,
lib/hekenga/parallel_job.rb,
lib/hekenga/document_task.rb,
lib/hekenga/dsl/migration.rb,
lib/hekenga/failure/error.rb,
lib/hekenga/failure/write.rb,
lib/hekenga/parallel_task.rb,
lib/hekenga/task_splitter.rb,
lib/hekenga/master_process.rb,
lib/hekenga/virtual_method.rb,
lib/hekenga/dsl/simple_task.rb,
lib/hekenga/dsl/document_task.rb,
lib/hekenga/failure/cancelled.rb,
lib/hekenga/task_failed_error.rb,
lib/hekenga/failure/validation.rb,
lib/hekenga/document_task_record.rb,
lib/hekenga/document_task_executor.rb

Defined Under Namespace

Classes: BaseError, Config, Context, DSL, DocumentTask, DocumentTaskExecutor, DocumentTaskRecord, Failure, Invalid, Irreversible, Iterator, Log, MasterProcess, Migration, ParallelJob, ParallelTask, Scaffold, SimpleTask, TaskFailedError, TaskSplitter, VirtualMethod

Constant Summary collapse

VERSION =
"1.1.0"
@@load_all_mutex =
Mutex.new
@@registry_mutex =
Mutex.new
@@registry =
[]

Class Method Summary collapse

Class Method Details

.configObject



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

def config
  @config ||= Hekenga::Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



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

def configure
  yield(config)
end

.find_migration(key) ⇒ Object



42
43
44
45
46
47
# File 'lib/hekenga.rb', line 42

def find_migration(key)
  load_all!
  registry.detect do |migration|
    migration.to_key == key
  end
end

.load_all!Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hekenga.rb', line 24

def load_all!
  return if @loaded

  @@load_all_mutex.synchronize do
    Dir.glob(File.join(config.abs_dir, "*.rb")).each do |path|
      require path
    end

    @loaded = true
  end
end

.log(str) ⇒ Object



68
69
70
# File 'lib/hekenga.rb', line 68

def log(str)
  print str.to_s+"\n"
end

.migration(&block) ⇒ Object



36
37
38
39
40
# File 'lib/hekenga.rb', line 36

def migration(&block)
  Hekenga::DSL::Migration.new(&block).object.tap do |obj|
    @@registry_mutex.synchronize { registry.push(obj) }
  end
end

.registryObject



49
50
51
# File 'lib/hekenga.rb', line 49

def registry
  @@registry
end

.reset_registryObject



53
54
55
# File 'lib/hekenga.rb', line 53

def reset_registry
  @@registry_mutex.synchronize { @@registry = [] }
end

.status(migration) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/hekenga.rb', line 57

def status(migration)
  logs = Hekenga::Log.where(
    pkey: migration.to_key
  ).to_a
  return :naught if logs.empty?
  return :skipped if logs.any? {|x| x.skip}
  return :failed if logs.any? {|x| x.cancel}
  return :complete if logs.all? {|x| x.done} && logs.length == migration.tasks.length
  return :running
end