Add Notification for stopped deployments

This commit is contained in:
DerDavidBohl
2025-01-21 07:53:50 +01:00
parent 15e79d5f96
commit ef426f5a8a
3 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package org.davidbohl.dirigent.deployments.models.events;
import org.springframework.context.ApplicationEvent;
public class NotConfiguredDeploymentStopped extends ApplicationEvent {
private final String deploymentName;
public NotConfiguredDeploymentStopped(Object source, String deploymentName) {
super(source);
this.deploymentName = deploymentName;
}
public String getDeploymentName() {
return deploymentName;
}
}

View File

@@ -136,6 +136,7 @@ public class DeploymentsService {
.start()
.waitFor();
deleteDirectory(file);
applicationEventPublisher.publishEvent(new NotConfiguredDeploymentStopped(this, file.getName()));
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}

View File

@@ -2,6 +2,7 @@ package org.davidbohl.dirigent.deployments.service;
import org.davidbohl.dirigent.deployments.models.events.DeploymentStartFailedEvent;
import org.davidbohl.dirigent.deployments.models.events.DeploymentStartSucceededEvent;
import org.davidbohl.dirigent.deployments.models.events.NotConfiguredDeploymentStopped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -35,6 +36,13 @@ public class NotificationService {
logger.info("Deployment '{}' succeeded.", event.getDeploymentName());
}
@EventListener(NotConfiguredDeploymentStopped.class)
public void onNotConfiguredDeploymentStopped(NotConfiguredDeploymentStopped event) {
sendGotifyMessage("Deployment stopped", "Deployment \"%s\" stopped because it is not configured".formatted(event.getDeploymentName()));
logger.info("Deployment '{}' stopped because it is not configured.", event.getDeploymentName());
}
private void sendGotifyMessage(String title, String message) {
if (gotifyToken != null && gotifyBaseUrl != null && !gotifyToken.isBlank() && !gotifyBaseUrl.isBlank()) {
RestTemplate restTemplate = new RestTemplate();