mirror of
https://github.com/DerDavidBohl/dirigent-spring.git
synced 2026-01-03 00:49:39 -06:00
Add Notification for stopped deployments
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user