@autofleet/rabbit 3.2.21-beta.0.3 → 3.2.21-beta.0.5
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/celery.d.ts +6 -2
- package/dist/lib/celery.js +10 -14
- package/package.json +1 -1
- package/src/lib/celery.ts +19 -12
package/dist/lib/celery.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
interface TaskData {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
interface SendTaskOptions {
|
|
5
|
+
taskName: string;
|
|
6
|
+
queueName: string;
|
|
7
|
+
}
|
|
8
|
+
declare function sendCeleryTaskViaHttp(data: TaskData, { taskName, queueName }: SendTaskOptions): Promise<void>;
|
|
9
|
+
export { sendCeleryTaskViaHttp, TaskData, SendTaskOptions };
|
package/dist/lib/celery.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.sendCeleryTaskViaHttp = void 0;
|
|
7
4
|
const node_crypto_1 = require("node:crypto");
|
|
8
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
9
5
|
// Environment configuration
|
|
10
6
|
const config = {
|
|
11
|
-
host: process.env.RABBITMQ_SERVICE_HOST || '
|
|
12
|
-
username: process.env.RABBITMQ_USERNAME || '
|
|
13
|
-
password: process.env.RABBITMQ_PASSWORD || '
|
|
7
|
+
host: process.env.RABBITMQ_SERVICE_HOST || '10.132.15.204',
|
|
8
|
+
username: process.env.RABBITMQ_USERNAME || 'default_user_Zjlb8cnBF-jwc61bbC8',
|
|
9
|
+
password: process.env.RABBITMQ_PASSWORD || 'SDjnZWKAgz9TROLDV85OUZb6FOLlfw1b',
|
|
14
10
|
};
|
|
15
|
-
async function sendCeleryTaskViaHttp(data) {
|
|
11
|
+
async function sendCeleryTaskViaHttp(data, { taskName, queueName }) {
|
|
16
12
|
const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
|
|
17
13
|
const message = {
|
|
18
|
-
task:
|
|
14
|
+
task: taskName,
|
|
19
15
|
id: (0, node_crypto_1.randomUUID)(),
|
|
20
16
|
args: [data],
|
|
21
17
|
};
|
|
@@ -24,7 +20,7 @@ async function sendCeleryTaskViaHttp(data) {
|
|
|
24
20
|
delivery_mode: 2,
|
|
25
21
|
content_type: 'application/json',
|
|
26
22
|
},
|
|
27
|
-
routing_key:
|
|
23
|
+
routing_key: queueName,
|
|
28
24
|
payload: JSON.stringify(message),
|
|
29
25
|
payload_encoding: 'string',
|
|
30
26
|
};
|
|
@@ -39,15 +35,15 @@ async function sendCeleryTaskViaHttp(data) {
|
|
|
39
35
|
});
|
|
40
36
|
if (response.ok) {
|
|
41
37
|
const result = await response.json();
|
|
42
|
-
|
|
38
|
+
console.log('Successfully published message:', result);
|
|
43
39
|
}
|
|
44
40
|
else {
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
console.error(`Failed to publish message. Status code: ${response.status}`);
|
|
42
|
+
console.error(`Response: ${await response.text()}`);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
catch (error) {
|
|
50
|
-
|
|
46
|
+
console.error('Error sending request:', error instanceof Error ? error.message : String(error));
|
|
51
47
|
throw error;
|
|
52
48
|
}
|
|
53
49
|
}
|
package/package.json
CHANGED
package/src/lib/celery.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import logger from '../logger';
|
|
3
2
|
|
|
4
3
|
// Environment configuration
|
|
5
4
|
const config = {
|
|
6
|
-
host: process.env.RABBITMQ_SERVICE_HOST || '
|
|
7
|
-
username: process.env.RABBITMQ_USERNAME || '
|
|
8
|
-
password: process.env.RABBITMQ_PASSWORD || '
|
|
5
|
+
host: process.env.RABBITMQ_SERVICE_HOST || '10.132.15.204',
|
|
6
|
+
username: process.env.RABBITMQ_USERNAME || 'default_user_Zjlb8cnBF-jwc61bbC8',
|
|
7
|
+
password: process.env.RABBITMQ_PASSWORD || 'SDjnZWKAgz9TROLDV85OUZb6FOLlfw1b',
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
// Type definitions
|
|
@@ -33,11 +32,19 @@ interface PublishResponse {
|
|
|
33
32
|
routed: boolean;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
interface SendTaskOptions {
|
|
36
|
+
taskName: string;
|
|
37
|
+
queueName: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function sendCeleryTaskViaHttp(
|
|
41
|
+
data: TaskData,
|
|
42
|
+
{ taskName, queueName }: SendTaskOptions,
|
|
43
|
+
): Promise<void> {
|
|
37
44
|
const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
|
|
38
45
|
|
|
39
46
|
const message: TaskMessage = {
|
|
40
|
-
task:
|
|
47
|
+
task: taskName,
|
|
41
48
|
id: randomUUID(),
|
|
42
49
|
args: [data],
|
|
43
50
|
};
|
|
@@ -47,7 +54,7 @@ async function sendCeleryTaskViaHttp(data: TaskData): Promise<void> {
|
|
|
47
54
|
delivery_mode: 2,
|
|
48
55
|
content_type: 'application/json',
|
|
49
56
|
},
|
|
50
|
-
routing_key:
|
|
57
|
+
routing_key: queueName,
|
|
51
58
|
payload: JSON.stringify(message),
|
|
52
59
|
payload_encoding: 'string',
|
|
53
60
|
};
|
|
@@ -64,15 +71,15 @@ async function sendCeleryTaskViaHttp(data: TaskData): Promise<void> {
|
|
|
64
71
|
|
|
65
72
|
if (response.ok) {
|
|
66
73
|
const result: PublishResponse = await response.json();
|
|
67
|
-
|
|
74
|
+
console.log('Successfully published message:', result);
|
|
68
75
|
} else {
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
console.error(`Failed to publish message. Status code: ${response.status}`);
|
|
77
|
+
console.error(`Response: ${await response.text()}`);
|
|
71
78
|
}
|
|
72
79
|
} catch (error) {
|
|
73
|
-
|
|
80
|
+
console.error('Error sending request:', error instanceof Error ? error.message : String(error));
|
|
74
81
|
throw error;
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
export { sendCeleryTaskViaHttp, TaskData };
|
|
85
|
+
export { sendCeleryTaskViaHttp, TaskData, SendTaskOptions };
|