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
13 changes: 3 additions & 10 deletions src/services/module.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,16 @@ const handleHivemindWebsiteCase = async (platform: any) => {
* @param {Object} platform - Platform object
*/
const handleHivemindMediaWikiCase = async (platform: any) => {
console.log('Handling Hivemind MediaWiki case for platform:', platform);
const platformDoc = await platformService.getPlatformById(platform.platform);

if (!platformDoc) return;

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

if (isActivated === true) {
console.log('Platform is activated, checking for existing workflow ID:', existingWorkflowId);
if (!existingWorkflowId) {
console.log('No existing workflow ID found, executing new workflow for platform:', platform.platform);
const workflowId = await temporalMediaWiki.executeWorkflow(platform.platform);
console.log('New workflow ID created:', workflowId);
platformDoc.set('metadata.workflowId', workflowId);
await platformDoc.save();
}
temporalMediaWiki.executeWorkflow(platformDoc.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing await for workflow execution.

The workflow execution call is not awaited, which could lead to the function returning before the workflow starts. This may cause issues if subsequent operations depend on the workflow being active.

Apply this diff to fix the async operation:

-    temporalMediaWiki.executeWorkflow(platformDoc.id);
+    await temporalMediaWiki.executeWorkflow(platformDoc.id);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
temporalMediaWiki.executeWorkflow(platformDoc.id);
await temporalMediaWiki.executeWorkflow(platformDoc.id);
🤖 Prompt for AI Agents
In src/services/module.service.ts at line 150, the call to
temporalMediaWiki.executeWorkflow(platformDoc.id) is missing an await, causing
the function to potentially return before the workflow starts. Add the await
keyword before temporalMediaWiki.executeWorkflow to ensure the workflow
execution completes or starts before proceeding.

} else if (isActivated === false) {
temporalMediaWiki.terminateWorkflow(platformDoc.id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing await for workflow termination.

The workflow termination call is not awaited, which could lead to the function returning before the workflow is actually terminated. This may cause issues if the platform state depends on the workflow being stopped.

Apply this diff to fix the async operation:

-    temporalMediaWiki.terminateWorkflow(platformDoc.id);
+    await temporalMediaWiki.terminateWorkflow(platformDoc.id);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
temporalMediaWiki.terminateWorkflow(platformDoc.id);
await temporalMediaWiki.terminateWorkflow(platformDoc.id);
🤖 Prompt for AI Agents
In src/services/module.service.ts at line 152, the call to
temporalMediaWiki.terminateWorkflow(platformDoc.id) is missing an await, causing
the function to potentially return before the workflow termination completes.
Add the await keyword before the call to ensure the workflow termination
finishes before proceeding.

}
};

Expand Down
21 changes: 9 additions & 12 deletions src/services/temporal/mediaWiki.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@ const logger = parentLogger.child({ module: 'MediaWikiTemporalService' });
class TemporalMediaWikiService extends TemporalCoreService {
public async executeWorkflow(platformId: Types.ObjectId) {
const client: Client = await this.getClient();
const payload = {
platform_id: platformId,
};
const payload = platformId;
try {
const workflowHandle = await client.workflow.execute('MediaWikiETLWorkflow', {
client.workflow.execute('MediaWikiETLWorkflow', {
taskQueue: queues.TEMPORAL_QUEUE_PYTHON_HEAVY,
args: [payload],
workflowId: `mediawiki/${platformId}/${uuidv4()}`,
workflowId: `api:mediawikietl:${platformId}`,
});
Comment on lines +17 to 21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing await for workflow execution.

The workflow execution is not awaited, which means the method will return immediately without waiting for the workflow to start. This could lead to race conditions or make error handling ineffective.

Apply this diff to fix the async operation:

-      client.workflow.execute('MediaWikiETLWorkflow', {
+      await client.workflow.execute('MediaWikiETLWorkflow', {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
client.workflow.execute('MediaWikiETLWorkflow', {
taskQueue: queues.TEMPORAL_QUEUE_PYTHON_HEAVY,
args: [payload],
workflowId: `mediawiki/${platformId}/${uuidv4()}`,
workflowId: `api:mediawikietl:${platformId}`,
});
await client.workflow.execute('MediaWikiETLWorkflow', {
taskQueue: queues.TEMPORAL_QUEUE_PYTHON_HEAVY,
args: [payload],
workflowId: `api:mediawikietl:${platformId}`,
});
🤖 Prompt for AI Agents
In src/services/temporal/mediaWiki.service.ts around lines 17 to 21, the call to
client.workflow.execute is missing an await, causing the method to return
immediately without waiting for the workflow to start. To fix this, add the
await keyword before client.workflow.execute to ensure the workflow execution is
properly awaited and errors can be handled effectively.

logger.info(`Started MediaWiki workflow with ID: ${workflowHandle}`);
return workflowHandle;
} catch (error) {
logger.error(`Failed to trigger MediaWiki workflow: ${(error as Error).message}`);
throw new Error(`Failed to trigger MediaWiki workflow: ${(error as Error).message}`);
}
}

public async terminateWorkflow(workflowId: string): Promise<void> {
public async terminateWorkflow(platformId: Types.ObjectId): Promise<void> {
const client: Client = await this.getClient();
const handle = client.workflow.getHandle(workflowId);
const description = await handle.describe();
if (description.status.name !== 'TERMINATED' && description.status.name !== 'COMPLETED') {
await handle.terminate('Terminated due to schedule deletion');
try {
client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing await for workflow termination.

The workflow termination is not awaited, which means the method will return before the termination completes. This could lead to inconsistent state or ineffective error handling.

Apply this diff to fix the async operation:

-      client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
+      await client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
await client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
🤖 Prompt for AI Agents
In src/services/temporal/mediaWiki.service.ts at line 31, the call to terminate
the workflow handle is missing an await, causing the method to return before the
termination completes. Add the await keyword before
client.workflow.getHandle(...).terminate() to ensure the termination completes
before proceeding, enabling proper error handling and consistent state.

} catch (error) {
logger.error(`Failed to terminate MediaWiki workflow: ${(error as Error).message}`);
throw new Error(`Failed to terminate MediaWiki workflow: ${(error as Error).message}`);
}
}
}
Expand Down