Implement a small example dynamic schedule
All checks were successful
Java CI with Maven / test (push) Successful in 34s
Java CI with Maven / build-and-push-frontend (push) Successful in 6s
Java CI with Maven / build-and-push-backend (push) Successful in 8s

This commit is contained in:
Sebastian Böckelmann 2024-03-14 08:08:04 +01:00
parent 5366dcc0e3
commit 2b0f9ef186
4 changed files with 38 additions and 13 deletions

View File

@ -5,12 +5,16 @@ import core.entities.UserRole;
import core.repositories.RoleRepository;
import core.repositories.UserRepository;
import core.services.PropertyService;
import core.services.TaskScheduleService;
import core.services.ntfy.TaskSchedulingService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class DemoApplication{
public static void main(String[] args) {
@ -18,19 +22,10 @@ public class DemoApplication{
}
/*@Bean
public CommandLineRunner init(RoleRepository roleRepository, UserRepository userRepository, PropertyService propertyService) {
@Bean
public CommandLineRunner init() {
return args -> {
for (UserRole userRole : UserRole.values()) {
if(!roleRepository.existsByName(userRole)) {
roleRepository.save(new RoleEntity(userRole));
}
}
propertyService.init();
FirstUserObserver observer = new FirstUserObserver(userRepository);
observer.start();
TaskSchedulingService.scheduleTask();
};
}*/
}
}

View File

@ -0,0 +1,8 @@
package core.services.ntfy;
public class NtfyTask implements Runnable{
@Override
public void run() {
System.out.println("A little Test");
}
}

View File

@ -0,0 +1,21 @@
package core.services.ntfy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ScheduledFuture;
public class TaskSchedulingService {
public static void scheduleTask() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.initialize();
threadPoolTaskScheduler.schedule(new NtfyTask(), new CronTrigger("0 0/1 * 1/1 * *"));
}
}

View File

@ -27,6 +27,7 @@ spring.jpa.open-in-view=false
# Spring Data Rest Setup
spring.data.rest.base-path=/api