feat(markers): auto-delete after 8 hours
This commit is contained in:
@@ -16,3 +16,5 @@ POSTGRES_DB=vodSystem
|
|||||||
|
|
||||||
FRONTEND_URL=
|
FRONTEND_URL=
|
||||||
BACKEND_URL=
|
BACKEND_URL=
|
||||||
|
|
||||||
|
STREAM_RING_LENGTH_SECOND=28800
|
||||||
@@ -22,6 +22,8 @@ services:
|
|||||||
container_name: vod_rtmp
|
container_name: vod_rtmp
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
environment:
|
environment:
|
||||||
- WEB_SERVER_URL=http://host.docker.internal:8080
|
- WEB_SERVER_URL=http://host.docker.internal:8080
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ services:
|
|||||||
context: ./nginx
|
context: ./nginx
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: vod_rtmp
|
container_name: vod_rtmp
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
environment:
|
environment:
|
||||||
- WEB_SERVER_URL=http://backend:8080
|
- WEB_SERVER_URL=http://backend:8080
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ rtmp {
|
|||||||
hls_path /stream;
|
hls_path /stream;
|
||||||
hls_fragment_naming system;
|
hls_fragment_naming system;
|
||||||
hls_fragment 3;
|
hls_fragment 3;
|
||||||
hls_playlist_length 28800;
|
hls_playlist_length ${STREAM_RING_LENGTH_SECOND};
|
||||||
|
|
||||||
on_publish ${WEB_SERVER_URL}/api/v1/stream/start;
|
on_publish ${WEB_SERVER_URL}/api/v1/stream/start;
|
||||||
on_publish_done ${WEB_SERVER_URL}/api/v1/stream/stop;
|
on_publish_done ${WEB_SERVER_URL}/api/v1/stream/stop;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# must only run on certain env files, otherwise it replaces too much
|
# must only run on certain env files, otherwise it replaces too much
|
||||||
envsubst '${WEB_SERVER_URL}' \
|
envsubst '${WEB_SERVER_URL} ${STREAM_RING_LENGTH_SECOND}' \
|
||||||
< /etc/nginx/templates/default.conf.template \
|
< /etc/nginx/templates/default.conf.template \
|
||||||
> /etc/nginx/nginx.conf
|
> /etc/nginx/nginx.conf
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface MarkerRepository extends JpaRepository<Marker, Long> {
|
public interface MarkerRepository extends JpaRepository<Marker, Long> {
|
||||||
@Query("SELECT m FROM Marker m WHERE m.user = ?1")
|
@Query("SELECT m FROM Marker m WHERE m.user = ?1")
|
||||||
List<Marker> findByUser(User user);
|
List<Marker> findByUser(User user);
|
||||||
|
|
||||||
|
@Query("SELECT m FROM Marker m WHERE m.timestamp <= ?1")
|
||||||
|
List<Marker> findAllBefore(Instant time);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import com.ddf.vodsystem.exceptions.MarkerNotFound;
|
|||||||
import com.ddf.vodsystem.exceptions.NotAuthenticated;
|
import com.ddf.vodsystem.exceptions.NotAuthenticated;
|
||||||
import com.ddf.vodsystem.exceptions.NotStreaming;
|
import com.ddf.vodsystem.exceptions.NotStreaming;
|
||||||
import com.ddf.vodsystem.repositories.MarkerRepository;
|
import com.ddf.vodsystem.repositories.MarkerRepository;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -20,6 +23,9 @@ public class MarkerService {
|
|||||||
private final StreamService streamService;
|
private final StreamService streamService;
|
||||||
private final MarkerRepository markerRepository;
|
private final MarkerRepository markerRepository;
|
||||||
|
|
||||||
|
@Value("${stream.max-length}")
|
||||||
|
private Long maxStreamLength;
|
||||||
|
|
||||||
public MarkerService(UserService userService, StreamService streamService, MarkerRepository markerRepository) {
|
public MarkerService(UserService userService, StreamService streamService, MarkerRepository markerRepository) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.streamService = streamService;
|
this.streamService = streamService;
|
||||||
@@ -65,4 +71,12 @@ public class MarkerService {
|
|||||||
marker.setTimestamp(Instant.now());
|
marker.setTimestamp(Instant.now());
|
||||||
return markerRepository.saveAndFlush(marker);
|
return markerRepository.saveAndFlush(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = 360_000)
|
||||||
|
@Transactional
|
||||||
|
public void deleteOldMarkers() {
|
||||||
|
Instant cutoff = Instant.now().minusSeconds(maxStreamLength);
|
||||||
|
List<Marker> stale = markerRepository.findAllBefore(cutoff);
|
||||||
|
markerRepository.deleteAllInBatch(stale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ spring.application.name=vodSystem
|
|||||||
# VODs
|
# VODs
|
||||||
spring.servlet.multipart.max-file-size=2GB
|
spring.servlet.multipart.max-file-size=2GB
|
||||||
spring.servlet.multipart.max-request-size=2GB
|
spring.servlet.multipart.max-request-size=2GB
|
||||||
|
stream.max-length=${STREAM_RING_LENGTH_SECOND}
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
spring.datasource.url=${POSTGRES_URL}
|
spring.datasource.url=${POSTGRES_URL}
|
||||||
|
|||||||
Reference in New Issue
Block a user