Skip to content

Commit 47c2a79

Browse files
author
Adrian Immel
committed
Fixed Task Scheduling
1 parent 08eb677 commit 47c2a79

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/main/java/app/betterhm/backend/BackendApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
56

67
@SpringBootApplication
8+
@EnableScheduling
79
public class BackendApplication {
810

911
public static void main(String[] args) {

src/main/java/app/betterhm/backend/v1/component/StaticUpdater.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ public StaticUpdater(YamlParser yamlParser) {
2929
* Downloads the calendar files from the source URLs and saves them in the static folder
3030
*/
3131
@PostConstruct
32-
@Scheduled(cron = "0 4 * * *")
32+
@Scheduled(cron = "0 0 4 * * *")
3333
public void updateCalendar(){
3434
yaml.Calendars().stream().filter(element -> element.SourceURL().isPresent()).forEach(element ->
3535
downloadFile(element.SourceURL().get(), "src/main/resources/static/calendar/" + element.ID() + ".ics"));
36+
logger.info("Calendar files updated");
3637
}
3738

3839
/**
@@ -42,9 +43,11 @@ public void updateCalendar(){
4243
*/
4344
private void downloadFile(String url, String path) {
4445
URL website;
46+
4547
try {
4648
website = new URL(url);
4749
} catch (MalformedURLException e) {
50+
logger.error("Invalid URL", e);
4851
throw new RuntimeException("Invalid URL", e);
4952
}
5053
try (InputStream in = website.openStream()) {

src/main/java/app/betterhm/backend/v1/services/CapacityService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ public CapacityApiElement getSingleCapacityElement(String enum_nameToFind){
5656
/**
5757
* Method to update the Capacity Elements every 5 Minutes
5858
*/
59-
@Scheduled(cron = "0/5 * * * * *")
59+
@Scheduled(cron = "0 */5 * * * *")
6060
public void updateCapacity(){
6161
List<CapacityApiElement> newElementList = new ArrayList<>();
6262
capacityConfigRecordList.forEach(Element -> newElementList.add(getUpdatedCapacityElement(Element)));
6363
capacityApiElementList = newElementList;
64+
logger.info("Capacity Elements Updated");
6465
}
6566

6667
private CapacityApiElement getUpdatedCapacityElement(CapacityConfigRecord capacityConfigRecord){

0 commit comments

Comments
 (0)