Skip to content

Commit

Permalink
Merge pull request #120 from scc-digitalhub/websocket
Browse files Browse the repository at this point in the history
Websocket for run states
  • Loading branch information
matteo-s authored Sep 24, 2024
2 parents fa949c2 + fdcb968 commit 113a532
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 140 deletions.
11 changes: 10 additions & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
Expand All @@ -67,6 +71,11 @@
<artifactId>spring-security-oauth2-jose</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down Expand Up @@ -94,7 +103,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- <scope>test</scope> -->
</dependency>
<dependency>
<groupId>com.github.fge</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package it.smartcommunitylabdhub.core.components.cloud;

import it.smartcommunitylabdhub.commons.models.entities.run.Run;
import it.smartcommunitylabdhub.core.websocket.UserNotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RunCloudListener {

private UserNotificationService notificationService;

@Autowired(required = false)
public void setNotificationService(UserNotificationService notificationService) {
this.notificationService = notificationService;
}

@Async
@EventListener
public void broadcast(CloudEntityEvent<Run> event) {
Run run = event.getDto();

if (run != null) {
log.debug("receive event for {}: {}", run.getId(), event.getAction());

if (notificationService != null) {
//forward all events to users via notification
//TODO support filtering/config
notificationService.notifyOwner(run);
}
}
}
}
Loading

0 comments on commit 113a532

Please sign in to comment.