Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

web: switch to Task.Supervisor.start_child for deploy to avoid crashing

+42 -49
+41 -48
apps/sower/lib/sower/orchestration.ex
··· 959 959 960 960 %Agent{} = agent -> 961 961 request_id = SowerClient.Sid.generate("request") 962 - {:ok, request_id, _task} = process_deployment(request_id, [subscription], agent, opts) 962 + {:ok, request_id} = process_deployment(request_id, [subscription], agent, opts) 963 963 {:ok, request_id} 964 964 end 965 965 end ··· 1015 1015 def handle_deployment_request(payload, agent) do 1016 1016 with {:ok, request} <- SowerClient.Orchestration.DeploymentRequest.cast(payload), 1017 1017 {:ok, subscriptions} <- validate_deployment_request(request, agent.id), 1018 - {:ok, request_id, task} <- 1018 + {:ok, request_id} <- 1019 1019 process_deployment(request.request_id, subscriptions, agent, force: request.force) do 1020 - {:ok, request_id, task} 1020 + {:ok, request_id} 1021 1021 end 1022 1022 end 1023 1023 ··· 1042 1042 @doc """ 1043 1043 Process a deployment request asynchronously. 1044 1044 1045 - Spawns an async task to match seeds, create deployment record, and broadcast 1046 - results back to agent via channel. Validation happens synchronously before 1047 - task spawn. 1045 + Spawns a fire-and-forget task to match seeds, create deployment record, and 1046 + broadcast results back to agent via channel. Validation happens synchronously 1047 + before task spawn. 1048 1048 1049 - Returns {:ok, request_id, task} where task is the async %Task{}. 1049 + Returns {:ok, request_id} on success. 1050 1050 Returns {:error, reason} if validation fails. 1051 - 1052 - ## Examples 1053 - 1054 - iex> {:ok, request_id, task} = process_deployment(request_id, subscriptions, agent) 1055 - iex> Task.await(task) 1056 - 1057 1051 """ 1058 1052 def process_deployment(request_id, subscriptions, %Agent{} = agent, opts \\ []) do 1059 - task = 1060 - Task.Supervisor.async_nolink(Sower.TaskSupervisor, fn -> 1061 - Repo.put_org_id(agent.org_id) 1053 + Task.Supervisor.start_child(Sower.TaskSupervisor, fn -> 1054 + Repo.put_org_id(agent.org_id) 1062 1055 1063 - Logger.info( 1064 - msg: "Deployment processing started", 1065 - request_id: request_id, 1066 - agent_id: agent.id 1067 - ) 1056 + Logger.info( 1057 + msg: "Deployment processing started", 1058 + request_id: request_id, 1059 + agent_id: agent.id 1060 + ) 1068 1061 1069 - case do_deployment(request_id, subscriptions, opts) do 1070 - {:ok, deployment} -> 1071 - Logger.info( 1072 - msg: "Deployment broadcast successful", 1073 - request_id: request_id, 1074 - deployment_sid: deployment.sid, 1075 - skipped: deployment.skipped 1076 - ) 1062 + case do_deployment(request_id, subscriptions, opts) do 1063 + {:ok, deployment} -> 1064 + Logger.info( 1065 + msg: "Deployment broadcast successful", 1066 + request_id: request_id, 1067 + deployment_sid: deployment.sid, 1068 + skipped: deployment.skipped 1069 + ) 1077 1070 1078 - SowerWeb.Endpoint.broadcast( 1079 - "agent:#{agent.sid}", 1080 - "deployment", 1081 - Map.from_struct(deployment) 1082 - ) 1071 + SowerWeb.Endpoint.broadcast( 1072 + "agent:#{agent.sid}", 1073 + "deployment", 1074 + Map.from_struct(deployment) 1075 + ) 1083 1076 1084 - {:error, reason} -> 1085 - Logger.error( 1086 - msg: "Deployment processing failed", 1087 - request_id: request_id, 1088 - reason: to_string(reason) 1089 - ) 1077 + {:error, reason} -> 1078 + Logger.error( 1079 + msg: "Deployment processing failed", 1080 + request_id: request_id, 1081 + reason: to_string(reason) 1082 + ) 1090 1083 1091 - SowerWeb.Endpoint.broadcast( 1092 - "agent:#{agent.sid}", 1093 - "deployment:error", 1094 - %{request_id: request_id, reason: to_string(reason)} 1095 - ) 1096 - end 1097 - end) 1084 + SowerWeb.Endpoint.broadcast( 1085 + "agent:#{agent.sid}", 1086 + "deployment:error", 1087 + %{request_id: request_id, reason: to_string(reason)} 1088 + ) 1089 + end 1090 + end) 1098 1091 1099 - {:ok, request_id, task} 1092 + {:ok, request_id} 1100 1093 end 1101 1094 1102 1095 defp do_deployment(request_id, subscriptions, opts) do
+1 -1
apps/sower/lib/sower_web/agent_channel.ex
··· 121 121 req, 122 122 socket.assigns.agent 123 123 ) do 124 - {:ok, request_id, _task} -> 124 + {:ok, request_id} -> 125 125 {:ok, %{request_id: request_id}} 126 126 127 127 {:error, error} ->