Sha256: 2422090227ec95e61e88f61370586a97fe35c71ea7c43502f0edf88da5602d34

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require_relative 'example_helper'
require 'tmpdir'

class SampleAction < Dynflow::Action
  def plan
    number = rand(1e10)
    puts "Plannin action: #{number}"
    plan_self(number: number)
  end

  def run
    puts "Running action: #{input[:number]}"
  end
end

class RemoteExecutorExample
  class << self

    def run_server
      world               = ExampleHelper.create_world(persistence_adapter: persistence_adapter)
      listener            = Dynflow::Listeners::Socket.new world, socket

      Thread.new { Dynflow::Daemon.new(listener, world).run }
      ExampleHelper.run_web_console(world)
    ensure
      File.delete(db_path)
    end

    def run_client
      executor = ->(world) { Dynflow::Executors::RemoteViaSocket.new(world, socket) }
      world    = ExampleHelper.create_world(persistence_adapter: persistence_adapter,
                                            executor:            executor)

      loop do
        world.trigger(SampleAction).finished.wait
        sleep 0.5
      end
    end

    def socket
      File.join(Dir.tmpdir, 'dynflow_socket')
    end

    def persistence_adapter
      Dynflow::PersistenceAdapters::Sequel.new "sqlite://#{db_path}"
    end

    def db_path
      File.expand_path("../remote_executor_db.sqlite", __FILE__)
    end

  end
end

command = ARGV.first || 'server'

if $0 == __FILE__
  case command
  when 'server'
    puts <<MSG
The server is starting…. You can send the work to it by running:

   #{$0} client

MSG
   RemoteExecutorExample.run_server
  when 'client'
    RemoteExecutorExample.run_client
  else
    puts "Unknown command #{comment}"
    exit 1
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dynflow-0.7.9 examples/remote_executor.rb
dynflow-0.7.8 examples/remote_executor.rb
dynflow-0.7.7 examples/remote_executor.rb
dynflow-0.7.6 examples/remote_executor.rb
dynflow-0.7.5 examples/remote_executor.rb
dynflow-0.7.4 examples/remote_executor.rb
dynflow-0.7.3 examples/remote_executor.rb
dynflow-0.7.2 examples/remote_executor.rb
dynflow-0.7.1 examples/remote_executor.rb
dynflow-0.7.0 examples/remote_executor.rb