-
Notifications
You must be signed in to change notification settings - Fork 1
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
627 support for streaming via stdio #50
Changes from 9 commits
8a5f4a3
98790a5
df03f0f
5a4ceec
002f3e0
072abb8
737ea74
da0c85e
77482d9
b80d717
9f3d946
3512752
f4fa014
979eb26
37a30be
cae8f34
8d1d9ea
3254c01
e27e673
15e78d1
7166d77
c24a642
0c45b9c
f8bdd12
e96e22f
b09a503
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 |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import Membrane.ChildrenSpec | ||
import Membrane.Testing.Assertions | ||
alias Membrane.Testing.Pipeline | ||
Mix.start() | ||
Mix.shell(Mix.Shell.Quiet) | ||
# if Mix pollutes the logs, consider redirecting its logs by overriding the | ||
# [Mix.Shell](https://hexdocs.pm/mix/Mix.Shell.html) behaviour | ||
|
||
# redirect membrane logs to stderr | ||
# currently also requires 'configure: :logger, backends: []' line in config.exs | ||
LoggerBackends.add(LoggerBackends.Console) | ||
LoggerBackends.configure(LoggerBackends.Console, device: :standard_error) | ||
Mix.install([{:membrane_file_plugin, path: "."}]) | ||
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. shouldn't it be |
||
|
||
[input | _] = System.argv() | ||
defmodule FileExamplePipeline do | ||
use Membrane.Pipeline | ||
|
||
spec = | ||
child(%Membrane.File.Source{location: input}) | ||
|> child(:sink, %Membrane.File.Sink{location: :stdout}) | ||
@impl true | ||
def handle_init(_ctx, %{target: target, input: input}) do | ||
spec = | ||
child(%Membrane.File.Source{location: input}) | ||
|> child(:sink, %Membrane.File.Sink{location: :stdout}) | ||
|
||
{:ok, _supervisor, pipeline} = Pipeline.start(spec: spec) | ||
{[spec: spec], %{target: target}} | ||
end | ||
|
||
assert_end_of_stream(pipeline, :sink, :input) | ||
Pipeline.terminate(pipeline) | ||
@impl true | ||
def handle_element_end_of_stream(:sink, :input, _ctx, state) do | ||
send(state.target, :done) | ||
{[], state} | ||
end | ||
end | ||
|
||
Membrane.File.Sink.redirect_logs_to_stderr() | ||
|
||
[input] = System.argv() | ||
|
||
{:ok, _supervisor, pid} = | ||
Membrane.Pipeline.start_link(FileExamplePipeline, %{input: input, target: self()}) | ||
|
||
receive do | ||
:done -> Membrane.Pipeline.terminate(pid) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
import Membrane.ChildrenSpec | ||
import Membrane.Testing.Assertions | ||
alias Membrane.Testing.Pipeline | ||
Mix.start() | ||
Mix.shell(Mix.Shell.Quiet) | ||
|
||
LoggerBackends.add(LoggerBackends.Console) | ||
LoggerBackends.configure(LoggerBackends.Console, device: :standard_error) | ||
Mix.install([{:membrane_file_plugin, path: "."}]) | ||
|
||
[output, chunk_size_str | _] = System.argv() | ||
{chunk_size, ""} = Integer.parse(chunk_size_str) | ||
|
||
spec = | ||
child(%Membrane.File.Source{location: :stdin, chunk_size: chunk_size}) | ||
|> child(:sink, %Membrane.File.Sink{location: output}) | ||
defmodule PipeToFile do | ||
use Membrane.Pipeline | ||
|
||
{:ok, _supervisor, pipeline} = Pipeline.start(spec: spec) | ||
@impl true | ||
def handle_init(_ctx, %{target: target, output: output, chunk_size: chunk_size}) do | ||
spec = | ||
child(%Membrane.File.Source{location: :stdin, chunk_size: chunk_size}) | ||
|> child(:sink, %Membrane.File.Sink{location: output}) | ||
|
||
assert_end_of_stream(pipeline, :sink, :input) | ||
Pipeline.terminate(pipeline) | ||
{[spec: spec], %{target: target}} | ||
end | ||
|
||
@impl true | ||
def handle_element_end_of_stream(:sink, :input, _ctx, state) do | ||
send(state.target, :done) | ||
{[], state} | ||
end | ||
end | ||
|
||
{:ok, _supervisor, pid} = | ||
Membrane.Pipeline.start_link(PipeToFile, %{ | ||
target: self(), | ||
output: output, | ||
chunk_size: chunk_size | ||
}) | ||
|
||
receive do | ||
:done -> Membrane.Pipeline.terminate(pid) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,6 @@ defmodule Membrane.File.Plugin.Mixfile do | |
] | ||
end | ||
|
||
def application do | ||
[ | ||
extra_applications: [] | ||
] | ||
end | ||
|
||
defp elixirc_paths(:test), do: ["lib", "test/support"] | ||
defp elixirc_paths(_env), do: ["lib"] | ||
|
||
|
@@ -84,3 +78,39 @@ defmodule Membrane.File.Plugin.Mixfile do | |
] | ||
end | ||
end | ||
|
||
# Also, a small bug noticed when reproducing on elixir 1.16.0, this time related to mix: | ||
# ```elixir | ||
# require Logger | ||
|
||
# Mix.start() | ||
# Mix.shell(Mix.Shell.Quiet) | ||
|
||
# Mix.install( | ||
# [ | ||
# :ratio, | ||
# :logger_backends | ||
# ], | ||
# force: true | ||
# ) | ||
# ``` | ||
# ```command | ||
# root@5da670a83b2e:/workspace/membrane/logger_mre# elixirc mre.exs 2> stderr.log | ||
# ==> ratio | ||
# ``` | ||
# stderr.log: | ||
# ```log | ||
# Every 2.0s: cat stderr.log 5da670a83b2e: Tue Jan 30 12:35:47 2024 | ||
|
||
# warning: Ratio.DecimalConversion.decimal_to_rational/1 is undefined (module Ratio.DecimalConversion is not availabl | ||
# e or is yet to be defined) | ||
# │ | ||
# 17 │ {ratio, Ratio.DecimalConversion.decimal_to_rational(decimal)} | ||
# │ ~ | ||
# │ | ||
# └─ lib/ratio/coerce.ex:17:37: Coerce.Implementations.Ratio.Decimal.coerce/2 | ||
|
||
# both :extra_applications and :applications was found in your mix.exs. You most likely want to remove the :applications | ||
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 think we can remove this one (I believe it's good to describe such problematic cases for instance in the PR's description). |
||
# key, as all applications are derived from your dependencies | ||
# ``` | ||
# It looks like a part of the message is logged to stderr, and the last line to stdout, which, again, was a hindrance for our use case. |
kidq330 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires to be run within a mix project. Let's add
Mix.install
so it can be run withelixir file_to_pipe.exs