issue-86 #102

Merged
sebastian merged 10 commits from issue-86 into master 2024-03-14 14:57:52 +01:00
4 changed files with 31 additions and 6 deletions
Showing only changes of commit 14aabc483f - Show all commits

View File

@ -11,6 +11,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@ -23,9 +24,9 @@ public class DemoApplication{
@Bean
public CommandLineRunner init() {
public CommandLineRunner init(TaskSchedulingService taskSchedulingService) {
return args -> {
TaskSchedulingService.scheduleStartingTask("Finishing ConceptCreator");
taskSchedulingService.scheduleStartingTask("Finishing ConceptCreator");
};
}
}

View File

@ -3,6 +3,8 @@ package core.services.ntfy;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.net.URI;
import java.net.URISyntaxException;
@ -12,18 +14,21 @@ import java.net.http.HttpResponse;
public class NtfyTaskStartNotification implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
HttpClient httpClient = HttpClient.newHttpClient();
String msg = "Task " + jobExecutionContext.getMergedJobDataMap().getString("task") + " should have been started by now!";
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://localhost:4280/Test"))
.uri(new URI(jobExecutionContext.getMergedJobDataMap().getString("ntfy_host") + "/Test"))
.POST(HttpRequest.BodyPublishers.ofString(msg))
.header("Tags", "warning")
.header("Title", "Task Starting Reminder")
.header("Actions", "view, Open TimeScheduler, https://time.fawkes100.de/, clear=true")
.header("Actions", "view, Open TimeScheduler, "+jobExecutionContext.getMergedJobDataMap().getString("frontend_domain")+", clear=true")
.build();
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());

View File

@ -3,19 +3,34 @@ package core.services.ntfy;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
@Service
public class TaskSchedulingService {
public static void scheduleStartingTask(String taskName) throws SchedulerException {
@Value("${ntfy.host}")
private String ntfy_host;
@Value("${ntfy.topic}")
private String ntfy_topic;
@Value("${frontend.domain}")
private String frontend_domain;
public void scheduleStartingTask(String taskName) throws SchedulerException {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
JobDetail job = JobBuilder.newJob(NtfyTaskStartNotification.class).build();
job.getJobDataMap().put("task", taskName);
job.getJobDataMap().put("ntfy_host", ntfy_host);
job.getJobDataMap().put("ntfy_topic", ntfy_topic);
job.getJobDataMap().put("frontend_domain", frontend_domain);
Trigger immediatly = TriggerBuilder.newTrigger().startNow().build();

View File

@ -44,3 +44,7 @@ demo.webapp.jwtSecret=demoWebappSecretKey
demo.webapp.jwtExpirationMS=86400000
spring.jackson.time-zone=UTC
server.servlet.session.cookie.samesite=None
ntfy.host=http://localhost:4280
ntfy.topic=Test
frontend.domain=http://localhost:4200