Skip to content

Commit

Permalink
#58 - Extracting delay to application.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
iakunin committed May 4, 2020
1 parent 9b0c637 commit 3946e03
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
import dev.iakunin.codexiabot.github.repository.GithubRepoStatRepository;
import dev.iakunin.codexiabot.github.sdk.CodetabsClient;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@AllArgsConstructor(onConstructor_={@Autowired})
public final class LinesOfCode implements Runnable {

private final GithubRepoRepository githubRepoRepository;
Expand All @@ -23,6 +21,20 @@ public final class LinesOfCode implements Runnable {

private final CodetabsClient codetabsClient;

private final Integer delay;

public LinesOfCode(
GithubRepoRepository githubRepoRepository,
GithubRepoStatRepository githubRepoStatRepository,
CodetabsClient codetabsClient,
@Value("${app.cron.github.stat.lines-of-code.delay}") Integer delay
) {
this.githubRepoRepository = githubRepoRepository;
this.githubRepoStatRepository = githubRepoStatRepository;
this.codetabsClient = codetabsClient;
this.delay = delay;
}

public void run() {
this.githubRepoRepository.findAllWithoutLinesOfCode().forEach(
githubRepo -> {
Expand Down Expand Up @@ -50,8 +62,7 @@ public void run() {
}
} finally {
log.debug("Sleeping...");
// @todo #58 configure this timeout for tests
sleep(5000);
sleep(this.delay);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
"name": "app.codetabs.base-url",
"type": "java.lang.String",
"description": "Base url of Codetabs."
},
{
"name": "app.cron.github.stat.lines-of-code.delay",
"type": "java.lang.Integer",
"description": "Delay for github.stat.lines-of-code cron."
}
]
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ app.reddit.client-id=<insert-your-reddit-client-id-here>
app.reddit.client-secret=<insert-your-reddit-client-secret-here>

app.codetabs.base-url=https://api.codetabs.com/v1/

app.cron.github.stat.lines-of-code.delay=5000
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ static class Initializer implements ApplicationContextInitializer<ConfigurableAp
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"app.codetabs.base-url=" + WireMockServer.getInstance().baseUrl()
"app.codetabs.base-url=" + WireMockServer.getInstance().baseUrl(),
"app.cron.github.stat.lines-of-code.delay=0"
).applyTo(applicationContext.getEnvironment());
}
}
Expand Down

0 comments on commit 3946e03

Please sign in to comment.