From 88f0be96933c287b99469edcfb6483cc91fa73c8 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Mon, 22 Apr 2019 07:19:53 +0000 Subject: Feature/826 healthcheck endpoint --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/pleroma/web/twitter_api/controllers/util_controller.ex') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 8665e058a..197a89966 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -363,4 +363,17 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do def captcha(conn, _params) do json(conn, Pleroma.Captcha.new()) end + + def healthcheck(conn, _params) do + info = Pleroma.Healthcheck.system_info() + + conn = + if info.healthy do + conn + else + Plug.Conn.put_status(conn, :service_unavailable) + end + + json(conn, info) + end end -- cgit v1.2.3 From b9cdf6d3b9940fded7d6be9f8771fd9c211afdd4 Mon Sep 17 00:00:00 2001 From: Egor Date: Mon, 22 Apr 2019 07:20:43 +0000 Subject: Use `User.get_cached*` everywhere --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/pleroma/web/twitter_api/controllers/util_controller.ex') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 197a89966..d0bf3a315 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do def show_password_reset(conn, %{"token" => token}) do with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), - %User{} = user <- User.get_by_id(token.user_id) do + %User{} = user <- User.get_cached_by_id(token.user_id) do render(conn, "password_reset.html", %{ token: token, user: user @@ -113,13 +113,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do def do_remote_follow(conn, %{ "authorization" => %{"name" => username, "password" => password, "id" => id} }) do - followee = User.get_by_id(id) + followee = User.get_cached_by_id(id) avatar = User.avatar_url(followee) name = followee.nickname with %User{} = user <- User.get_cached_by_nickname(username), true <- Pbkdf2.checkpw(password, user.password_hash), - %User{} = _followed <- User.get_by_id(id), + %User{} = _followed <- User.get_cached_by_id(id), {:ok, follower} <- User.follow(user, followee), {:ok, _activity} <- ActivityPub.follow(follower, followee) do conn @@ -141,7 +141,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end def do_remote_follow(%{assigns: %{user: user}} = conn, %{"user" => %{"id" => id}}) do - with %User{} = followee <- User.get_by_id(id), + with %User{} = followee <- User.get_cached_by_id(id), {:ok, follower} <- User.follow(user, followee), {:ok, _activity} <- ActivityPub.follow(follower, followee) do conn -- cgit v1.2.3 From d35246c4490bcca4831b85d23049c04ffff58758 Mon Sep 17 00:00:00 2001 From: Alex S Date: Mon, 22 Apr 2019 17:00:06 +0700 Subject: added healthcheck setting to instance config --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/pleroma/web/twitter_api/controllers/util_controller.ex') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index d0bf3a315..1122e6c5d 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -365,10 +365,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end def healthcheck(conn, _params) do - info = Pleroma.Healthcheck.system_info() + info = + if Pleroma.Config.get([:instance, :healthcheck]) do + Pleroma.Healthcheck.system_info() + else + %{} + end conn = - if info.healthy do + if info[:healthy] do conn else Plug.Conn.put_status(conn, :service_unavailable) -- cgit v1.2.3