Skip to content

Commit

Permalink
chore: 优化任务调度服务端配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 14, 2024
1 parent 8c3fe35 commit c5cd4e2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 100 deletions.
23 changes: 0 additions & 23 deletions continew-extension/continew-extension-schedule-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,11 @@
<version>${snail-job.version}</version>
</dependency>

<!-- MyBatis Plus(MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,简化开发、提高效率) -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
</dependency>

<!-- Dynamic Datasource(基于 Spring Boot 的快速集成多数据源的启动器) -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
</dependency>

<!-- Liquibase(用于管理数据库版本,跟踪、管理和应用数据库变化) -->
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,43 @@

package top.continew.admin.extension.scheduling;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.spring.SpringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;

/**
* 任务调度服务端启动程序
*
* @author KAI
* @since 2024/6/25 22:24
*/
@Slf4j
@SpringBootApplication
public class ScheduleServerApplication {
@RequiredArgsConstructor
public class ScheduleServerApplication extends com.aizuda.snailjob.server.SnailJobServerApplication implements ApplicationRunner {

private final ServerProperties serverProperties;

public static void main(String[] args) {
SpringApplication.run(com.aizuda.snailjob.server.SnailJobServerApplication.class, args);
SpringApplication.run(ScheduleServerApplication.class, args);
}

@Override
public void run(ApplicationArguments args) {
String hostAddress = NetUtil.getLocalhostStr();
Integer port = serverProperties.getPort();
String contextPath = serverProperties.getServlet().getContextPath();
String baseUrl = URLUtil.normalize("%s:%s%s".formatted(hostAddress, port, contextPath));
log.info("----------------------------------------------");
log.info("{} service started successfully.", SpringUtil.getApplicationName());
log.info("API 地址:{}", baseUrl);
log.info("----------------------------------------------");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,15 @@ server:

--- ### 数据源配置
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
## 动态数据源配置(可配多主多从:m1、s1...;纯粹多库:mysql、oracle...;混合配置:m1、s1、oracle...)
dynamic:
# 设置默认的数据源或者数据源组(默认:master)
primary: master
# 严格匹配数据源(true:未匹配到指定数据源时抛异常;false:使用默认数据源;默认 false)
strict: false
datasource:
# 主库配置(可配多个,构成多主)
master:
url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false&allowPublicKeyRetrieval=true
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
hikari:
# 最大连接数量(默认 10,根据实际环境调整)
# 注意:当连接达到上限,并且没有空闲连接可用时,获取连接将在超时前阻塞最多 connectionTimeout 毫秒
max-pool-size: 20
# 获取连接超时时间(默认 30000 毫秒,30 秒)
connection-timeout: 30000
# 空闲连接最大存活时间(默认 600000 毫秒,10 分钟)
idle-timeout: 600000
# 保持连接活动的频率,以防止它被数据库或网络基础设施超时。该值必须小于 maxLifetime(默认 0,禁用)
keepaliveTime: 30000
# 连接最大生存时间(默认 1800000 毫秒,30 分钟)
max-lifetime: 1800000
url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
# # PostgreSQL 配置
# url: jdbc:postgresql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
# password: ${DB_PWD:123456}
# driver-class-name: org.postgresql.Driver
## Liquibase 配置
spring.liquibase:
# 是否启用
Expand Down Expand Up @@ -67,3 +49,10 @@ snail-job:
max-count: 288
# 配置回调触发的间隔时间
trigger-interval: 900

--- ### 日志配置
logging:
level:
com.aizuda.snailjob: DEBUG
file:
path: ./logs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,15 @@ server:

--- ### 数据源配置
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
## 动态数据源配置(可配多主多从:m1、s1...;纯粹多库:mysql、oracle...;混合配置:m1、s1、oracle...)
dynamic:
# 设置默认的数据源或者数据源组(默认:master)
primary: master
# 严格匹配数据源(true:未匹配到指定数据源时抛异常;false:使用默认数据源;默认 false)
strict: false
datasource:
# 主库配置(可配多个,构成多主)
master:
url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
hikari:
# 最大连接数量(默认 10,根据实际环境调整)
# 注意:当连接达到上限,并且没有空闲连接可用时,获取连接将在超时前阻塞最多 connectionTimeout 毫秒
max-pool-size: 20
# 获取连接超时时间(默认 30000 毫秒,30 秒)
connection-timeout: 30000
# 空闲连接最大存活时间(默认 600000 毫秒,10 分钟)
idle-timeout: 600000
# 保持连接活动的频率,以防止它被数据库或网络基础设施超时。该值必须小于 maxLifetime(默认 0,禁用)
keepaliveTime: 30000
# 连接最大生存时间(默认 1800000 毫秒,30 分钟)
max-lifetime: 1800000
url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
# # PostgreSQL 配置
# url: jdbc:postgresql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin_job}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
# password: ${DB_PWD:123456}
# driver-class-name: org.postgresql.Driver
## Liquibase 配置
spring.liquibase:
# 是否启用
Expand Down Expand Up @@ -67,3 +49,10 @@ snail-job:
max-count: 288
# 配置回调触发的间隔时间
trigger-interval: 900

--- ### 日志配置
logging:
level:
com.aizuda.snailjob: INFO
file:
path: ../logs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ spring:
# 启用的环境
active: dev

--- ### MyBatis Plus 配置
mybatis-plus:
# 类型别名扫描包配置
typeAliasesPackage: com.aizuda.snailjob.template.datasource.persistence.po
## MyBatis 配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: true
## 全局配置
global-config:
db-config:
where-strategy: NOT_EMPTY
capital-mode: false
# 逻辑删除全局值(默认 1,表示已删除)
logic-delete-value: 1
# 逻辑未删除全局值(默认 0,表示未删除)
logic-not-delete-value: 0

--- ### 日志配置
logging:
config: classpath:logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spring.datasource:
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
# PostgreSQL 配置
# # PostgreSQL 配置
# url: jdbc:p6spy:postgresql://${DB_HOST:127.0.0.1}:${DB_PORT:5432}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
# password: ${DB_PWD:123456}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spring.datasource:
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
# PostgreSQL 配置
# # PostgreSQL 配置
# postgresql:
# url: jdbc:postgresql://${DB_HOST:127.0.0.1}:${DB_PORT:5432}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
- redis
- mysql
schedule-server:
build: schedule-server
build: ./schedule-server
restart: always
container_name: continew-admin-schedule-server
ports:
Expand All @@ -91,6 +91,8 @@ services:
DB_USER: 你的数据库用户名
DB_PWD: 你的数据库密码
DB_NAME: continew_admin_job
volumes:
- /docker/schedule-server/logs/:/app/logs/
depends_on:
- mysql
nginx:
Expand Down

0 comments on commit c5cd4e2

Please sign in to comment.