Send ntf-msg when schedule is started
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 17s
Java CI with Maven / build-and-push-backend (push) Successful in 15s

This commit is contained in:
Sebastian Böckelmann 2024-03-14 14:56:02 +01:00
parent 526c57a362
commit 19075b2b1d
2 changed files with 27 additions and 1 deletions

View File

@ -175,6 +175,7 @@ public class ScheduleController {
if(scheduleResult.getExitCode() == ServiceExitCode.ENTITY_ALREADY_EXIST) {
return ResponseEntity.status(409).body(new SimpleStatusResponse("failed"));
} else {
taskSchedulingService.sendRunningTaskNotification(scheduleResult.getResult());
return ResponseEntity.ok(scheduleResult.getResult().toScheduleInfo());
}
}
@ -204,11 +205,12 @@ public class ScheduleController {
if(serviceResult.getResult() instanceof AdvancedTaskSchedule) {
try {
taskSchedulingService.stopStartReminderNotification((AdvancedTaskSchedule) serviceResult.getResult());
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
taskSchedulingService.sendRunningTaskNotification(serviceResult.getResult());
return ResponseEntity.ok(new ScheduleActivateResponse(serviceResult.getResult().getStartTime()));
}

View File

@ -1,6 +1,7 @@
package core.services.ntfy;
import core.entities.User;
import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.AdvancedTaskSchedule;
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.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.LocalDateTime;
import java.time.ZoneId;
@ -46,6 +52,24 @@ public class TaskSchedulingService {
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) {
return Date.from(executionTime.atZone(ZoneId.systemDefault()).toInstant());
}