Implement a small example dynamic schedule
This commit is contained in:
		
							parent
							
								
									5366dcc0e3
								
							
						
					
					
						commit
						2b0f9ef186
					
				@ -5,12 +5,16 @@ import core.entities.UserRole;
 | 
				
			|||||||
import core.repositories.RoleRepository;
 | 
					import core.repositories.RoleRepository;
 | 
				
			||||||
import core.repositories.UserRepository;
 | 
					import core.repositories.UserRepository;
 | 
				
			||||||
import core.services.PropertyService;
 | 
					import core.services.PropertyService;
 | 
				
			||||||
 | 
					import core.services.TaskScheduleService;
 | 
				
			||||||
 | 
					import core.services.ntfy.TaskSchedulingService;
 | 
				
			||||||
import org.springframework.boot.CommandLineRunner;
 | 
					import org.springframework.boot.CommandLineRunner;
 | 
				
			||||||
import org.springframework.boot.SpringApplication;
 | 
					import org.springframework.boot.SpringApplication;
 | 
				
			||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
					import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
				
			||||||
import org.springframework.context.annotation.Bean;
 | 
					import org.springframework.context.annotation.Bean;
 | 
				
			||||||
 | 
					import org.springframework.scheduling.annotation.EnableScheduling;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SpringBootApplication
 | 
					@SpringBootApplication
 | 
				
			||||||
 | 
					@EnableScheduling
 | 
				
			||||||
public class DemoApplication{
 | 
					public class DemoApplication{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void main(String[] args) {
 | 
						public static void main(String[] args) {
 | 
				
			||||||
@ -18,19 +22,10 @@ public class DemoApplication{
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*@Bean
 | 
						@Bean
 | 
				
			||||||
	public CommandLineRunner init(RoleRepository roleRepository, UserRepository userRepository, PropertyService propertyService) {
 | 
						public CommandLineRunner init() {
 | 
				
			||||||
		return args -> {
 | 
							return args -> {
 | 
				
			||||||
			for (UserRole userRole :  UserRole.values()) {
 | 
								TaskSchedulingService.scheduleTask();
 | 
				
			||||||
				if(!roleRepository.existsByName(userRole)) {
 | 
					 | 
				
			||||||
					roleRepository.save(new RoleEntity(userRole));
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			propertyService.init();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			FirstUserObserver observer = new FirstUserObserver(userRepository);
 | 
					 | 
				
			||||||
			observer.start();
 | 
					 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}*/
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										8
									
								
								backend/src/main/java/core/services/ntfy/NtfyTask.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								backend/src/main/java/core/services/ntfy/NtfyTask.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package core.services.ntfy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class NtfyTask implements Runnable{
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void run() {
 | 
				
			||||||
 | 
					        System.out.println("A little Test");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -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 * *"));
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -27,6 +27,7 @@ spring.jpa.open-in-view=false
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Spring Data Rest Setup
 | 
					# Spring Data Rest Setup
 | 
				
			||||||
spring.data.rest.base-path=/api
 | 
					spring.data.rest.base-path=/api
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user