Created
February 12, 2016 09:53
-
-
Save mfilej/02eda27e4ac69f305bf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Ploy.Task do | |
use GenEvent | |
def start do | |
result = {:ok, pid} = GenEvent.start_link([]) | |
GenEvent.add_handler(pid, Ploy.Task, []) | |
result | |
end | |
def run(pid) do | |
GenEvent.notify(pid, :run) | |
end | |
def handle_event(:run, state) do | |
Port.open({:spawn, "ruby sup.rb"}, [:stderr_to_stdout, :binary, :exit_status]) | |
{:ok, state} | |
end | |
def handle_info({_port, {:data, data}}, state) do | |
IO.puts(data) | |
{:ok, state} | |
end | |
def handle_info({_port, {:exit_status, 0}}, state) do | |
IO.puts("done") | |
{:ok, state} | |
end | |
def handle_info({_port, {:exit_status, status}}, _state) do | |
raise "exited with status: #{status}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment