@autofleet/rabbit 3.2.21-beta.0.3 → 3.2.21-beta.0.4
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/package.json +1 -1
- package/src/lib/celery.ts +19 -12
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 sendTaskViaHttp(
|
|
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 {
|
|
85
|
+
export { sendTaskViaHttp, TaskData, SendTaskOptions };
|