Skip to content

Commit 864aa58

Browse files
authored
Merge pull request #29 from theSimpleCloud/feat/start-multiple-server
feat: stop servers started after specific Timestamp
2 parents e5b5ab8 + 71e759b commit 864aa58

File tree

1 file changed

+20
-3
lines changed
  • controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/server

1 file changed

+20
-3
lines changed

controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/server/ServerService.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ class ServerService(
331331
override suspend fun stopServer(request: StopServerRequest): ServerDefinition {
332332
val server = serverRepository.find(request.serverId)
333333
?: throw StatusException(Status.NOT_FOUND.withDescription("No server was found matching this id."))
334+
335+
request.since?.let { sinceTimestamp ->
336+
val sinceLocalDateTime = ProtobufTimestamp.toLocalDateTime(sinceTimestamp)
337+
if (server.createdAt.isBefore(sinceLocalDateTime)) {
338+
return server.toDefinition()
339+
}
340+
}
341+
334342
try {
335343
val stopped = stopServer(server.toDefinition(), request.stopCause)
336344
return stopped
@@ -340,21 +348,30 @@ class ServerService(
340348
}
341349

342350
override suspend fun stopServersByGroupWithTimeout(request: StopServersByGroupWithTimeoutRequest): StopServersByGroupResponse {
343-
return stopServersByGroup(request.groupName, request.timeoutSeconds, request.stopCause)
351+
val sinceLocalDateTime = request.since?.let {
352+
ProtobufTimestamp.toLocalDateTime(it)
353+
}
354+
return stopServersByGroup(request.groupName, request.timeoutSeconds, request.stopCause, sinceLocalDateTime)
344355
}
345356

346357
override suspend fun stopServersByGroup(request: StopServersByGroupRequest): StopServersByGroupResponse {
347-
return stopServersByGroup(request.groupName, null, request.stopCause)
358+
val sinceLocalDateTime = request.since?.let {
359+
ProtobufTimestamp.toLocalDateTime(it)
360+
}
361+
return stopServersByGroup(request.groupName, null, request.stopCause, sinceLocalDateTime)
348362
}
349363

350364
private suspend fun stopServersByGroup(
351365
groupName: String,
352366
timeout: Int?,
353-
cause: ServerStopCause = ServerStopCause.NATURAL_STOP
367+
cause: ServerStopCause = ServerStopCause.NATURAL_STOP,
368+
since: LocalDateTime? = null
354369
): StopServersByGroupResponse {
355370
val group = groupRepository.find(groupName)
356371
?: throw StatusException(Status.NOT_FOUND.withDescription("No group was found matching this name. $groupName"))
357372
val groupServers = serverRepository.findServersByGroup(group.name)
373+
.filter { since == null || it.createdAt.isAfter(since) }
374+
358375
if (groupServers.isEmpty()) {
359376
throw StatusException(Status.NOT_FOUND.withDescription("No server was found matching this group name. ${group.name}"))
360377
}

0 commit comments

Comments
 (0)