Skip to content

Commit

Permalink
优化自动检查更新时间控制
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed May 8, 2024
1 parent d881574 commit d9a14af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitea/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: "Release"
uses: https://ssl.lunadeer.cn:14446/zhangyuheng/release-action@main
with:
note: "带 `original-` 前缀的文件无法用于运行,请下载不带此前缀的版本。"
note: " - 带 `original-` 前缀的文件无法用于运行,请下载不带此前缀的版本。"
files: |-
staging/*.jar
api_key: '${{secrets.RELEASE_TOKEN}}'
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.22.1-beta</version>
<version>1.22.2-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/cn/lunadeer/dominion/utils/GiteaReleaseCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class GiteaReleaseCheck {
Expand All @@ -30,11 +31,12 @@ public GiteaReleaseCheck(JavaPlugin plugin, String giteaServer, String owner, St
this.current_version = plugin.getPluginMeta().getVersion();
// 异步每12小时检查一次更新
plugin.getServer().getAsyncScheduler().runAtFixedRate(plugin, (instance) -> {
getLatestRelease();
if (auto_update) {
downloadUpdate();
}
}, 10, 60 * 60 * 12, TimeUnit.SECONDS);
getLatestRelease();
if (auto_update) {
downloadUpdate();
}
}, 10 + new Random().nextInt(10), 60 * 60 * 12 + new Random().nextInt(60),
TimeUnit.SECONDS);
}

public void enableAutoUpdate() {
Expand Down

0 comments on commit d9a14af

Please sign in to comment.