Sha256: 06e3f1a71f8e30ab1752787e93026bd0d5f535d22dd5875bbe3bb09cfc876219

Contents?: true

Size: 905 Bytes

Versions: 6

Compression:

Stored size: 905 Bytes

Contents

module Dynflow
  module Action::Polling

    Poll = Algebrick.atom

    def run(event = nil)
      case event
      when nil
        self.external_task = invoke_external_task
        suspend_and_ping
      when Poll
        self.external_task = poll_external_task
        suspend_and_ping unless done?
      else
        raise "unrecognized event #{event}"
      end
    end

    def external_task
      raise NotImplementedError
    end

    def done?
      raise NotImplementedError
    end

    private

    def invoke_external_task
      raise NotImplementedError
    end

    def external_task=(external_task_data)
      raise NotImplementedError
    end

    def poll_external_task
      raise NotImplementedError
    end

    def suspend_and_ping
      suspend { |suspended_action| world.clock.ping suspended_action, poll_interval, Poll }
    end

    def poll_interval
      0.5
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dynflow-0.5.1 lib/dynflow/action/polling.rb
dynflow-0.5.0 lib/dynflow/action/polling.rb
dynflow-0.4.1 lib/dynflow/action/polling.rb
dynflow-0.4.0 lib/dynflow/action/polling.rb
dynflow-0.3.0 lib/dynflow/action/polling.rb
dynflow-0.2.0 lib/dynflow/action/polling.rb