issue-86 #102
@ -11,6 +11,7 @@ import org.springframework.boot.CommandLineRunner;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ -23,9 +24,9 @@ public class DemoApplication{
|
|||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CommandLineRunner init() {
|
public CommandLineRunner init(TaskSchedulingService taskSchedulingService) {
|
||||||
return args -> {
|
return args -> {
|
||||||
TaskSchedulingService.scheduleStartingTask("Finishing ConceptCreator");
|
taskSchedulingService.scheduleStartingTask("Finishing ConceptCreator");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package core.services.ntfy;
|
|||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
import org.quartz.JobExecutionException;
|
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.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -12,18 +14,21 @@ import java.net.http.HttpResponse;
|
|||||||
|
|
||||||
public class NtfyTaskStartNotification implements Job {
|
public class NtfyTaskStartNotification implements Job {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||||
HttpClient httpClient = HttpClient.newHttpClient();
|
HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
String msg = "Task " + jobExecutionContext.getMergedJobDataMap().getString("task") + " should have been started by now!";
|
String msg = "Task " + jobExecutionContext.getMergedJobDataMap().getString("task") + " should have been started by now!";
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
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))
|
.POST(HttpRequest.BodyPublishers.ofString(msg))
|
||||||
.header("Tags", "warning")
|
.header("Tags", "warning")
|
||||||
.header("Title", "Task Starting Reminder")
|
.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();
|
.build();
|
||||||
|
|
||||||
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
@ -3,19 +3,34 @@ package core.services.ntfy;
|
|||||||
|
|
||||||
import org.quartz.*;
|
import org.quartz.*;
|
||||||
import org.quartz.impl.StdSchedulerFactory;
|
import org.quartz.impl.StdSchedulerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class TaskSchedulingService {
|
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 scheduler = StdSchedulerFactory.getDefaultScheduler();
|
||||||
scheduler.start();
|
scheduler.start();
|
||||||
|
|
||||||
JobDetail job = JobBuilder.newJob(NtfyTaskStartNotification.class).build();
|
JobDetail job = JobBuilder.newJob(NtfyTaskStartNotification.class).build();
|
||||||
job.getJobDataMap().put("task", taskName);
|
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();
|
Trigger immediatly = TriggerBuilder.newTrigger().startNow().build();
|
||||||
|
|
||||||
|
@ -43,4 +43,8 @@ spring.servlet.multipart.max-request-size=4196KB
|
|||||||
demo.webapp.jwtSecret=demoWebappSecretKey
|
demo.webapp.jwtSecret=demoWebappSecretKey
|
||||||
demo.webapp.jwtExpirationMS=86400000
|
demo.webapp.jwtExpirationMS=86400000
|
||||||
spring.jackson.time-zone=UTC
|
spring.jackson.time-zone=UTC
|
||||||
server.servlet.session.cookie.samesite=None
|
server.servlet.session.cookie.samesite=None
|
||||||
|
|
||||||
|
ntfy.host=http://localhost:4280
|
||||||
|
ntfy.topic=Test
|
||||||
|
frontend.domain=http://localhost:4200
|
Loading…
Reference in New Issue
Block a user