mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: PowerJobClient support shutdown #895
This commit is contained in:
parent
3e0088870a
commit
605497b36d
@ -23,6 +23,8 @@ import tech.powerjob.common.serialize.JsonUtils;
|
|||||||
import tech.powerjob.common.utils.CommonUtils;
|
import tech.powerjob.common.utils.CommonUtils;
|
||||||
import tech.powerjob.common.utils.DigestUtils;
|
import tech.powerjob.common.utils.DigestUtils;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ import static tech.powerjob.client.TypeStore.*;
|
|||||||
* @since 2020/4/15
|
* @since 2020/4/15
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PowerJobClient implements IPowerJobClient {
|
public class PowerJobClient implements IPowerJobClient, Closeable {
|
||||||
|
|
||||||
private Long appId;
|
private Long appId;
|
||||||
|
|
||||||
@ -546,4 +548,8 @@ public class PowerJobClient implements IPowerJobClient {
|
|||||||
return JSON.parseObject(post, WF_INSTANCE_RESULT_TYPE);
|
return JSON.parseObject(post, WF_INSTANCE_RESULT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
requestService.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package tech.powerjob.client.service;
|
package tech.powerjob.client.service;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求服务
|
* 请求服务
|
||||||
*
|
*
|
||||||
* @author tjq
|
* @author tjq
|
||||||
* @since 2024/2/20
|
* @since 2024/2/20
|
||||||
*/
|
*/
|
||||||
public interface RequestService {
|
public interface RequestService extends Closeable {
|
||||||
|
|
||||||
|
|
||||||
String request(String path, PowerRequestBody powerRequestBody);
|
String request(String path, PowerRequestBody powerRequestBody);
|
||||||
|
@ -131,4 +131,17 @@ public class ClusterRequestServiceOkHttp3Impl extends AppAuthClusterRequestServi
|
|||||||
.connectTimeout(Optional.ofNullable(config.getReadTimeout()).orElse(DEFAULT_TIMEOUT_SECONDS), TimeUnit.SECONDS);
|
.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user