Sha256: b2fe3002a95ec980c20283fccc1cbf1c932c105590aa0cf153a606da184d865d

Contents?: true

Size: 1.72 KB

Versions: 12

Compression:

Stored size: 1.72 KB

Contents

$:.unshift(File.expand_path('../../lib', __FILE__))

require 'dynflow'

class ExampleHelper
  class << self
    def world
      @world ||= create_world
    end

    def set_world(world)
      @world = world
    end

    def create_world
      config = Dynflow::Config.new
      config.persistence_adapter = persistence_adapter
      config.logger_adapter      = logger_adapter
      config.auto_rescue         = false
      config.telemetry_adapter   = telemetry_adapter
      yield config if block_given?
      Dynflow::World.new(config).tap do |world|
        puts "World #{world.id} started..."
      end
    end

    def persistence_conn_string
      ENV['DB_CONN_STRING'] || 'sqlite:/'
    end

    def telemetry_adapter
      if (host = ENV['TELEMETRY_STATSD_HOST'])
        Dynflow::TelemetryAdapters::StatsD.new host
      else
        Dynflow::TelemetryAdapters::Dummy.new
      end
    end

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

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

    def run_web_console(world = ExampleHelper.world)
      require 'dynflow/web'
      dynflow_console = Dynflow::Web.setup do
        set :world, world
      end
      Rack::Server.new(:app => dynflow_console, :Port => 4567).start
    end

    # for simulation of the execution failing for the first time
    def something_should_fail!
      @should_fail = true
    end

    # for simulation of the execution failing for the first time
    def something_should_fail?
      @should_fail
    end

    def nothing_should_fail!
      @should_fail = false
    end

    def terminate
      @world.terminate.wait if @world
    end
  end
end

at_exit { ExampleHelper.terminate }

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dynflow-1.3.0 examples/example_helper.rb
dynflow-1.2.3 examples/example_helper.rb
dynflow-1.2.2 examples/example_helper.rb
dynflow-1.2.1 examples/example_helper.rb
dynflow-1.2.0 examples/example_helper.rb
dynflow-1.2.0.pre1 examples/example_helper.rb
dynflow-1.1.6 examples/example_helper.rb
dynflow-1.1.5 examples/example_helper.rb
dynflow-1.1.4 examples/example_helper.rb
dynflow-1.1.3 examples/example_helper.rb
dynflow-1.1.2 examples/example_helper.rb
dynflow-1.1.1 examples/example_helper.rb