Class: Dynflow::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/rails.rb,
lib/dynflow/rails/daemon.rb,
lib/dynflow/rails/configuration.rb

Overview

Class for configuring and preparing the Dynflow runtime environment.

Defined Under Namespace

Classes: Configuration, Daemon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world_class = nil, config = Rails::Configuration.new) ⇒ Rails

Returns a new instance of Rails.



12
13
14
15
16
# File 'lib/dynflow/rails.rb', line 12

def initialize(world_class = nil, config = Rails::Configuration.new)
  @required = false
  @config = config
  @world_class = world_class
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/dynflow/rails.rb', line 10

def config
  @config
end

#worldObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dynflow/rails.rb', line 74

def world
  return @world if @world

  initialize! if config.lazy_initialization
  unless @world
    raise 'The Dynflow world was not initialized yet. '\
      'If your plugin uses it, make sure to call Rails.application.dynflow.require! '\
          'in some initializer'
  end

  @world
end

Instance Method Details

#eager_load_actions!Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dynflow/rails.rb', line 89

def eager_load_actions!
  config.eager_load_paths.each do |load_path|
    Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
      unless loaded_paths.include?(file)
        require_dependency file
        loaded_paths << file
      end
    end
  end
  @world.reload! if @world
end

#executor!Object

Mark that the process is executor. This prevents the remote setting from applying. Needs to be set up before the world is being initialized



61
62
63
# File 'lib/dynflow/rails.rb', line 61

def executor!
  @executor = true
end

#executor?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/dynflow/rails.rb', line 65

def executor?
  @executor
end

#initialize!Object



31
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
# File 'lib/dynflow/rails.rb', line 31

def initialize!
  return unless @required
  return @world if @world

  if config.lazy_initialization && defined?(::PhusionPassenger)
    config.dynflow_logger
          .warn('Dynflow: lazy loading with PhusionPassenger might lead to unexpected results')
  end
  init_world.tap do |world|
    @world = world
    config.run_on_init_hooks(false, world)
    config.increase_db_pool_size(world)
    unless config.remote?
      config.run_on_init_hooks(true, world)
      # leave this just for long-running executors
      unless config.rake_task_with_executor?
        invalidated_worlds = world.perform_validity_checks
        world.auto_execute
        world.post_initialization if invalidated_worlds > 0
        if @world.delayed_executor && !@world.delayed_executor.started?
          @world.delayed_executor.start
        end
        config.run_post_executor_init_hooks(world)
      end
    end
  end
end

#initialized?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dynflow/rails.rb', line 27

def initialized?
  !@world.nil?
end

#loaded_pathsObject



101
102
103
# File 'lib/dynflow/rails.rb', line 101

def loaded_paths
  @loaded_paths ||= Set.new
end

#reinitialize!Object



69
70
71
72
# File 'lib/dynflow/rails.rb', line 69

def reinitialize!
  @world = nil
  initialize!
end

#require!Object

call this method if your engine uses Dynflow



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

def require!
  @required = true
end

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  @required
end