mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: allowed user to customize the storage path of the h2 database #521
This commit is contained in:
parent
b8199bf036
commit
8e94976cdd
@ -41,6 +41,8 @@ public class PowerJobDKey {
|
||||
* <a href="https://stackoverflow.com/questions/16504140/thread-stop-deprecated">It's VERY dangerous</a>
|
||||
*/
|
||||
public static final String WORKER_ALLOWED_FORCE_STOP_THREAD = "powerjob.worker.allowed-force-stop-thread";
|
||||
|
||||
public static final String WORKER_WORK_SPACE = "powerjob.worker.workspace";
|
||||
/**
|
||||
* ms
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package tech.powerjob.official.processors.impl.script;
|
||||
|
||||
import tech.powerjob.worker.common.utils.PowerFileUtils;
|
||||
import tech.powerjob.worker.core.processor.ProcessResult;
|
||||
import tech.powerjob.worker.core.processor.TaskContext;
|
||||
import tech.powerjob.worker.log.OmsLogger;
|
||||
@ -34,7 +35,7 @@ public abstract class AbstractScriptProcessor extends CommonBasicProcessor {
|
||||
protected static final String SH_SHELL = "/bin/sh";
|
||||
protected static final String CMD_SHELL = "cmd.exe";
|
||||
|
||||
private static final String WORKER_DIR = System.getProperty("user.home") + "/powerjob/worker/official_script_processor/";
|
||||
private static final String WORKER_DIR = PowerFileUtils.workspace() + "/official_script_processor/";
|
||||
|
||||
@Override
|
||||
protected ProcessResult process0(TaskContext context) throws Exception {
|
||||
|
@ -0,0 +1,30 @@
|
||||
package tech.powerjob.worker.common.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import tech.powerjob.common.PowerJobDKey;
|
||||
|
||||
/**
|
||||
* 文件工具
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2023/1/22
|
||||
*/
|
||||
@Slf4j
|
||||
public class PowerFileUtils {
|
||||
|
||||
/**
|
||||
* 获取工作目录
|
||||
* @return 允许用户通过启动配置文件自定义存储目录,默认为 user.home
|
||||
*/
|
||||
public static String workspace() {
|
||||
String workspaceByDKey = System.getProperty(PowerJobDKey.WORKER_WORK_SPACE);
|
||||
if (StringUtils.isNotEmpty(workspaceByDKey)) {
|
||||
log.info("[PowerFileUtils] [workspace] use custom workspace: {}", workspaceByDKey);
|
||||
return workspaceByDKey;
|
||||
}
|
||||
final String userHome = System.getProperty("user.home").concat("/powerjob/worker");
|
||||
log.info("[PowerFileUtils] [workspace] use user.home as workspace: {}", userHome);
|
||||
return userHome;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import tech.powerjob.worker.common.WorkerRuntime;
|
||||
import tech.powerjob.worker.common.utils.PowerFileUtils;
|
||||
import tech.powerjob.worker.common.utils.TransportUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -26,13 +27,13 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class OmsContainerFactory {
|
||||
|
||||
private static final String CONTAINER_DIR = System.getProperty("user.home") + "/powerjob/worker/container/";
|
||||
private static final String CONTAINER_DIR = PowerFileUtils.workspace() + "/container/";
|
||||
private static final Map<Long, OmsContainer> CARGO = Maps.newConcurrentMap();
|
||||
|
||||
/**
|
||||
* 获取容器
|
||||
* @param containerId 容器ID
|
||||
* @param serverActor 当容器不存在且 serverActor 非空时,尝试从服务端重新拉取容器
|
||||
* @param workerRuntime 当容器不存在且 serverActor 非空时,尝试从服务端重新拉取容器
|
||||
* @return 容器示例,可能为 null
|
||||
*/
|
||||
public static OmsContainer fetchContainer(Long containerId, WorkerRuntime workerRuntime) {
|
||||
|
@ -8,6 +8,7 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.h2.Driver;
|
||||
import tech.powerjob.worker.common.utils.PowerFileUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
@ -25,7 +26,7 @@ public class ConnectionFactory {
|
||||
|
||||
private volatile DataSource dataSource;
|
||||
|
||||
private final String H2_PATH = System.getProperty("user.home") + "/powerjob/worker/h2/" + CommonUtils.genUUID() + "/";
|
||||
private final String H2_PATH = PowerFileUtils.workspace() + "/h2/" + CommonUtils.genUUID() + "/";
|
||||
private final String DISK_JDBC_URL = String.format("jdbc:h2:file:%spowerjob_worker_db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", H2_PATH);
|
||||
private final String MEMORY_JDBC_URL = String.format("jdbc:h2:mem:%spowerjob_worker_db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", H2_PATH);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user