-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8a5f4a3
Update examples
kidq330 98790a5
Add test pipelines
kidq330 df03f0f
Draft with working tests
kidq330 5a4ceec
WIP Compiling deps during tests
kidq330 002f3e0
Improved tests
kidq330 072abb8
Fix mix env issue in integration tests
kidq330 737ea74
Improve logs on failure
kidq330 da0c85e
Fix credo error
kidq330 77482d9
Refactored tests and test logging
kidq330 b80d717
Moved pipelines to examples
kidq330 9f3d946
Minor refactor
kidq330 3512752
Added element descriptions
kidq330 f4fa014
Fix tests failing after refactor
kidq330 979eb26
Fix linting issue
kidq330 37a30be
Add missing fix to last test
kidq330 cae8f34
Rework scripts to be standalone
kidq330 8d1d9ea
Format test cmds
kidq330 3254c01
Update docs as per code review
kidq330 e27e673
Update mix.lock to not use logger_backends for now
kidq330 15e78d1
Add spec for credo to shut up :)
kidq330 7166d77
Remove WIP comments
kidq330 c24a642
rename redirect_logs to redirect_logs_to_stderr
kidq330 0c45b9c
Rename all redirect occurences
kidq330 f8bdd12
Improve logger redirection fn
kidq330 e96e22f
Refactors after review
kidq330 b09a503
Rollback to relative path for examples
kidq330 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,19 +1,78 @@ | ||
import Membrane.ChildrenSpec | ||
import Membrane.Testing.Assertions | ||
alias Membrane.Testing.Pipeline | ||
# defmodule Mix.Shell.Ultraquiet do | ||
# @behaviour Mix.Shell | ||
|
||
# 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) | ||
# def print_app, do: :ok | ||
|
||
[input | _] = System.argv() | ||
# def error(_message), do: :ok | ||
|
||
spec = | ||
child(%Membrane.File.Source{location: input}) | ||
|> child(:sink, %Membrane.File.Sink{location: :stdout}) | ||
# def info(_message), do: :ok | ||
|
||
{:ok, _supervisor, pipeline} = Pipeline.start(spec: spec) | ||
# def print_app(_message), do: :ok | ||
|
||
assert_end_of_stream(pipeline, :sink, :input) | ||
Pipeline.terminate(pipeline) | ||
# def prompt(_message), do: :ok | ||
|
||
# def yes?(_message, _opts \\ []), do: :ok | ||
|
||
# def cmd(command, opts \\ []) do | ||
# Mix.Shell.cmd(command, opts, fn data -> data end) | ||
# end | ||
# end | ||
|
||
# {:ok, config} = :logger.get_handler_config(:default) | ||
# config_dev = put_in(config, [:config, :type], :standard_error) | ||
|
||
# :ok = | ||
# :logger.set_handler_config(:default, put_in(config, [:config, :type], :standard_error)) | ||
|
||
# :logger.remove_handler(:default) | ||
# :ok = | ||
# :logger.add_handler(:default, :logger_std_h, put_in(config, [:config, :type], :standard_error)) | ||
|
||
# Logger.configure(device: :standard_error) | ||
# Logger.Backends.Internal.configure(device: :standard_error) | ||
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. Are you sure this is finished? :P |
||
|
||
Mix.start() | ||
Mix.shell(Mix.Shell.Quiet) | ||
|
||
Mix.install( | ||
[ | ||
{:membrane_file_plugin, path: "."} | ||
] | ||
# force: true | ||
) | ||
|
||
defmodule FileExamplePipeline do | ||
@doc """ | ||
Example pipeline that reads its source code file and outputs it to /tmp/test. | ||
""" | ||
|
||
use Membrane.Pipeline | ||
|
||
@doc false | ||
@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}) | ||
|
||
{[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 | ||
|
||
# # redirect membrane logs to stderr | ||
Membrane.File.Sink.redirect_logs() | ||
|
||
[input] = System.argv() | ||
|
||
{:ok, _supervisor, pid} = | ||
Membrane.Pipeline.start_link(FileExamplePipeline, %{input: input, target: self()}) | ||
|
||
receive do | ||
:done -> Membrane.Pipeline.terminate(pid) | ||
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 |
---|---|---|
@@ -1,18 +1,47 @@ | ||
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: "."} | ||
] | ||
# force: true | ||
) | ||
|
||
[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 | ||
@doc """ | ||
Example pipeline that reads its source code file and outputs it to /tmp/test. | ||
""" | ||
|
||
{:ok, _supervisor, pipeline} = Pipeline.start(spec: spec) | ||
use Membrane.Pipeline | ||
|
||
assert_end_of_stream(pipeline, :sink, :input) | ||
Pipeline.terminate(pipeline) | ||
@doc false | ||
@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}) | ||
|
||
{[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 |
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
kidq330 marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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