You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/useful_concepts/running_membrane_in_elixir_application.md
+93-78Lines changed: 93 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,85 +6,11 @@ This guide outlines best practices for integrating Membrane Pipelines into your
6
6
7
7
In most cases, pipelines are used in one of the following scenarios:
8
8
9
-
- Batch Processing: Handling "offline" tasks with a clear start and end (e.g. transcoding a stream inside an MP4 file).
10
-
11
9
- Static Orchestration: Maintaining a single, permanent pipeline that always runs with your application (e.g. mixing output from multiple IP cameras into a single HLS stream).
12
10
13
11
- Dynamic Orchestration: Spawning pipelines on-demand based on user actions (e.g. starting a unique pipeline for every user joining a conference room).
14
12
15
-
### Batch Processing
16
-
17
-
Batch processing is ideal for "offline tasks" where you need to ensure the job completes successfully.
18
-
19
-
For example, let's assume we want to transcode video from H.264 (in MP4) to VP8 (in Matroska). To achieve this, we build the pipeline as follows:
To ensure reliability, we might wrap this execution in an [Oban](https://hexdocs.pm/oban/Oban.html) worker.
49
-
50
-
Oban is the standard library for background job processing in Elixir. It persists jobs to your database, ensuring that your long-running transcoding tasks are fault-tolerant.
51
-
If the pipeline crashes or the server restarts, Oban will automatically retry the job until it succeeds.
caseMembrane.Pipeline.wait_for_termination(pipeline_pid, 100_000) do
69
-
:ok->:ok
70
-
{:error, reason} -> {:error, reason}
71
-
end
72
-
end
73
-
end
74
-
```
75
-
76
-
Now we can run the Oban worker:
77
-
78
-
```elixir
79
-
%{
80
-
"input_path"=>"uploads/input_video.mp4",
81
-
"output_path"=>"processed/transcoded_video.mkv"
82
-
}
83
-
|>VideoTranscoderWorker.new()
84
-
|>Oban.insert()
85
-
```
86
-
87
-
When the job terminates successfully, you will see the output `.mkv` file with transcoded video.
13
+
- Batch Processing: Handling "offline" tasks with a clear start and end (e.g. transcoding a stream inside an MP4 file).
88
14
89
15
### Static Orchestration: Supervisor on Startup
90
16
@@ -167,17 +93,106 @@ defmodule MyProject.Application do
167
93
end
168
94
```
169
95
170
-
Now, whenever a new pipeline is needed you can spawn a new instance of your infrastructure using `DynamicSupervisor.start_child/2`.
96
+
Now, whenever a new pipeline is needed you can spawn a new instance of your infrastructure using [`DynamicSupervisor.start_child/2`](https://hexdocs.pm/elixir/1.12/DynamicSupervisor.html#start_child/2).
171
97
It could happen e.g. inside `mount/3` callback of your LiveView:
When you need to stop the pipeline, you can use [`DynamicSupervisor.terminate_child/2`](https://hexdocs.pm/elixir/1.12/DynamicSupervisor.html#terminate_child/2).
114
+
115
+
In case of your LiveView commponent it could happen in its `terminate/2` callback:
116
+
117
+
```elixir
118
+
defterminate(_reason, socket) do
119
+
if pid = socket.assigns[:infrastructure_supervisor_pid] do
To ensure reliability, we might wrap this execution in an [Oban](https://hexdocs.pm/oban/Oban.html) worker.
160
+
161
+
Oban is the standard library for background job processing in Elixir. It persists jobs to your database, ensuring that your long-running transcoding tasks are fault-tolerant.
162
+
If the pipeline crashes or the server restarts, Oban will automatically retry the job until it succeeds.
0 commit comments