@betterinternship/core 2.5.12 → 2.5.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/broker/base.task.d.ts +40 -40
- package/dist/lib/broker/base.task.js +78 -78
- package/package.json +2 -2
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { Task } from '@betterinternship/db';
|
|
2
|
-
import { JsonValue } from '@prisma/client/runtime/client';
|
|
3
|
-
export interface BaseJson {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
}
|
|
6
|
-
export declare class TaskRequest<TaskInputs extends JsonValue> implements Pick<Task, 'inputs' | 'internal_id' | 'handler_id' | 'parent_id' | 'process_id' | 'timestamp'> {
|
|
7
|
-
inputs: TaskInputs;
|
|
8
|
-
internal_id: string;
|
|
9
|
-
handler_id: string;
|
|
10
|
-
parent_id: string | null;
|
|
11
|
-
process_id: string;
|
|
12
|
-
timestamp: Date;
|
|
13
|
-
}
|
|
14
|
-
export declare class TaskResponse<TaskResult extends JsonValue> implements Pick<Task, 'result' | 'status' | 'error'> {
|
|
15
|
-
result: TaskResult;
|
|
16
|
-
error: string;
|
|
17
|
-
status: string;
|
|
18
|
-
}
|
|
19
|
-
type TaskResponseHandler<TaskResult extends JsonValue> = (response: TaskResponse<TaskResult>) => Promise<void>;
|
|
20
|
-
export declare class BaseTaskInitiator<TaskInputs extends JsonValue, TaskResult extends JsonValue> {
|
|
21
|
-
private handlerId;
|
|
22
|
-
private requestQueueId;
|
|
23
|
-
private responseQueueId;
|
|
24
|
-
constructor(queueId: string, handler: TaskResponseHandler<TaskResult>);
|
|
25
|
-
init(handler: TaskResponseHandler<TaskResult>): Promise<void>;
|
|
26
|
-
sendTaskRequest(processId: string, inputs: TaskInputs, options: {
|
|
27
|
-
internalId?: string;
|
|
28
|
-
parentId?: string;
|
|
29
|
-
maxRetries?: number;
|
|
30
|
-
}): Promise<boolean>;
|
|
31
|
-
}
|
|
32
|
-
type TaskRequestHandler<TaskInputs extends JsonValue, TaskResult extends JsonValue> = (task: TaskRequest<TaskInputs>) => Promise<TaskResponse<TaskResult>>;
|
|
33
|
-
export declare class BaseTaskRunner<TaskInputs extends JsonValue, TaskResult extends JsonValue> {
|
|
34
|
-
private requestQueueId;
|
|
35
|
-
private responseQueueId;
|
|
36
|
-
private handler;
|
|
37
|
-
constructor(queueId: string, handler: TaskRequestHandler<TaskInputs, TaskResult>);
|
|
38
|
-
listen(): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
1
|
+
import { Task } from '@betterinternship/db';
|
|
2
|
+
import { JsonValue } from '@prisma/client/runtime/client';
|
|
3
|
+
export interface BaseJson {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export declare class TaskRequest<TaskInputs extends JsonValue> implements Pick<Task, 'inputs' | 'internal_id' | 'handler_id' | 'parent_id' | 'process_id' | 'timestamp'> {
|
|
7
|
+
inputs: TaskInputs;
|
|
8
|
+
internal_id: string;
|
|
9
|
+
handler_id: string;
|
|
10
|
+
parent_id: string | null;
|
|
11
|
+
process_id: string;
|
|
12
|
+
timestamp: Date;
|
|
13
|
+
}
|
|
14
|
+
export declare class TaskResponse<TaskResult extends JsonValue> implements Pick<Task, 'result' | 'status' | 'error'> {
|
|
15
|
+
result: TaskResult;
|
|
16
|
+
error: string;
|
|
17
|
+
status: string;
|
|
18
|
+
}
|
|
19
|
+
type TaskResponseHandler<TaskResult extends JsonValue> = (response: TaskResponse<TaskResult>) => Promise<void>;
|
|
20
|
+
export declare class BaseTaskInitiator<TaskInputs extends JsonValue, TaskResult extends JsonValue> {
|
|
21
|
+
private handlerId;
|
|
22
|
+
private requestQueueId;
|
|
23
|
+
private responseQueueId;
|
|
24
|
+
constructor(queueId: string, handler: TaskResponseHandler<TaskResult>);
|
|
25
|
+
init(handler: TaskResponseHandler<TaskResult>): Promise<void>;
|
|
26
|
+
sendTaskRequest(processId: string, inputs: TaskInputs, options: {
|
|
27
|
+
internalId?: string;
|
|
28
|
+
parentId?: string;
|
|
29
|
+
maxRetries?: number;
|
|
30
|
+
}): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
type TaskRequestHandler<TaskInputs extends JsonValue, TaskResult extends JsonValue> = (task: TaskRequest<TaskInputs>) => Promise<TaskResponse<TaskResult>>;
|
|
33
|
+
export declare class BaseTaskRunner<TaskInputs extends JsonValue, TaskResult extends JsonValue> {
|
|
34
|
+
private requestQueueId;
|
|
35
|
+
private responseQueueId;
|
|
36
|
+
private handler;
|
|
37
|
+
constructor(queueId: string, handler: TaskRequestHandler<TaskInputs, TaskResult>);
|
|
38
|
+
listen(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { BrokerAPI } from './broker.js';
|
|
2
|
-
import { tasks } from '@betterinternship/db';
|
|
3
|
-
import { v4 } from 'uuid';
|
|
4
|
-
export class TaskRequest {
|
|
5
|
-
inputs;
|
|
6
|
-
internal_id;
|
|
7
|
-
handler_id;
|
|
8
|
-
parent_id;
|
|
9
|
-
process_id;
|
|
10
|
-
timestamp;
|
|
11
|
-
}
|
|
12
|
-
export class TaskResponse {
|
|
13
|
-
result;
|
|
14
|
-
error;
|
|
15
|
-
status;
|
|
16
|
-
}
|
|
17
|
-
export class BaseTaskInitiator {
|
|
18
|
-
handlerId;
|
|
19
|
-
requestQueueId;
|
|
20
|
-
responseQueueId;
|
|
21
|
-
constructor(queueId, handler) {
|
|
22
|
-
this.handlerId = queueId;
|
|
23
|
-
this.requestQueueId = `request.${queueId}`;
|
|
24
|
-
this.responseQueueId = `response.${queueId}`;
|
|
25
|
-
void this.init(handler);
|
|
26
|
-
}
|
|
27
|
-
async init(handler) {
|
|
28
|
-
const brokerAPI = await BrokerAPI.instance();
|
|
29
|
-
return await brokerAPI.addQueueHandler(this.responseQueueId, async (taskId) => {
|
|
30
|
-
const task = await tasks.findFirst({ where: { id: taskId } });
|
|
31
|
-
await handler({
|
|
32
|
-
result: task?.result,
|
|
33
|
-
error: task?.error ?? '',
|
|
34
|
-
status: task?.status ?? 'failed',
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
async sendTaskRequest(processId, inputs, options) {
|
|
39
|
-
const brokerAPI = await BrokerAPI.instance();
|
|
40
|
-
const task = await tasks.create({
|
|
41
|
-
data: {
|
|
42
|
-
internal_id: options.internalId ?? `${processId}.${v4()}`,
|
|
43
|
-
parent_id: options.parentId,
|
|
44
|
-
handler_id: this.handlerId,
|
|
45
|
-
process_id: processId,
|
|
46
|
-
inputs: inputs,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
return brokerAPI.addToQueue(this.requestQueueId, task.id, options);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export class BaseTaskRunner {
|
|
53
|
-
requestQueueId;
|
|
54
|
-
responseQueueId;
|
|
55
|
-
handler;
|
|
56
|
-
constructor(queueId, handler) {
|
|
57
|
-
this.requestQueueId = `request.${queueId}`;
|
|
58
|
-
this.responseQueueId = `response.${queueId}`;
|
|
59
|
-
this.handler = handler;
|
|
60
|
-
}
|
|
61
|
-
async listen() {
|
|
62
|
-
const processTask = async (taskId) => {
|
|
63
|
-
const task = await tasks.findFirst({ where: { id: taskId } });
|
|
64
|
-
const response = await this.handler(task);
|
|
65
|
-
await tasks.update({
|
|
66
|
-
where: { id: taskId },
|
|
67
|
-
data: {
|
|
68
|
-
result: response.result ?? {},
|
|
69
|
-
error: response.error ?? '',
|
|
70
|
-
status: response.status,
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
await brokerAPI.addToQueue(this.responseQueueId, taskId);
|
|
74
|
-
};
|
|
75
|
-
const brokerAPI = await BrokerAPI.instance();
|
|
76
|
-
await brokerAPI.addQueueHandler(this.requestQueueId, processTask);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
1
|
+
import { BrokerAPI } from './broker.js';
|
|
2
|
+
import { tasks } from '@betterinternship/db';
|
|
3
|
+
import { v4 } from 'uuid';
|
|
4
|
+
export class TaskRequest {
|
|
5
|
+
inputs;
|
|
6
|
+
internal_id;
|
|
7
|
+
handler_id;
|
|
8
|
+
parent_id;
|
|
9
|
+
process_id;
|
|
10
|
+
timestamp;
|
|
11
|
+
}
|
|
12
|
+
export class TaskResponse {
|
|
13
|
+
result;
|
|
14
|
+
error;
|
|
15
|
+
status;
|
|
16
|
+
}
|
|
17
|
+
export class BaseTaskInitiator {
|
|
18
|
+
handlerId;
|
|
19
|
+
requestQueueId;
|
|
20
|
+
responseQueueId;
|
|
21
|
+
constructor(queueId, handler) {
|
|
22
|
+
this.handlerId = queueId;
|
|
23
|
+
this.requestQueueId = `request.${queueId}`;
|
|
24
|
+
this.responseQueueId = `response.${queueId}`;
|
|
25
|
+
void this.init(handler);
|
|
26
|
+
}
|
|
27
|
+
async init(handler) {
|
|
28
|
+
const brokerAPI = await BrokerAPI.instance();
|
|
29
|
+
return await brokerAPI.addQueueHandler(this.responseQueueId, async (taskId) => {
|
|
30
|
+
const task = await tasks.findFirst({ where: { id: taskId } });
|
|
31
|
+
await handler({
|
|
32
|
+
result: task?.result,
|
|
33
|
+
error: task?.error ?? '',
|
|
34
|
+
status: task?.status ?? 'failed',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async sendTaskRequest(processId, inputs, options) {
|
|
39
|
+
const brokerAPI = await BrokerAPI.instance();
|
|
40
|
+
const task = await tasks.create({
|
|
41
|
+
data: {
|
|
42
|
+
internal_id: options.internalId ?? `${processId}.${v4()}`,
|
|
43
|
+
parent_id: options.parentId,
|
|
44
|
+
handler_id: this.handlerId,
|
|
45
|
+
process_id: processId,
|
|
46
|
+
inputs: inputs,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return brokerAPI.addToQueue(this.requestQueueId, task.id, options);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class BaseTaskRunner {
|
|
53
|
+
requestQueueId;
|
|
54
|
+
responseQueueId;
|
|
55
|
+
handler;
|
|
56
|
+
constructor(queueId, handler) {
|
|
57
|
+
this.requestQueueId = `request.${queueId}`;
|
|
58
|
+
this.responseQueueId = `response.${queueId}`;
|
|
59
|
+
this.handler = handler;
|
|
60
|
+
}
|
|
61
|
+
async listen() {
|
|
62
|
+
const processTask = async (taskId) => {
|
|
63
|
+
const task = await tasks.findFirst({ where: { id: taskId } });
|
|
64
|
+
const response = await this.handler(task);
|
|
65
|
+
await tasks.update({
|
|
66
|
+
where: { id: taskId },
|
|
67
|
+
data: {
|
|
68
|
+
result: response.result ?? {},
|
|
69
|
+
error: response.error ?? '',
|
|
70
|
+
status: response.status,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
await brokerAPI.addToQueue(this.responseQueueId, taskId);
|
|
74
|
+
};
|
|
75
|
+
const brokerAPI = await BrokerAPI.instance();
|
|
76
|
+
await brokerAPI.addQueueHandler(this.requestQueueId, processTask);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
79
|
//# sourceMappingURL=base.task.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterinternship/core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14",
|
|
4
4
|
"description": "Core library of BetterInternship services.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"license": "ISC",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@aws-sdk/client-ses": "^3.971.0",
|
|
55
|
-
"@betterinternship/db": "^1.0.
|
|
55
|
+
"@betterinternship/db": "^1.0.11",
|
|
56
56
|
"@supabase/supabase-js": "^2.52.0",
|
|
57
57
|
"@types/amqplib": "^0.10.7",
|
|
58
58
|
"@types/nodemailer": "^7.0.3",
|