Added performing tours and docs
This commit is contained in:
parent
2141f35e3f
commit
3485dff86f
@ -119,25 +119,52 @@ public class AppConfig {
|
||||
return AppState.NO_TOUR;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of first tour end
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getFirstTourEndCron() {
|
||||
return getCron(this.firstTourEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of second tour end
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getSecondTourEndCron() {
|
||||
return getCron(this.secondTourEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of first tour start
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getFirstTourStartCron() {
|
||||
return getCron(this.firstTourStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of second tour start
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getSecondTourStartCron() {
|
||||
return getCron(this.secondTourStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* create spring cron expression
|
||||
*
|
||||
* @param date date to create cron exp from
|
||||
* @return spring cron expression. Remember that spring's cron deosn't contain
|
||||
* year in it.
|
||||
*/
|
||||
private CronTrigger getCron(Date date) {
|
||||
final LocalDate tourEnd = date.toLocalDate();
|
||||
return new CronTrigger("0 0 0 " + tourEnd.getDayOfMonth() + " " + tourEnd.getMonthValue() + " ?",
|
||||
return new CronTrigger("0 11 11 " + tourEnd.getDayOfMonth() + " " + tourEnd.getMonthValue() + " ?",
|
||||
TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,13 @@ import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.repositories.AppConfigRepository;
|
||||
import com.plannaplan.tasks.PerformAcceptAlgorythmTask;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -29,6 +30,8 @@ public class ConfiguratorService {
|
||||
private AppConfigRepository configRepo;
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
public ConfiguratorService() {
|
||||
}
|
||||
@ -95,10 +98,39 @@ public class ConfiguratorService {
|
||||
}
|
||||
|
||||
private void shceduleTaskAfterToursDateChange(AppConfig config) {
|
||||
this.eventService.scheduleTask(EventService.FIRST_TOUR_SCHEDULE, new PerformAcceptAlgorythmTask(),
|
||||
config.getFirstTourEndCron());
|
||||
|
||||
this.eventService.scheduleTask(EventService.SECOND_TOUR_SCHEDULE, new PerformAcceptAlgorythmTask(),
|
||||
config.getSecondTourEndCron());
|
||||
this.eventService.scheduleTask(EventService.FIRST_TOUR_SCHEDULE,
|
||||
new AlgorythmAcceptTask(config.getFirstTourEnd()), config.getFirstTourEndCron());
|
||||
|
||||
this.eventService.scheduleTask(EventService.SECOND_TOUR_SCHEDULE,
|
||||
new AlgorythmAcceptTask(config.getSecondTourEnd()), config.getSecondTourEndCron());
|
||||
}
|
||||
|
||||
/**
|
||||
* It's local class to perform accept Task. It's needed to be here due to have
|
||||
* acces to AssignmentService.
|
||||
*/
|
||||
private class AlgorythmAcceptTask implements Runnable {
|
||||
|
||||
private LocalDate localDate;
|
||||
|
||||
/**
|
||||
* create instance of AlgorythmAcceptTask
|
||||
*
|
||||
* @param date date of algorythm perform. Needed to check if ti's being called
|
||||
* in correct year
|
||||
*/
|
||||
public AlgorythmAcceptTask(Date date) {
|
||||
this.localDate = date.toLocalDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (localDate.getYear() == LocalDate.now().getYear()) {
|
||||
assignmentService.callAcceptAlgorythm();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,21 +1,11 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
// import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
@ -27,28 +17,22 @@ public class EventService {
|
||||
public static final int FIRST_TOUR_SCHEDULE = 0;
|
||||
public static final int SECOND_TOUR_SCHEDULE = 1;
|
||||
|
||||
// @Autowired
|
||||
// private EmailService emailService;
|
||||
|
||||
private ThreadPoolTaskScheduler scheduler;
|
||||
private Map<Integer, ScheduledFuture<?>> jobsMap = new HashMap<>();
|
||||
|
||||
// @Autowired
|
||||
// private ConfiguratorService configService;
|
||||
|
||||
@Scheduled(cron = "0 24 17 * * *")
|
||||
public void collectGroupLosses() {
|
||||
System.out.println("Checking for groups");
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "#{eventService.getFirstTourValue()}")
|
||||
// public void performAcceptAction() {
|
||||
// System.out.println("Checking for hahaha");
|
||||
// }
|
||||
|
||||
// new CronTrigger("0 0 0 * * ?",
|
||||
// TimeZone.getTimeZone(TimeZone.getDefault().getID()))
|
||||
|
||||
/**
|
||||
* Schedule provided task to perform
|
||||
*
|
||||
* @param taskId static filed of this class that represents to what event
|
||||
* we want to assign task
|
||||
* @param task runnable class that perform task in implemented run method
|
||||
* @param cronTrigger CronTrigger instance with date to perform
|
||||
*/
|
||||
public void scheduleTask(int taskId, Runnable task, CronTrigger cronTrigger) {
|
||||
ScheduledFuture<?> scheduledTask = jobsMap.get(taskId);
|
||||
if (scheduledTask != null) {
|
||||
@ -59,21 +43,6 @@ public class EventService {
|
||||
jobsMap.put(taskId, scheduledTask);
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public String getFirstTourValue() {
|
||||
// final AppConfig config = this.configService.getCurrentConfig();
|
||||
// final LocalDate tourEnd = config.getFirstTourEnd().toLocalDate();
|
||||
// final String cronExp = "0 0 0 " + tourEnd.getDayOfMonth() + " " +
|
||||
// tourEnd.getMonthValue() + " "
|
||||
// + tourEnd.getYear();
|
||||
// return cronExp;
|
||||
// }
|
||||
|
||||
// @Bean
|
||||
// public String getSecondTourValue() {
|
||||
// return "0 6 18 * * *";
|
||||
// }
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
this.scheduler = new ThreadPoolTaskScheduler();
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.tasks;
|
||||
|
||||
public class PerformAcceptAlgorythmTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("XDDDDDDDd");
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user