-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Partially added nodejs script task execution
- Loading branch information
Showing
10 changed files
with
167 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
language: elixir | ||
elixir: '1.5' | ||
otp_release: '20.0' | ||
|
||
elixir: | ||
- '1.5' | ||
otp_release: | ||
- '19.0' | ||
- '20.0' | ||
|
||
env: | ||
- MIX_ENV=test | ||
|
||
script: mix coveralls.travis |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Bpmn.Application do | ||
# See http://elixir-lang.org/docs/stable/elixir/Application.html | ||
# for more information on OTP Applications | ||
@moduledoc false | ||
|
||
use Application | ||
|
||
def start(_type, _args) do | ||
import Supervisor.Spec, warn: false | ||
|
||
# Define workers and child supervisors to be supervised | ||
children = [ | ||
# Starts a worker by calling: Bpmn.Worker.start_link(arg1, arg2, arg3) | ||
# worker(Bpmn.Worker, [arg1, arg2, arg3]), | ||
supervisor(Bpmn.Port.Supervisor, []) | ||
] | ||
|
||
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html | ||
# for other strategies and supported options | ||
opts = [strategy: :one_for_one, name: Bpmn.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
defmodule Bpmn.Port.Nodejs do | ||
use GenServer | ||
|
||
def start_link cmd \\ nil do | ||
cmd = case cmd do | ||
nil-> ["node /Users/cosmin/Incubator/github/hashiru/bpmn/priv/scripts/node.js"] | ||
_-> cmd | ||
end | ||
GenServer.start_link __MODULE__, cmd, name: __MODULE__ | ||
end | ||
|
||
def eval_script script, context do | ||
GenServer.call __MODULE__, {:script, script, context} | ||
end | ||
|
||
def eval_string script, context do | ||
GenServer.call __MODULE__, {:string, script, context} | ||
end | ||
|
||
def close do | ||
GenServer.call __MODULE__, {:close} | ||
end | ||
|
||
## callbacks | ||
|
||
def init cmd do | ||
port = Port.open {:spawn, hd(cmd)}, [:binary] | ||
{:ok, port} | ||
end | ||
|
||
def handle_call({:string, script, context}, from, port), do: send_request({"string", script, context}, from, port) | ||
def handle_call({:script, script, context}, from, port), do: send_request({"file", script, context}, from, port) | ||
|
||
def handle_call {:close}, _, port do | ||
Port.close port | ||
{:reply, :ok, nil} | ||
end | ||
|
||
def handle_call _, _from, nil do | ||
{:stop, :port_closed, nil} | ||
end | ||
|
||
defp send_request {type, script, context}, _, port do | ||
msg = Poison.encode!(%{ | ||
type: type, | ||
script: script, | ||
context: context, | ||
}) | ||
result = case Port.command port, msg do | ||
true -> receive do | ||
{^port, {:data, result}} -> | ||
{:ok, result} | ||
|
||
after 5_000 -> {:error, :timed_out} | ||
end | ||
|
||
false -> {:error, :process_dead} | ||
end | ||
|
||
case result do | ||
{:error, reason} -> {:stop, reason, nil} | ||
{:ok, x} -> {:reply, Poison.decode!(x), port} | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Bpmn.Port.Supervisor do | ||
use Supervisor | ||
|
||
def start_link() do | ||
Supervisor.start_link(__MODULE__, :ok) | ||
end | ||
|
||
def init(:ok) do | ||
children = [ | ||
{Bpmn.Port.Nodejs, ["node ./priv/scripts/node.js"]} | ||
] | ||
|
||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
process.stdin.on('data', d => { | ||
process.stdout.write(d + "\n"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Bpmn.Activity.Task.ScriptTest do | ||
use ExUnit.Case, async: true | ||
doctest Bpmn.Activity.Task.Script | ||
end |