-
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.
Signed-off-by: edmondfrank <[email protected]>
- Loading branch information
1 parent
a8e0ac3
commit 08ba14d
Showing
8 changed files
with
175 additions
and
1 deletion.
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,61 @@ | ||
defmodule CompassAdmin.Agents.ProxyAgent do | ||
use GenServer | ||
|
||
alias CompassAdmin.User | ||
alias CompassAdmin.Agents.DeployAgent | ||
|
||
@agent_svn "proxy_v1" | ||
|
||
def start_link(_) do | ||
GenServer.start_link(__MODULE__, [], name: __MODULE__) | ||
end | ||
|
||
def init(_) do | ||
{:ok, DeployAgent.init(@agent_svn)} | ||
end | ||
|
||
def execute(trigger_id) do | ||
GenServer.cast(__MODULE__, {:deploy, trigger_id}) | ||
end | ||
|
||
def get_state() do | ||
GenServer.call(__MODULE__, :get_state) | ||
end | ||
|
||
def update_deploy_state(deploy_state, last_deploy_id, last_deploy_result) do | ||
GenServer.cast( | ||
__MODULE__, | ||
{:update_deploy_state, deploy_state, last_deploy_id, last_deploy_result} | ||
) | ||
end | ||
|
||
def append_log(log) do | ||
GenServer.cast(__MODULE__, {:append, log}) | ||
end | ||
|
||
def handle_call(:get_state, _from, state) do | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_cast({:update_deploy_state, deploy_state, last_deploy_id, last_deploy_result}, state) do | ||
{:noreply, | ||
DeployAgent.update_deploy_state( | ||
state, | ||
deploy_state, | ||
last_deploy_id, | ||
last_deploy_result | ||
)} | ||
end | ||
|
||
def handle_cast({:append, log}, state) do | ||
{:noreply, DeployAgent.append_log(state, log)} | ||
end | ||
|
||
def handle_cast({:deploy, trigger_id}, state) do | ||
{:noreply, DeployAgent.deploy(__MODULE__, state, trigger_id, User.frontend_dev_role())} | ||
end | ||
|
||
def handle_info(_msg, state) do | ||
{:noreply, state} | ||
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
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,88 @@ | ||
defmodule CompassAdminWeb.ProxyDeploymentLive do | ||
use CompassAdminWeb, :live_view | ||
|
||
alias CompassAdmin.User | ||
alias CompassAdmin.Agents.ProxyAgent | ||
|
||
import CompassAdmin.Utils, only: [apm_call: 3] | ||
|
||
@impl true | ||
def mount(_params, %{"current_user" => current_user}, socket) do | ||
if connected?(socket), do: Process.send_after(self(), :refresh, 5000) | ||
|
||
state = apm_call(ProxyAgent, :get_state, []) | ||
last_deploy_user = User.find(state.last_deploy_id, preloads: :login_binds) | ||
last_trigger_user = User.find(state.last_trigger_id, preloads: :login_binds) | ||
last_deployer = if last_deploy_user, do: List.first(last_deploy_user.login_binds) | ||
last_trigger = if last_trigger_user, do: List.first(last_trigger_user.login_binds) | ||
can_deploy = current_user.role_level >= User.frontend_dev_role() | ||
|
||
{:ok, | ||
assign(socket, | ||
title: "Proxy recent deployment logs", | ||
agent_state: state, | ||
can_deploy: can_deploy, | ||
current_user: current_user, | ||
last_trigger: last_trigger, | ||
last_deployer: last_deployer | ||
)} | ||
end | ||
|
||
@impl true | ||
def handle_params(_params, _uri, socket) do | ||
case socket.assigns.live_action do | ||
:index -> | ||
{:noreply, assign(socket, action: :index)} | ||
end | ||
end | ||
|
||
@impl true | ||
def handle_info(:refresh, socket) do | ||
Process.send_after(self(), :refresh, 5000) | ||
|
||
state = apm_call(ProxyAgent, :get_state, []) | ||
last_deploy_user = User.find(state.last_deploy_id, preloads: :login_binds) | ||
last_trigger_user = User.find(state.last_trigger_id, preloads: :login_binds) | ||
last_deployer = if last_deploy_user, do: List.first(last_deploy_user.login_binds) | ||
last_trigger = if last_trigger_user, do: List.first(last_trigger_user.login_binds) | ||
|
||
{:noreply, | ||
assign(socket, | ||
agent_state: state, | ||
last_trigger: last_trigger, | ||
last_deployer: last_deployer | ||
)} | ||
end | ||
|
||
@impl true | ||
def handle_event("deploy", _value, socket) do | ||
apm_call(ProxyAgent, :execute, [socket.assigns.current_user.id]) | ||
Process.sleep(1000) | ||
state = apm_call(ProxyAgent, :get_state, []) | ||
last_deploy_user = User.find(state.last_deploy_id, preloads: :login_binds) | ||
last_trigger_user = User.find(state.last_trigger_id, preloads: :login_binds) | ||
last_deployer = if last_deploy_user, do: List.first(last_deploy_user.login_binds) | ||
last_trigger = if last_trigger_user, do: List.first(last_trigger_user.login_binds) | ||
|
||
{:noreply, | ||
assign(socket, | ||
agent_state: state, | ||
last_trigger: last_trigger, | ||
last_deployer: last_deployer | ||
)} | ||
end | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<.deployment_page | ||
title={@title} | ||
agent_state={@agent_state} | ||
last_trigger={@last_trigger} | ||
last_deployer={@last_deployer} | ||
can_deploy={@can_deploy} | ||
> | ||
</.deployment_page> | ||
""" | ||
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
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