Skip to content

Commit

Permalink
feat: add github api config and update cron job start time (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicheng-ning authored Feb 14, 2023
1 parent 28cea1b commit a963992
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
*.txt

### STS ###
.apt_generated
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/cn/nzcer/odapi/config/GitHubApiConfig.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 10 additions & 6 deletions src/main/java/cn/nzcer/odapi/cron/SyncDataBase.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -116,10 +117,10 @@ public Set<String> 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<String> allRepo = getAllRepo();
Expand Down Expand Up @@ -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<Map<String, String>> repoInfo = repoMetricService.getRepoInfo();
List<RepoStatistic> list = new ArrayList<>();
log.info(String.valueOf(repoInfo.size()));
int cnt = 1;
String token = "your-github-token";
String token = GitHubApiConfig.token;
for (Map<String, String> map : repoInfo) {
String orgName = map.get("orgName");
String repoName = map.get("repoName");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a963992

Please sign in to comment.