Skip to content

Commit

Permalink
delete temporal schedule for discourse.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed Nov 26, 2024
1 parent 4070eb2 commit e54c1eb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/services/discourse/core.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ async function createDiscourseSchedule(platformId: string, endpoint: string): Pr
await schedule.trigger();
return schedule.scheduleId;
} catch (error) {
logger.error(error, 'Failed to create discourse schedule');
throw new ApiError(590, 'Failed to create discourse schedule');
logger.error(error, 'Failed to create discourse schedule.');
throw new ApiError(590, 'Failed to create discourse schedule.');
}
}

async function deleteDiscourseSchedule(scheduleId: string): Promise<void> {
try {
await temporalDiscourse.deleteSchedule(scheduleId);
} catch (error) {
logger.error(error, 'Failed to delete discourse schedule.');
throw new ApiError(590, 'Failed to delete discourse schedule.');
}
}

export default {
getPropertyHandler,
createDiscourseSchedule,
deleteDiscourseSchedule,
};
11 changes: 10 additions & 1 deletion src/services/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ const updatePlatform = async (
* @returns {Promise<HydratedDocument<IPlatform>>}
*/
const deletePlatform = async (platform: HydratedDocument<IPlatform>): Promise<HydratedDocument<IPlatform>> => {
switch (platform.name) {
case PlatformNames.Discourse: {
if (platform.metadata?.scheduleId) {
await discourseService.coreService.deleteDiscourseSchedule(platform.metadata.scheduleId);
}
}
default: {
}
}
return await platform.remove();
};

Expand All @@ -157,7 +166,7 @@ const deletePlatformByFilter = async (filter: object): Promise<HydratedDocument<
if (!platform) {
throw new ApiError(httpStatus.NOT_FOUND, 'Platform not found');
}
return await platform.remove();
return await deletePlatform(platform);
};

function getMetadataKey(platformName: string): string {
Expand Down
12 changes: 12 additions & 0 deletions src/services/temporal/discourse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ class TemporalDiscourseService extends TemporalCoreService {
throw new Error(`Failed to create Temporal schedule: ${(error as Error).message}`);
}
}

public async pauseSchedule(scheduleId: string): Promise<void> {
const client: Client = await this.getClient();
const handle = client.schedule.getHandle(scheduleId);
await handle.pause();
}

public async deleteSchedule(scheduleId: string): Promise<void> {
const client: Client = await this.getClient();
const handle = client.schedule.getHandle(scheduleId);
await handle.delete();
}
}

export default new TemporalDiscourseService();

0 comments on commit e54c1eb

Please sign in to comment.