issue-86 #102
@ -175,6 +175,7 @@ public class ScheduleController {
|
|||||||
if(scheduleResult.getExitCode() == ServiceExitCode.ENTITY_ALREADY_EXIST) {
|
if(scheduleResult.getExitCode() == ServiceExitCode.ENTITY_ALREADY_EXIST) {
|
||||||
return ResponseEntity.status(409).body(new SimpleStatusResponse("failed"));
|
return ResponseEntity.status(409).body(new SimpleStatusResponse("failed"));
|
||||||
} else {
|
} else {
|
||||||
|
taskSchedulingService.sendRunningTaskNotification(scheduleResult.getResult());
|
||||||
return ResponseEntity.ok(scheduleResult.getResult().toScheduleInfo());
|
return ResponseEntity.ok(scheduleResult.getResult().toScheduleInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,11 +205,12 @@ public class ScheduleController {
|
|||||||
if(serviceResult.getResult() instanceof AdvancedTaskSchedule) {
|
if(serviceResult.getResult() instanceof AdvancedTaskSchedule) {
|
||||||
try {
|
try {
|
||||||
taskSchedulingService.stopStartReminderNotification((AdvancedTaskSchedule) serviceResult.getResult());
|
taskSchedulingService.stopStartReminderNotification((AdvancedTaskSchedule) serviceResult.getResult());
|
||||||
|
|
||||||
} catch (SchedulerException e) {
|
} catch (SchedulerException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
taskSchedulingService.sendRunningTaskNotification(serviceResult.getResult());
|
||||||
return ResponseEntity.ok(new ScheduleActivateResponse(serviceResult.getResult().getStartTime()));
|
return ResponseEntity.ok(new ScheduleActivateResponse(serviceResult.getResult().getStartTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package core.services.ntfy;
|
package core.services.ntfy;
|
||||||
|
|
||||||
|
|
||||||
|
import core.entities.User;
|
||||||
import core.entities.timemanager.AbstractSchedule;
|
import core.entities.timemanager.AbstractSchedule;
|
||||||
import core.entities.timemanager.AdvancedTaskSchedule;
|
import core.entities.timemanager.AdvancedTaskSchedule;
|
||||||
import core.repositories.timemanager.ScheduleRepository;
|
import core.repositories.timemanager.ScheduleRepository;
|
||||||
@ -13,6 +14,11 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@ -46,6 +52,24 @@ public class TaskSchedulingService {
|
|||||||
scheduler.scheduleJob(job, trigger);
|
scheduler.scheduleJob(job, trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendRunningTaskNotification(AbstractSchedule abstractSchedule) {
|
||||||
|
HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
|
User user = abstractSchedule.getTask().getTaskgroup().getUser();
|
||||||
|
try {
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(new URI(user.getNtfy_host()+ "/" + user.getNtfy_topic()))
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString("Running Task " + abstractSchedule.getTask().getTaskName()))
|
||||||
|
.header("Tags", "heavy_check_mark")
|
||||||
|
.header("Title", "Task Running")
|
||||||
|
.header("Actions", "view, Open TimeScheduler, "+frontend_domain+", clear=true")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Date calculateDelayInMillis(LocalDateTime executionTime) {
|
private static Date calculateDelayInMillis(LocalDateTime executionTime) {
|
||||||
return Date.from(executionTime.atZone(ZoneId.systemDefault()).toInstant());
|
return Date.from(executionTime.atZone(ZoneId.systemDefault()).toInstant());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user