From a963992b08bc0202913caa69cd81d4353dc78a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=9D=E4=B8=8D=E7=AD=89=E7=90=B4=E7=94=9F?= <39022409+zhicheng-ning@users.noreply.github.com> Date: Tue, 14 Feb 2023 20:24:20 +0800 Subject: [PATCH] feat: add github api config and update cron job start time (#13) --- .gitignore | 1 + .../nzcer/odapi/config/GitHubApiConfig.java | 27 +++++++++++++++++++ .../cn/nzcer/odapi/cron/SyncDataBase.java | 16 ++++++----- src/main/resources/application-dev.yml | 2 ++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/main/java/cn/nzcer/odapi/config/GitHubApiConfig.java diff --git a/.gitignore b/.gitignore index 713a17e..be197d9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ +*.txt ### STS ### .apt_generated diff --git a/src/main/java/cn/nzcer/odapi/config/GitHubApiConfig.java b/src/main/java/cn/nzcer/odapi/config/GitHubApiConfig.java new file mode 100644 index 0000000..da5f145 --- /dev/null +++ b/src/main/java/cn/nzcer/odapi/config/GitHubApiConfig.java @@ -0,0 +1,27 @@ +package cn.nzcer.odapi.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @project: od-api + * @ClassName: GitHubAPIConfig + * @author: nzcer + * @creat: 2023/2/14 19:51 + * @description: GitHub API 配置类 + */ +@Component +@ConfigurationProperties(prefix = "github") +public class GitHubApiConfig { + @Value("${github.token}") + public static String token; + + public String getToken() { + return token; + } + + public void setToken(String token) { + GitHubApiConfig.token = token; + } +} diff --git a/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java b/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java index 66fcdb2..bfa575a 100644 --- a/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java +++ b/src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java @@ -1,5 +1,6 @@ package cn.nzcer.odapi.cron; +import cn.nzcer.odapi.config.GitHubApiConfig; import cn.nzcer.odapi.entity.RepoMetric; import cn.nzcer.odapi.entity.RepoStatistic; import cn.nzcer.odapi.service.RepoMetricService; @@ -116,10 +117,10 @@ public Set parseRepo(String url, int count) throws IOException { return repoNames; } - // 每月 4 日凌晨 1 点启动定时任务 - @Scheduled(cron = "0 0 1 4 * ?") + // 每月 3 日凌晨 1 点启动定时任务 + @Scheduled(cron = "0 0 1 3 * ?") public void insertAllRepoMetrics() throws IOException { - log.info("定时任务启动:" + new Date()); + log.info("Repo Metrics 定时任务启动:" + new Date()); log.info("清空 repo_metric 表"); repoMetricService.truncateRepoMetric(); Set allRepo = getAllRepo(); @@ -162,14 +163,17 @@ public void insertAllRepoMetrics() throws IOException { log.info("定时任务完成:" + new Date()); } - // 每月 5 日凌晨 1 点启动定时任务 - @Scheduled(cron = "0 0 1 5 * ?") + // 每日凌晨 5 点启动定时任务 + @Scheduled(cron = "0 0 5 * * ?") public void insertAllRepoStarAndFork() throws IOException { + log.info("Repo Statistic 定时任务启动:" + new Date()); + log.info("清空 repo_statistic 表"); + repoStatisticService.truncateRepoStatistic(); List> repoInfo = repoMetricService.getRepoInfo(); List list = new ArrayList<>(); log.info(String.valueOf(repoInfo.size())); int cnt = 1; - String token = "your-github-token"; + String token = GitHubApiConfig.token; for (Map map : repoInfo) { String orgName = map.get("orgName"); String repoName = map.get("repoName"); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 7f52f70..5d5600d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -29,4 +29,6 @@ mybatis: configuration: map-underscore-to-camel-case: true cache-enabled: false +github: + token: your-personal-github-token # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl