Skip to content

Commit

Permalink
fix: a regression caught by bug repro test 1047
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Dec 29, 2024
1 parent 97ae93a commit e8c9c34
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/app-api/src/service/CommandService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PlayerService } from './PlayerService.js';
import { PlayerOnGameServerService } from './PlayerOnGameserverService.js';
import { UserService } from './User/index.js';
import { ModuleService } from './Module/index.js';
import { InstallModuleDTO } from './Module/dto.js';

export function commandsRunningKey(data: ICommandJobData) {
return `commands-running:${data.pog.id}`;
Expand Down Expand Up @@ -244,6 +245,25 @@ export class CommandService extends TakaroService<CommandModel, CommandOutputDTO
}

const updated = await this.repo.update(id, item);

const installations = await this.moduleService.getInstalledModules({ versionId: updated.versionId });
await Promise.all(
installations.map((i) => {
const newSystemConfig = i.systemConfig;
const cmdCfg = newSystemConfig.commands[existing.name];
delete newSystemConfig.commands[existing.name];
newSystemConfig.commands[updated.name] = cmdCfg;
return this.moduleService.installModule(
new InstallModuleDTO({
gameServerId: i.gameserverId,
versionId: i.versionId,
userConfig: JSON.stringify(i.userConfig),
systemConfig: JSON.stringify(newSystemConfig),
}),
);
}),
);

return updated;
}

Expand Down
20 changes: 19 additions & 1 deletion packages/app-api/src/service/CronJobService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TakaroDTO, errors, TakaroModelDTO, traceableClass } from '@takaro/util'
import { PaginatedOutput } from '../db/base.js';
import { ITakaroQuery } from '@takaro/db';
import { randomUUID } from 'crypto';
import { ModuleInstallationOutputDTO } from './Module/dto.js';
import { InstallModuleDTO, ModuleInstallationOutputDTO } from './Module/dto.js';
import { ModuleService } from './Module/index.js';

export class CronJobOutputDTO extends TakaroModelDTO<CronJobOutputDTO> {
Expand Down Expand Up @@ -121,6 +121,24 @@ export class CronJobService extends TakaroService<CronJobModel, CronJobOutputDTO
const updated = await this.repo.update(id, item);

const installedModules = await this.moduleService.getInstalledModules({ versionId: updated.versionId });

await Promise.all(
installedModules.map((i) => {
const newSystemConfig = i.systemConfig;
const cmdCfg = newSystemConfig.cronJobs[existing.name];
delete newSystemConfig.cronJobs[existing.name];
newSystemConfig.cronJobs[updated.name] = cmdCfg;
return this.moduleService.installModule(
new InstallModuleDTO({
gameServerId: i.gameserverId,
versionId: i.versionId,
userConfig: JSON.stringify(i.userConfig),
systemConfig: JSON.stringify(newSystemConfig),
}),
);
}),
);

await Promise.all(installedModules.map((mod) => this.syncModuleCronjobs(mod)));
return updated;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/app-api/src/service/HookService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { HookEvents, isDiscordMessageEvent, EventPayload, EventTypes, EventMappi
import { PlayerOnGameServerService } from './PlayerOnGameserverService.js';
import { PlayerService } from './PlayerService.js';
import { ModuleService } from './Module/index.js';
import { InstallModuleDTO } from './Module/dto.js';

interface IHandleHookOptions {
eventType: EventTypes;
Expand Down Expand Up @@ -165,6 +166,24 @@ export class HookService extends TakaroService<HookModel, HookOutputDTO, HookCre

const updated = await this.repo.update(id, item);

const installations = await this.moduleService.getInstalledModules({ versionId: updated.versionId });
await Promise.all(
installations.map((i) => {
const newSystemConfig = i.systemConfig;
const cmdCfg = newSystemConfig.hooks[existing.name];
delete newSystemConfig.hooks[existing.name];
newSystemConfig.hooks[updated.name] = cmdCfg;
return this.moduleService.installModule(
new InstallModuleDTO({
gameServerId: i.gameserverId,
versionId: i.versionId,
userConfig: JSON.stringify(i.userConfig),
systemConfig: JSON.stringify(newSystemConfig),
}),
);
}),
);

return updated;
}

Expand Down

0 comments on commit e8c9c34

Please sign in to comment.