Skip to content

Commit e81a1ac

Browse files
Merge pull request #481 from TogetherCrew/mediawiki-changes
Mediawiki changes
2 parents 2f5ebe5 + bb4b85b commit e81a1ac

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/services/module.service.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,16 @@ const handleHivemindWebsiteCase = async (platform: any) => {
140140
* @param {Object} platform - Platform object
141141
*/
142142
const handleHivemindMediaWikiCase = async (platform: any) => {
143-
console.log('Handling Hivemind MediaWiki case for platform:', platform);
144143
const platformDoc = await platformService.getPlatformById(platform.platform);
145144

146145
if (!platformDoc) return;
147146

148147
const isActivated = platform.metadata?.activated;
149-
const existingWorkflowId = platformDoc.get('metadata.workflowId');
150148

151149
if (isActivated === true) {
152-
console.log('Platform is activated, checking for existing workflow ID:', existingWorkflowId);
153-
if (!existingWorkflowId) {
154-
console.log('No existing workflow ID found, executing new workflow for platform:', platform.platform);
155-
const workflowId = await temporalMediaWiki.executeWorkflow(platform.platform);
156-
console.log('New workflow ID created:', workflowId);
157-
platformDoc.set('metadata.workflowId', workflowId);
158-
await platformDoc.save();
159-
}
150+
temporalMediaWiki.executeWorkflow(platformDoc.id);
151+
} else if (isActivated === false) {
152+
temporalMediaWiki.terminateWorkflow(platformDoc.id);
160153
}
161154
};
162155

src/services/temporal/mediaWiki.service.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@ const logger = parentLogger.child({ module: 'MediaWikiTemporalService' });
1212
class TemporalMediaWikiService extends TemporalCoreService {
1313
public async executeWorkflow(platformId: Types.ObjectId) {
1414
const client: Client = await this.getClient();
15-
const payload = {
16-
platform_id: platformId,
17-
};
15+
const payload = platformId;
1816
try {
19-
const workflowHandle = await client.workflow.execute('MediaWikiETLWorkflow', {
17+
client.workflow.execute('MediaWikiETLWorkflow', {
2018
taskQueue: queues.TEMPORAL_QUEUE_PYTHON_HEAVY,
2119
args: [payload],
22-
workflowId: `mediawiki/${platformId}/${uuidv4()}`,
20+
workflowId: `api:mediawikietl:${platformId}`,
2321
});
24-
logger.info(`Started MediaWiki workflow with ID: ${workflowHandle}`);
25-
return workflowHandle;
2622
} catch (error) {
2723
logger.error(`Failed to trigger MediaWiki workflow: ${(error as Error).message}`);
2824
throw new Error(`Failed to trigger MediaWiki workflow: ${(error as Error).message}`);
2925
}
3026
}
3127

32-
public async terminateWorkflow(workflowId: string): Promise<void> {
28+
public async terminateWorkflow(platformId: Types.ObjectId): Promise<void> {
3329
const client: Client = await this.getClient();
34-
const handle = client.workflow.getHandle(workflowId);
35-
const description = await handle.describe();
36-
if (description.status.name !== 'TERMINATED' && description.status.name !== 'COMPLETED') {
37-
await handle.terminate('Terminated due to schedule deletion');
30+
try {
31+
client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
32+
} catch (error) {
33+
logger.error(`Failed to terminate MediaWiki workflow: ${(error as Error).message}`);
34+
throw new Error(`Failed to terminate MediaWiki workflow: ${(error as Error).message}`);
3835
}
3936
}
4037
}

0 commit comments

Comments
 (0)