@@ -28,7 +28,7 @@ defmodule RealtimeWeb.TenantController do
2828
2929 action_fallback ( RealtimeWeb.FallbackController )
3030
31- plug :set_observability_attributes when action in [ :show , :edit , :update , :delete , :reload , :health ]
31+ plug :set_observability_attributes when action in [ :show , :edit , :update , :delete , :reload , :shutdown , : health]
3232
3333 operation ( :index ,
3434 summary: "List tenants" ,
@@ -77,13 +77,8 @@ defmodule RealtimeWeb.TenantController do
7777 tenant = Api . get_tenant_by_external_id ( id )
7878
7979 case tenant do
80- % Tenant { } = tenant ->
81- render ( conn , "show.json" , tenant: tenant )
82-
83- nil ->
84- conn
85- |> put_status ( 404 )
86- |> render ( "not_found.json" , tenant: nil )
80+ % Tenant { } = tenant -> render ( conn , "show.json" , tenant: tenant )
81+ nil -> { :error , :not_found }
8782 end
8883 end
8984
@@ -201,7 +196,6 @@ defmodule RealtimeWeb.TenantController do
201196 send_resp ( conn , 204 , "" )
202197 else
203198 nil ->
204- log_error ( "TenantNotFound" , "Tenant not found" )
205199 send_resp ( conn , 204 , "" )
206200
207201 err ->
@@ -233,11 +227,7 @@ defmodule RealtimeWeb.TenantController do
233227 def reload ( conn , % { "tenant_id" => tenant_id } ) do
234228 case Api . get_tenant_by_external_id ( tenant_id , use_replica?: false ) do
235229 nil ->
236- log_error ( "TenantNotFound" , "Tenant not found" )
237-
238- conn
239- |> put_status ( 404 )
240- |> render ( "not_found.json" , tenant: nil )
230+ { :error , :not_found }
241231
242232 tenant ->
243233 PostgresCdc . stop_all ( tenant , @ stop_timeout )
@@ -247,6 +237,37 @@ defmodule RealtimeWeb.TenantController do
247237 end
248238 end
249239
240+ operation ( :shutdown ,
241+ summary: "Shutdowns the Connect module for a tenant" ,
242+ parameters: [
243+ token: [
244+ in: :header ,
245+ name: "Authorization" ,
246+ schema: % OpenApiSpex.Schema { type: :string } ,
247+ required: true ,
248+ example:
249+ "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2ODAxNjIxNTR9.U9orU6YYqXAtpF8uAiw6MS553tm4XxRzxOhz2IwDhpY"
250+ ] ,
251+ tenant_id: [ in: :path , description: "Tenant ID" , type: :string ]
252+ ] ,
253+ responses: % {
254+ 204 => EmptyResponse . response ( ) ,
255+ 403 => EmptyResponse . response ( ) ,
256+ 404 => NotFoundResponse . response ( )
257+ }
258+ )
259+
260+ def shutdown ( conn , % { "tenant_id" => tenant_id } ) do
261+ case Api . get_tenant_by_external_id ( tenant_id , use_replica?: false ) do
262+ nil ->
263+ { :error , :not_found }
264+
265+ tenant ->
266+ Connect . shutdown ( tenant . external_id )
267+ send_resp ( conn , 204 , "" )
268+ end
269+ end
270+
250271 operation ( :health ,
251272 summary: "Tenant health" ,
252273 parameters: [
@@ -269,18 +290,9 @@ defmodule RealtimeWeb.TenantController do
269290
270291 def health ( conn , % { "tenant_id" => tenant_id } ) do
271292 case Tenants . health_check ( tenant_id ) do
272- { :ok , response } ->
273- json ( conn , % { data: response } )
274-
275- { :error , % { healthy: false } = response } ->
276- json ( conn , % { data: response } )
277-
278- { :error , :tenant_not_found } ->
279- log_error ( "TenantNotFound" , "Tenant not found" )
280-
281- conn
282- |> put_status ( 404 )
283- |> render ( "not_found.json" , tenant: nil )
293+ { :ok , response } -> json ( conn , % { data: response } )
294+ { :error , % { healthy: false } = response } -> json ( conn , % { data: response } )
295+ { :error , :tenant_not_found } -> { :error , :not_found }
284296 end
285297 end
286298
0 commit comments