-
Notifications
You must be signed in to change notification settings - Fork 5
Add decoding and encoding to string for Graph #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ defmodule Imageflow.GraphRunner do | |
| :ok <- add_outputs(job, graph.outputs), | ||
| :ok <- send_task(job, graph), | ||
| :ok <- save_outputs(job, graph.outputs), | ||
| :ok <- Native.destroy(job) do | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this step got left out entirely. |
||
| :ok | ||
| {:ok, results} <- print_results(job, graph.outputs) do | ||
| if results == [], do: :ok, else: {:ok, results} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with a breaking change here, if a new result type needs to be used. Returning different types based on the result leads to an inconsistent API.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option would be to just add a separate Might be worth checking how the .NET wrapper does it, since this one was mostly based on it
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually liked the |
||
| end | ||
| end | ||
|
|
||
|
|
@@ -18,6 +18,7 @@ defmodule Imageflow.GraphRunner do | |
| {id, value}, :ok -> | ||
| case value do | ||
| {:file, path} -> Native.add_input_file(job, id, path) | ||
| {:bytes, blob} -> Native.add_input_buffer(job, id, blob) | ||
| end | ||
| |> case do | ||
| :ok -> {:cont, :ok} | ||
|
|
@@ -29,10 +30,13 @@ defmodule Imageflow.GraphRunner do | |
| defp add_outputs(job, inputs) do | ||
| inputs | ||
| |> Enum.reduce_while(:ok, fn | ||
| {id, _}, :ok -> | ||
| with :ok <- Native.add_output_buffer(job, id) do | ||
| {:cont, :ok} | ||
| else | ||
| {id, value}, :ok -> | ||
| case value do | ||
| {:file, _path} -> Native.add_output_buffer(job, id) | ||
| :bytes -> Native.add_output_buffer(job, id) | ||
|
naps62 marked this conversation as resolved.
Outdated
|
||
| end | ||
| |> case do | ||
| :ok -> {:cont, :ok} | ||
| {:error, _} = error -> {:halt, error} | ||
| end | ||
| end) | ||
|
|
@@ -44,6 +48,8 @@ defmodule Imageflow.GraphRunner do | |
| {id, value}, :ok -> | ||
| case value do | ||
| {:file, path} -> Native.save_output_to_file(job, id, path) | ||
| # skip | ||
| :bytes -> :ok | ||
| end | ||
| |> case do | ||
| :ok -> {:cont, :ok} | ||
|
|
@@ -52,6 +58,22 @@ defmodule Imageflow.GraphRunner do | |
| end) | ||
| end | ||
|
|
||
| def print_results(job, outputs) do | ||
| outputs | ||
| |> Enum.reduce_while({:ok, []}, fn {id, value}, {:ok, acc} -> | ||
| case value do | ||
| :bytes -> Native.get_output_buffer(job, id) | ||
| # skip | ||
| {:file, _} -> :skip | ||
| end | ||
| |> case do | ||
| :skip -> {:cont, {:ok, acc}} | ||
| {:ok, results} -> {:cont, {:ok, :binary.list_to_bin(results)}} | ||
| {:error, _} = error -> {:halt, error} | ||
| end | ||
| end) | ||
| end | ||
|
|
||
| defp send_task(job, graph) do | ||
| with {:ok, _response} <- Native.message(job, "v0.1/execute", graph) do | ||
| :ok | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.