Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions packages/core/src/usecase/CreateServerForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ export class CreateServerForUser {
const { serverManagerFactory, serverRepository, userCreditsRepository, eventLogger, sourceTvEventLogger, configManager, userRepository, guildParametersRepository, userBanRepository } = this.dependencies;
const statusUpdater = args.statusUpdater;

// Get the appropriate server manager for this region
const serverManager = serverManagerFactory.createServerManager(args.region);
const user = await userRepository.getById(args.creatorId);
if (!user || !user.steamIdText) {
throw new UserError('Before creating a server, please set your Steam ID using the `/set-user-data` command. This is required to give you admin access to the server.');
}

// Check if user is banned
const steamId = new SteamID(user.steamIdText);
const steamID3 = steamId.steam3().replace("[", "").replace("]", "");

Expand Down Expand Up @@ -96,10 +94,6 @@ export class CreateServerForUser {
}
const serverId = uuid();

// Use a transaction to ensure atomicity and consistency
// Also, if the server creation fails, we want the server ID To be in the database
// so we can delete it later

await serverRepository.runInTransaction(async (trx) => {
const allServers = await serverRepository.getAllServersByUserId(args.creatorId, trx);
const runningServers = allServers.filter(server => server.status === "ready" || server.status === "pending");
Comment thread
sonikro marked this conversation as resolved.
Expand Down Expand Up @@ -146,4 +140,4 @@ export class CreateServerForUser {
});
return server;
}
}
}
2 changes: 0 additions & 2 deletions packages/core/src/usecase/DeleteServerForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export class DeleteServerForUser {
const { serverRepository, serverActivityRepository, serverManagerFactory, eventLogger, serverAbortManager } = this.dependencies;
const { userId } = args;

// Use transaction to ensure consistency
await serverRepository.runInTransaction(async (trx) => {
const server = await serverRepository.getAllServersByUserId(userId, trx);

if (!server || server.length === 0) {
return;
}

// Mark all servers as terminating
for (const s of server) {
await serverRepository.upsertServer({
...s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class TerminateServersWithoutCredit {

// Terminate servers without credits
const terminationPromises = await Promise.allSettled(serversWithoutCredits.map(async server => {
// Get the appropriate server manager for this region
const serverManager = serverManagerFactory.createServerManager(server.region);
await serverCommander.query({
command: `say Your server is being terminated due to lack of credits.`,
Expand All @@ -74,4 +73,4 @@ export class TerminateServersWithoutCredit {
throw new Error(`Failed to terminate some servers: ${errors.join(', ')}`)
}
}
}
}
Loading