Skip to content
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

style: Fix some typos in the codebase #586

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions apps/lenra/lib/lenra/apps.ex
Original file line number Diff line number Diff line change
Expand Up @@ -321,37 +321,37 @@ defmodule Lenra.Apps do
# Deployments #
###############

def all_deployements(app_id) do
def all_deployments(app_id) do
Repo.all(from(d in Deployment, where: d.application_id == ^app_id, order_by: d.id))
end

def get_deployement(build_id, env_id) do
def get_deployment(build_id, env_id) do
Repo.one(from(d in Deployment, where: d.build_id == ^build_id and d.environment_id == ^env_id))
end

def get_deployement_for_build(build_id) do
def get_deployment_for_build(build_id) do
Repo.one(from(d in Deployment, where: d.build_id == ^build_id))
end

def deploy_in_main_env(%Build{} = build) do
with loaded_build <- Repo.preload(build, :application),
loaded_app <- Repo.preload(loaded_build.application, main_env: [:environment]),
%Deployment{} = deployment <-
get_deployement(build.id, loaded_app.main_env.environment.id),
get_deployment(build.id, loaded_app.main_env.environment.id),
{:ok, _status} <-
OpenfaasServices.deploy_app(
loaded_build.application.service_name,
build.build_number,
Subscriptions.get_max_replicas(loaded_build.application.id)
) do
update_deployement(deployment, status: :waitingForAppReady)
update_deployment(deployment, status: :waitingForAppReady)

spawn(fn ->
Logger.debug(
"#{__MODULE__} start waiting for app ready with params #{inspect(%{build: build, loaded_app: loaded_app, deployment: deployment})}"
"#{__MODULE__} waiting for app to be ready with params #{inspect(%{build: build, loaded_app: loaded_app, deployment: deployment})}"
)

update_deployement_after_deploy(
update_deployment_after_deploy(
deployment,
loaded_app.main_env.environment,
loaded_app.service_name,
Expand Down Expand Up @@ -384,10 +384,10 @@ defmodule Lenra.Apps do
|> Repo.transaction()
end

def update_deployement_after_deploy(deployment, env, service_name, build_number),
do: update_deployement_after_deploy(deployment, env, service_name, build_number, 0)
def update_deployment_after_deploy(deployment, env, service_name, build_number),
do: update_deployment_after_deploy(deployment, env, service_name, build_number, 0)

def update_deployement_after_deploy(deployment, env, service_name, build_number, retry)
def update_deployment_after_deploy(deployment, env, service_name, build_number, retry)
when retry <= 120 do
case OpenfaasServices.is_deploy(service_name, build_number) do
true ->
Expand All @@ -411,27 +411,27 @@ defmodule Lenra.Apps do
# To let openfaas deploy in case of overload, after 2 retry -> failure
:error404 ->
if retry == 3 do
Logger.critical("Function #{service_name} not deploy on openfaas, this should not appens")
Logger.critical("Function #{service_name} could not be deployed on openfaas")

update_deployement(deployment, status: :failure)
update_deployment(deployment, status: :failure)
else
Process.sleep(5000)
update_deployement_after_deploy(deployment, env, service_name, build_number, retry + 1)
update_deployment_after_deploy(deployment, env, service_name, build_number, retry + 1)
end

:error500

_any ->
Process.sleep(5000)
update_deployement_after_deploy(deployment, env, service_name, build_number, retry + 1)
update_deployment_after_deploy(deployment, env, service_name, build_number, retry + 1)
end
end

def update_deployement_after_deploy(deployment, _env, _service_name, _build_number, _retry),
do: update_deployement(deployment, status: :failure)
def update_deployment_after_deploy(deployment, _env, _service_name, _build_number, _retry),
do: update_deployment(deployment, status: :failure)

def update_deployement(deployement, change) do
deployement
def update_deployment(deployment, change) do
deployment
|> Ecto.Changeset.change(change)
|> Repo.update()
end
Expand Down
2 changes: 1 addition & 1 deletion apps/lenra/lib/lenra/kubernetes/api_services.ex
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ defmodule Lenra.Kubernetes.ApiServices do
end

defp response({:ok, %Finch.Response{status: status_code, body: body}}, _atom) do
Logger.critical("#{__MODULE__} kubernetes return status code #{status_code} with message #{inspect(body)}")
Logger.critical("#{__MODULE__} kubernetes returned status code #{status_code} with message #{inspect(body)}")

{:error, :kubernetes_error}
end
Expand Down
4 changes: 2 additions & 2 deletions apps/lenra/lib/lenra/kubernetes/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ defmodule Lenra.Kubernetes.Status do

def update_deployment(build) do
build.id
|> Apps.get_deployement_for_build()
|> Apps.update_deployement(%{status: :failure})
|> Apps.get_deployment_for_build()
|> Apps.update_deployment(%{status: :failure})
end

defp response({:ok, %Finch.Response{status: 200, body: body}}) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule LenraWeb.DeploymentsController do
preloaded_app <- Repo.preload(app, main_env: [:environment]),
:ok <- allow(conn, preloaded_app.main_env.environment) do
conn
|> reply(Apps.all_deployements(app.id))
|> reply(Apps.all_deployments(app.id))
end
end

Expand Down
4 changes: 2 additions & 2 deletions apps/lenra_web/lib/lenra_web/controllers/runner_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule LenraWeb.RunnerController do

defp maybe_deploy_in_main_env(build, "failure") do
build.id
|> Apps.get_deployement_for_build()
|> Apps.update_deployement(%{status: :failure})
|> Apps.get_deployment_for_build()
|> Apps.update_deployment(%{status: :failure})

{:ok, :not_deployed}
end
Expand Down
2 changes: 1 addition & 1 deletion libs/application_runner/lib/errors/business_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ApplicationRunner.Errors.BusinessError do
module: LenraCommon.Errors.BusinessError,
inherit: true,
errors: [
{:env_not_started, "Environment not stated."},
{:env_not_started, "Environment not started."},
{:invalid_token, "Your token is invalid."},
{:did_not_accept_cgs, "You must accept the CGS to use Lenra"},
{:unknow_listener_code, "No listeners found for the given code"},
Expand Down
Loading