Skip to content

Instantly share code, notes, and snippets.

@mfilej
Created February 12, 2016 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfilej/02eda27e4ac69f305bf9 to your computer and use it in GitHub Desktop.
Save mfilej/02eda27e4ac69f305bf9 to your computer and use it in GitHub Desktop.
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