feat: PowerJobClient support shutdown #895

This commit is contained in:
tjq 2024-08-11 00:50:25 +08:00
parent 3e0088870a
commit 605497b36d
3 changed files with 24 additions and 3 deletions

View File

@ -23,6 +23,8 @@ import tech.powerjob.common.serialize.JsonUtils;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.common.utils.DigestUtils;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -35,7 +37,7 @@ import static tech.powerjob.client.TypeStore.*;
* @since 2020/4/15
*/
@Slf4j
public class PowerJobClient implements IPowerJobClient {
public class PowerJobClient implements IPowerJobClient, Closeable {
private Long appId;
@ -545,5 +547,9 @@ public class PowerJobClient implements IPowerJobClient {
String post = requestService.request(OpenAPIConstant.FETCH_WORKFLOW_INSTANCE_INFO, PowerRequestBody.newFormRequestBody(param));
return JSON.parseObject(post, WF_INSTANCE_RESULT_TYPE);
}
@Override
public void close() throws IOException {
requestService.close();
}
}

View File

@ -1,12 +1,14 @@
package tech.powerjob.client.service;
import java.io.Closeable;
/**
* 请求服务
*
* @author tjq
* @since 2024/2/20
*/
public interface RequestService {
public interface RequestService extends Closeable {
String request(String path, PowerRequestBody powerRequestBody);

View File

@ -131,4 +131,17 @@ public class ClusterRequestServiceOkHttp3Impl extends AppAuthClusterRequestServi
.connectTimeout(Optional.ofNullable(config.getReadTimeout()).orElse(DEFAULT_TIMEOUT_SECONDS), TimeUnit.SECONDS);
}
@Override
public void close() throws IOException {
// 关闭 Dispatcher
okHttpClient.dispatcher().executorService().shutdown();
// 清理连接池
okHttpClient.connectionPool().evictAll();
// 清理缓存如果有使用
Cache cache = okHttpClient.cache();
if (cache != null) {
cache.close();
}
}
}