From a88d201b91578f27da32fe1e6ea1c69cd3eb9490 Mon Sep 17 00:00:00 2001 From: codenamewei Date: Thu, 19 Aug 2021 09:31:45 +0800 Subject: [PATCH] :sparkles: API to terminate classifai --- .../ai/classifai/router/EndpointRouter.java | 2 ++ .../java/ai/classifai/router/V2Endpoint.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/classifai-core/src/main/java/ai/classifai/router/EndpointRouter.java b/classifai-core/src/main/java/ai/classifai/router/EndpointRouter.java index 48e6b1c23..7d6480cd2 100644 --- a/classifai-core/src/main/java/ai/classifai/router/EndpointRouter.java +++ b/classifai-core/src/main/java/ai/classifai/router/EndpointRouter.java @@ -159,6 +159,8 @@ public void start(Promise promise) router.delete("/v2/:annotation_type/projects/:project_name/uuids").handler(v2::deleteProjectData); + router.put("/v2/close").handler(v2::closeClassifai); + //*******************************Cloud******************************* router.put("/v2/:annotation_type/wasabi/projects/:project_name").handler(cloud::createWasabiCloudProject); diff --git a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java index 1dc8db38f..3959a587b 100644 --- a/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java +++ b/classifai-core/src/main/java/ai/classifai/router/V2Endpoint.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; /** * Classifai v2 endpoints @@ -560,6 +561,29 @@ public void selectProjectFolder(RoutingContext context) HTTPResponseHandler.configureOK(context); } + /** + * Close/terminate classifai + * PUT http://localhost:{port}/v2/close + * + * Example: + * PUT http://localhost:{port}/v2/close + */ + public void closeClassifai(RoutingContext context) + { + HTTPResponseHandler.configureOK(context); + + //terminate after 1 seconds + new java.util.Timer().schedule( + new java.util.TimerTask() { + @Override + public void run() { + System.exit(0); + } + }, + 1000 + ); + } + /** * Get status of choosing a project folder * GET http://localhost:{port}/v2/folders