Skip to content

Commit

Permalink
Make the xirsys channel create idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 26, 2023
1 parent b757d38 commit be78526
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ class XirsysApiAdapter(
}

@Retry
fun createChannel(channelName: String): Map<String, String> =
parseAndUnwrap {
xirsysApiClient.createChannel(
namespace = xirsysProperties.channelNamespace(),
environment = fafProperties.environment(),
channelName = channelName,
)
fun createChannel(channelName: String) {
try {
parseAndUnwrap<Map<String, String>> {
xirsysApiClient.createChannel(
namespace = xirsysProperties.channelNamespace(),
environment = fafProperties.environment(),
channelName = channelName,
)
}
} catch (e: XirsysSpecifiedApiException) {
if (!e.errorCode.equals(PATH_EXISTS, true)) throw e
LOG.debug("Channel $channelName already exists")
}
}

@Retry
fun deleteChannel(channelName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo

const val NOT_FOUND = "not_found"
const val PATH_EXISTS = "path_exists"

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "s")
@JsonSubTypes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@ class XirsysSessionHandler(
override val active = xirsysProperties.enabled()

override fun createSession(id: String) {
if (listSessions().contains(id)) {
LOG.debug("Session id $id already exists")
return
}

LOG.debug("Creating session id $id")

xirsysApiAdapter.createChannel(id)
}

override fun deleteSession(id: String) {
xirsysApiAdapter.deleteChannel(channelName = id)
}

private fun listSessions(): List<String> = xirsysApiAdapter.listChannel()

override fun getIceServers() = listOf(Server(id = SERVER_NAME, region = "Global"))

override fun getIceServersSession(sessionId: String): List<Session.Server> =
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ xirsys:
log:
category:
"org.hibernate.SQL":
level: DEBUG
"com.faforever":
level: DEBUG

0 comments on commit be78526

Please sign in to comment.