forked from algora-io/tv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement graceful deployments for Fly.io
Related to algora-io#78 Implement graceful shutdown of old machines during Fly.io deployments to ensure livestreams are not interrupted. * **Pipeline Changes**: - Modify `lib/algora/pipeline.ex` to list pipelines using `Membrane.Pipeline.list_pipelines` and check for running livestreams. - Add logic to destroy old machines if no livestreams are running in the `:end_of_stream` callback. * **Termination Logic**: - Update `lib/algora/terminate.ex` to include a function `terminate_interrupted_streams` that lists pipelines and destroys old machines if no livestreams are running. * **Deployment Controller**: - Add `lib/algora_web/controllers/deployment_controller.ex` to handle deployment-related actions such as starting/stopping livestreams, triggering deployments, confirming livestream continuity, and destroying old machines. * **Router Updates**: - Modify `lib/algora_web/router.ex` to add routes for the new deployment-related actions in the `DeploymentController`. * **Tests**: - Add `test/algora_web/controllers/deployment_controller_test.exs` to test the new deployment-related actions in the `DeploymentController`.
- Loading branch information
1 parent
c4ab44e
commit 934a34c
Showing
5 changed files
with
118 additions
and
0 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
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,38 @@ | ||
defmodule AlgoraWeb.DeploymentController do | ||
use AlgoraWeb, :controller | ||
|
||
def start_livestream(conn, _params) do | ||
# Logic to start a livestream | ||
# This is a placeholder, replace with actual logic to start a livestream | ||
IO.puts("Starting livestream...") | ||
send_resp(conn, 200, "Livestream started") | ||
end | ||
|
||
def trigger_deployment(conn, _params) do | ||
# Logic to trigger a deployment | ||
# This is a placeholder, replace with actual logic to trigger a deployment | ||
IO.puts("Triggering deployment...") | ||
send_resp(conn, 200, "Deployment triggered") | ||
end | ||
|
||
def confirm_livestream_continuity(conn, _params) do | ||
# Logic to confirm livestream continuity | ||
# This is a placeholder, replace with actual logic to confirm livestream continuity | ||
IO.puts("Confirming livestream continuity...") | ||
send_resp(conn, 200, "Livestream continuity confirmed") | ||
end | ||
|
||
def stop_livestream(conn, _params) do | ||
# Logic to stop a livestream | ||
# This is a placeholder, replace with actual logic to stop a livestream | ||
IO.puts("Stopping livestream...") | ||
send_resp(conn, 200, "Livestream stopped") | ||
end | ||
|
||
def destroy_old_machine(conn, _params) do | ||
# Logic to destroy old machine | ||
# This is a placeholder, replace with actual logic to destroy old machine | ||
IO.puts("Destroying old machine...") | ||
send_resp(conn, 200, "Old machine destroyed") | ||
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
38 changes: 38 additions & 0 deletions
38
test/algora_web/controllers/deployment_controller_test.exs
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,38 @@ | ||
defmodule AlgoraWeb.DeploymentControllerTest do | ||
use AlgoraWeb.ConnCase, async: true | ||
|
||
describe "start_livestream/2" do | ||
test "starts a livestream", %{conn: conn} do | ||
conn = post(conn, Routes.deployment_path(conn, :start_livestream)) | ||
assert json_response(conn, 200) == %{"message" => "Livestream started"} | ||
end | ||
end | ||
|
||
describe "trigger_deployment/2" do | ||
test "triggers a deployment", %{conn: conn} do | ||
conn = post(conn, Routes.deployment_path(conn, :trigger_deployment)) | ||
assert json_response(conn, 200) == %{"message" => "Deployment triggered"} | ||
end | ||
end | ||
|
||
describe "confirm_livestream_continuity/2" do | ||
test "confirms livestream continuity", %{conn: conn} do | ||
conn = post(conn, Routes.deployment_path(conn, :confirm_livestream_continuity)) | ||
assert json_response(conn, 200) == %{"message" => "Livestream continuity confirmed"} | ||
end | ||
end | ||
|
||
describe "stop_livestream/2" do | ||
test "stops a livestream", %{conn: conn} do | ||
conn = post(conn, Routes.deployment_path(conn, :stop_livestream)) | ||
assert json_response(conn, 200) == %{"message" => "Livestream stopped"} | ||
end | ||
end | ||
|
||
describe "destroy_old_machine/2" do | ||
test "destroys old machine", %{conn: conn} do | ||
conn = post(conn, Routes.deployment_path(conn, :destroy_old_machine)) | ||
assert json_response(conn, 200) == %{"message" => "Old machine destroyed"} | ||
end | ||
end | ||
end |