Class: Proxy::Dynflow

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_dynflow/api.rb,
lib/smart_proxy_dynflow/plugin.rb,
lib/smart_proxy_dynflow/helpers.rb,
lib/smart_proxy_dynflow/testing.rb,
lib/smart_proxy_dynflow/version.rb,
lib/smart_proxy_dynflow/callback.rb,
lib/smart_proxy_dynflow.rb

Defined Under Namespace

Modules: Callback, Helpers, Testing Classes: Api, Plugin

Constant Summary collapse

VERSION =
'0.0.6'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Dynflow

Returns a new instance of Dynflow.



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

def initialize
  @world = create_world
end

Class Attribute Details

.instance ⇒ Object (readonly)

Returns the value of attribute instance.



51
52
53
# File 'lib/smart_proxy_dynflow.rb', line 51

def instance
  @instance
end

Instance Attribute Details

#world ⇒ Object

Returns the value of attribute world.



9
10
11
# File 'lib/smart_proxy_dynflow.rb', line 9

def world
  @world
end

Class Method Details

.after_initialize(&block) ⇒ Object



78
79
80
# File 'lib/smart_proxy_dynflow.rb', line 78

def after_initialize(&block)
  after_initialize_blocks << block
end

.ensure_initialized ⇒ Object



53
54
55
56
57
58
# File 'lib/smart_proxy_dynflow.rb', line 53

def ensure_initialized
  return @instance if @instance
  @instance = Proxy::Dynflow.new
  after_initialize_blocks.each(&:call)
  @instance
end

.web_console ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/smart_proxy_dynflow.rb', line 60

def web_console
  require 'dynflow/web'
  dynflow_console = ::Dynflow::Web.setup do
    # we can't use the proxy's after_actionvation hook, as
    # it happens before the Daemon forks the process (including
    # closing opened file descriptors)
    # TODO: extend smart proxy to enable hooks that happen after
    # the forking
    Proxy::Dynflow.ensure_initialized
    set :world, Proxy::Dynflow.world
  end
  dynflow_console
end

.world ⇒ Object



74
75
76
# File 'lib/smart_proxy_dynflow.rb', line 74

def world
  instance.world
end

Instance Method Details

#create_world(&block) ⇒ Object



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

def create_world(&block)
  config = default_world_config(&block)
  ::Dynflow::World.new(config)
end

#default_world_config ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/smart_proxy_dynflow.rb', line 37

def default_world_config
  ::Dynflow::Config.new.tap do |config|
    config.auto_rescue = true
    config.logger_adapter = logger_adapter
    config.persistence_adapter = persistence_adapter
    yield config if block_given?
  end
end

#logger_adapter ⇒ Object



46
47
48
# File 'lib/smart_proxy_dynflow.rb', line 46

def logger_adapter
  ::Dynflow::LoggerAdapters::Simple.new $stderr, 0
end

#persistence_adapter ⇒ Object



33
34
35
# File 'lib/smart_proxy_dynflow.rb', line 33

def persistence_adapter
  ::Dynflow::PersistenceAdapters::Sequel.new persistence_conn_string
end

#persistence_conn_string ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/smart_proxy_dynflow.rb', line 20

def persistence_conn_string
  db_conn_string = 'sqlite:/'

  db_file = Proxy::Dynflow::Plugin.settings.database
  if db_file.nil? || db_file.empty?
    Proxy::Log.logger.warn "Could not open DB for dynflow at '#{db_file}', will keep data in memory. Restart will drop all dynflow data."
  else
    db_conn_string += "/#{db_file}"
  end

  ENV['DYNFLOW_DB_CONN_STRING'] || db_conn_string
end