Only send ntfy-msg when ntfy-data is specified
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 7s
Java CI with Maven / build-and-push-backend (push) Successful in 7s

This commit is contained in:
Sebastian Böckelmann 2024-03-17 09:33:49 +01:00
parent f5607f8023
commit b4a82c745d

View File

@ -55,19 +55,22 @@ public class TaskSchedulingService {
public void sendRunningTaskNotification(AbstractSchedule abstractSchedule) { public void sendRunningTaskNotification(AbstractSchedule abstractSchedule) {
HttpClient httpClient = HttpClient.newHttpClient(); HttpClient httpClient = HttpClient.newHttpClient();
User user = abstractSchedule.getTask().getTaskgroup().getUser(); User user = abstractSchedule.getTask().getTaskgroup().getUser();
try { if(user.getNtfy_host() != null && user.getNtfy_topic() != null) {
HttpRequest request = HttpRequest.newBuilder() try {
.uri(new URI(user.getNtfy_host()+ "/" + user.getNtfy_topic())) HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString("Running Task " + abstractSchedule.getTask().getTaskName())) .uri(new URI(user.getNtfy_host()+ "/" + user.getNtfy_topic()))
.header("Tags", "heavy_check_mark") .POST(HttpRequest.BodyPublishers.ofString("Running Task " + abstractSchedule.getTask().getTaskName()))
.header("Title", "Task Running") .header("Tags", "heavy_check_mark")
.header("Actions", "view, Open TimeScheduler, "+frontend_domain+", clear=true") .header("Title", "Task Running")
.build(); .header("Actions", "view, Open TimeScheduler, "+frontend_domain+", clear=true")
.build();
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
}
} }
} }
private static Date calculateDelayInMillis(LocalDateTime executionTime) { private static Date calculateDelayInMillis(LocalDateTime executionTime) {