-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmediaWiki.service.ts
More file actions
39 lines (33 loc) · 1.43 KB
/
mediaWiki.service.ts
File metadata and controls
39 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Types } from 'mongoose';
import { v4 as uuidv4 } from 'uuid';
import { Client } from '@temporalio/client';
import parentLogger from '../../config/logger';
import { queues } from './configs/temporal.config';
import { TemporalCoreService } from './core.service';
const logger = parentLogger.child({ module: 'MediaWikiTemporalService' });
class TemporalMediaWikiService extends TemporalCoreService {
public async executeWorkflow(platformId: Types.ObjectId) {
const client: Client = await this.getClient();
const payload = platformId;
try {
client.workflow.execute('MediaWikiETLWorkflow', {
taskQueue: queues.TEMPORAL_QUEUE_PYTHON_HEAVY,
args: [payload],
workflowId: `api:mediawikietl:${platformId}`,
});
} 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(platformId: Types.ObjectId): Promise<void> {
const client: Client = await this.getClient();
try {
client.workflow.getHandle(`api:mediawikietl:${platformId}`).terminate();
} 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}`);
}
}
}
export default new TemporalMediaWikiService();