parent
54cacc7e2e
commit
f27b313044
4 changed files with 24 additions and 26 deletions
|
|
@ -11,7 +11,6 @@ import ru.spcex.clearing.platform.messaging.domain.cud.schedule.ClearingCalendar
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.ClearingCalendarUpdateRequest;
|
||||
import ru.spcex.clearing.scheduler.error.ValidationError;
|
||||
import ru.spcex.clearing.scheduler.validation.rules.common.DateAfterTodayRule;
|
||||
import ru.spcex.clearing.scheduler.validation.rules.common.DateNotBeforeRule;
|
||||
import ru.spcex.clearing.scheduler.validation.rules.common.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.scheduler.validation.rules.common.IdPresentRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
|
|
@ -69,7 +68,7 @@ public class ClearingCalendarValidationConfig {
|
|||
IMDGDistributedNames.Map_ClearingCalendar,
|
||||
ClearingCalendar.class,
|
||||
ValidationError.RecordNotFound),
|
||||
DateNotBeforeRule.instance("clearingDate",//todo при редактировании DateAfterTodayRule или DateNotBeforeRule?
|
||||
DateAfterTodayRule.instance("clearingDate",
|
||||
ClearingCalendarUpdateRequest::getClearingDate),
|
||||
IdPresentRule.instance("companyId",
|
||||
ClearingCalendarUpdateRequest::getCompanyId,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public enum ValidationError implements IErrorEnumId {
|
|||
WrongDictionaryValue(18003L),
|
||||
WrongEnumValue(777L), //todo set code
|
||||
RecordNotFound(7006L),
|
||||
TaskForPastDate(7010L),
|
||||
TaskForPastDate(7016L),
|
||||
TaskForPastTime(7011L),
|
||||
CompanyNotFound(7014L),
|
||||
SecurityNotFound(7012L),
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import ru.spcex.platform.utils.validation.IValidator;
|
|||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static ru.spcex.clearing.scheduler.config.PlannerQueueConfig.addToPlannerQueue;
|
||||
|
|
@ -150,7 +149,11 @@ public class PlannerService extends QueueConsumer implements InitializingBean {
|
|||
Planner planner = plannerMap.getSingleObjectByID(req.getId());
|
||||
plannerMap.delete(planner);
|
||||
Collection<PlannerAllToday> values = plannerAllTodayMap.getCollectionObjectsBySQL(String.format("parentId = %s", planner.getId()));
|
||||
values.forEach(plannerAllTodayMap::delete);
|
||||
values.forEach(p -> {
|
||||
plannerAllTodayMap.delete(p);
|
||||
addToPlannerQueue(TaskManager.Process.delete, p);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +173,7 @@ public class PlannerService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
|
||||
if (planner.getTaskStatus().equalsIgnoreCase(Status.Cancel.getKey()) || planner.getTaskStatus().equalsIgnoreCase(Status.Blocked.getKey())) {
|
||||
Collection<PlannerAllToday> values = plannerAllTodayMap.getCollectionObjectsByFieldValues(Map.of(
|
||||
"task", planner.getTask(),
|
||||
"taskTime", planner.getTaskTime(),
|
||||
"securityId", planner.getSecurityId(),
|
||||
"companyId", planner.getCompanyId()));
|
||||
Collection<PlannerAllToday> values = plannerAllTodayMap.getCollectionObjectsBySQL(String.format("parentId = %s", planner.getId()));
|
||||
values.forEach(plannerAllToday -> {
|
||||
plannerAllTodayMap.delete(plannerAllToday);
|
||||
addToPlannerQueue(TaskManager.Process.delete, plannerAllToday);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class TaskManager implements InitializingBean, AutoCloseable {
|
|||
//если таск относится к другому обработчику, пропускаем
|
||||
|
||||
if (!Objects.equals(task.getTask(), oldTask.getTask())) {
|
||||
throw new IllegalStateException("changed taskId for PlannerAllToday in core");
|
||||
log.debug("Trying to cancel task type {} and add task type {}", oldTask.getTask(), task.getTask());
|
||||
}
|
||||
String taskStatus = task.getTaskStatus();
|
||||
if (taskStatus == null) {
|
||||
|
|
@ -124,24 +124,24 @@ public class TaskManager implements InitializingBean, AutoCloseable {
|
|||
addOrUpdateActiveTask(task);
|
||||
} else if (Cancel.equalsByKey(taskStatus)) { //&& TaskStatuses.CANCEL.equalsById(task.getTaskStatusId())
|
||||
if (removeTask(task.getTask(), task.getId()))
|
||||
log.debug("task was successfully deleted after update to cancel");
|
||||
else log.debug("no task for deleted after update to cancel");
|
||||
log.debug("Task {} was successfully deleted after update to cancel", task.getTask());
|
||||
else log.debug("No task {} for deleted after update to cancel", task.getTask());
|
||||
} else if (Blocked.equalsByKey(taskStatus)) {
|
||||
if (removeTask(task.getTask(), task.getId()))
|
||||
log.debug("task was successfully deleted after update to blocked");
|
||||
else log.debug("no task for deleted after update to blocked");
|
||||
log.debug("Task {} was successfully deleted after update to blocked", task.getTask());
|
||||
else log.debug("No task {} for deleted after update to blocked", task.getTask());
|
||||
}
|
||||
}
|
||||
|
||||
public void entryRemoved(PlannerAllToday taskToRemove) {
|
||||
if (taskToRemove == null) {
|
||||
log.debug("no task in removed event");
|
||||
log.debug("No task in removed event");
|
||||
return;
|
||||
}
|
||||
|
||||
if (removeTask(taskToRemove.getTask(), taskToRemove.getId()))
|
||||
log.debug("task successfully removed");
|
||||
else log.debug("no task for removing");
|
||||
log.debug("Task {} successfully removed", taskToRemove.getTask());
|
||||
else log.debug("No task for removing");
|
||||
}
|
||||
|
||||
private void restorePreviouslyRemovedTask(Long oldTaskId, PlannerAllToday oldTask) {
|
||||
|
|
@ -181,33 +181,33 @@ public class TaskManager implements InitializingBean, AutoCloseable {
|
|||
return;
|
||||
}
|
||||
if (taskStatus.equals(Blocked)) {
|
||||
log.debug("Task skipped - timeTime {} with status {}", taskTime, Blocked);
|
||||
log.debug("Task skipped - taskType {} timeTime {} with status {}", task.getTask(), taskTime, Blocked);
|
||||
return;
|
||||
}
|
||||
if (Cancel.equals(taskStatus)) {
|
||||
log.debug("task type {} time {} with status CANCEL - no tasks to cancel found", Objects.requireNonNull(taskType).name(), taskTime);
|
||||
log.debug("Task skipped - taskType {} time {} with status CANCEL", Objects.requireNonNull(taskType).getKey(), taskTime);
|
||||
return;
|
||||
}
|
||||
//чтобы не получилось, что старый таск не успели отменить а новый уже создали.
|
||||
if (taskTime.isBefore(LocalTime.now().plusSeconds(1))) {
|
||||
log.debug("Task skipped - taskTime {} is before now, taskType {} ok", taskTime, task.getTask());
|
||||
log.debug("Task skipped - taskTime {} is before now, taskType {}", taskTime, task.getTask());
|
||||
return;
|
||||
}
|
||||
//пришел активный таск
|
||||
log.debug("adding task type {}, time {}", Objects.requireNonNull(taskType).name(), taskTime);
|
||||
log.debug("Adding task type {}, time {}", Objects.requireNonNull(taskType).getKey(), taskTime);
|
||||
ScheduledFuture future = taskScheduler.schedule(() -> doJob(task), LocalDateTime.of(LocalDate.now(), taskTime).atZone(ZoneId.systemDefault()).toInstant());
|
||||
ScheduledFuture oldFuture = scheduledJobs.put(task.getId(), future);
|
||||
if (oldFuture != null && !oldFuture.isCancelled()) { //for synchronization, never
|
||||
log.warn("tasks were added simultaneously, cancel former one");
|
||||
log.warn("Tasks were added simultaneously, cancel former one");
|
||||
boolean success = oldFuture.cancel(false);
|
||||
log.warn("cancelling task " + (success ? "success" : "fail"));
|
||||
log.warn("Cancelling task " + (success ? "success" : "fail"));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean removeTask(String task, Long taskId) {
|
||||
ScheduledFuture future = scheduledJobs.remove(taskId);
|
||||
if (future == null) {
|
||||
log.debug("can't cancel task type {}, time {}, not found", task, taskId);
|
||||
log.debug("Can't cancel task type {}, time {}, not found", task, taskId);
|
||||
return false;
|
||||
}
|
||||
return future.cancel(false);
|
||||
|
|
@ -229,7 +229,7 @@ public class TaskManager implements InitializingBean, AutoCloseable {
|
|||
launcherMap.insert(launcher);
|
||||
// 2. отправить сообщение
|
||||
launcherSender.sendCommandToQueue(taskE, systemId);
|
||||
log.debug("successfully processed, new id {}", launcher.getId());
|
||||
log.debug("Successfully processed, new id {}", launcher.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue