@autofleet/rabbit 3.2.21-beta.0.1 → 3.2.21-beta.0.2

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/index.d.ts CHANGED
@@ -94,8 +94,8 @@ declare class RabbitMq implements IAfRabbitMq {
94
94
  consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any>;
95
95
  publish(exchange: string, content: any, customHeaders?: any): Promise<boolean>;
96
96
  sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<boolean | undefined>;
97
- sendToCeleryQueue(queue: string, taskName: string, data: any, options?: any, customHeaders?: any): Promise<boolean | undefined>;
98
97
  isConnected(): Promise<boolean>;
99
98
  gracefulShutdown(signal: string): Promise<void>;
100
99
  }
101
100
  export default RabbitMq;
101
+ export declare const sendToCelelryQueue: (queueName: string, taskName: string, payload: any) => Promise<import("celery-node/dist/app/result").AsyncResult>;
package/dist/index.js CHANGED
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.sendToCelelryQueue = void 0;
7
8
  const events_1 = require("events");
8
9
  const util_1 = require("util");
9
10
  const moment_1 = __importDefault(require("moment"));
11
+ const celery_node_1 = __importDefault(require("celery-node"));
10
12
  const redis_lock_1 = __importDefault(require("redis-lock"));
11
13
  const amqp_connection_manager_1 = require("amqp-connection-manager");
12
14
  const zehut_1 = require("@autofleet/zehut");
@@ -505,47 +507,6 @@ class RabbitMq {
505
507
  throw e;
506
508
  }
507
509
  }
508
- async sendToCeleryQueue(queue, taskName, data, options, customHeaders) {
509
- try {
510
- await this.assertChannel();
511
- }
512
- catch (e) {
513
- logger_1.default.error(`rabbit sendToCeleryQueue: failed to assert channel when sending to queue ${queue}`, { e });
514
- throw e;
515
- }
516
- try {
517
- RabbitMq.validateName('queue', queue);
518
- await this.assertQueue(queue, options);
519
- }
520
- catch (e) {
521
- logger_1.default.error(`rabbit sendToCeleryQueue: failed to assert queue ${queue}`, { e });
522
- throw e;
523
- }
524
- try {
525
- // Create Celery-compatible message format
526
- const celeryMessage = {
527
- task: taskName,
528
- id: (0, node_crypto_1.randomUUID)(),
529
- args: [data],
530
- };
531
- const celeryHeaders = {
532
- ...RabbitMq.getPublishOptions(customHeaders),
533
- properties: {
534
- delivery_mode: 2,
535
- content_type: 'application/json',
536
- content_encoding: 'utf-8',
537
- },
538
- };
539
- const res = await this.channel?.sendToQueue(queue, Buffer.from(JSON.stringify(celeryMessage)), celeryHeaders);
540
- debug(`rabbit: sending to celery queue ${queue}`, { res });
541
- return res;
542
- }
543
- catch (e) {
544
- const isConnected = await this.isConnected();
545
- logger_1.default.error(`rabbit sendToCeleryQueue: failed to send to queue ${queue}, isConnected: ${isConnected}`, { e });
546
- throw e;
547
- }
548
- }
549
510
  async isConnected() {
550
511
  const connection = await this.getConnection();
551
512
  const isConnected = connection.isConnected();
@@ -584,3 +545,9 @@ class RabbitMq {
584
545
  }
585
546
  }
586
547
  exports.default = RabbitMq;
548
+ const sendToCelelryQueue = async (queueName, taskName, payload) => {
549
+ const host = process.env.RABBITMQ_SERVICE_HOST || 'localhost';
550
+ const client = celery_node_1.default.createClient(host, undefined, queueName);
551
+ return client.sendTask(taskName, [payload], undefined, (0, node_crypto_1.randomUUID)());
552
+ };
553
+ exports.sendToCelelryQueue = sendToCelelryQueue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.21-beta.0.1",
3
+ "version": "3.2.21-beta.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@
19
19
  "amqp-connection-manager": "4.1.9",
20
20
  "amqplib": "0.10.3",
21
21
  "bluebird": "^3.7.2",
22
+ "celery-node": "^0.5.9",
22
23
  "moment": "^2.29.1",
23
24
  "redis": "^3.1.2",
24
25
  "redis-lock": "^0.1.4"
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import { EventEmitter, once } from 'events';
4
4
  import { promisify } from 'util';
5
5
  import moment from 'moment';
6
+ import celery from 'celery-node';
6
7
  import RedisLock from 'redis-lock';
7
8
  import {
8
9
  AmqpConnectionManager, ChannelWrapper, connect, CreateChannelOpts,
@@ -697,60 +698,6 @@ class RabbitMq implements IAfRabbitMq {
697
698
  }
698
699
  }
699
700
 
700
- async sendToCeleryQueue(
701
- queue: string,
702
- taskName: string,
703
- data: any,
704
- options?: any,
705
- customHeaders?: any,
706
- ): Promise<boolean | undefined> {
707
- try {
708
- await this.assertChannel();
709
- } catch (e) {
710
- logger.error(`rabbit sendToCeleryQueue: failed to assert channel when sending to queue ${queue}`, { e });
711
- throw e;
712
- }
713
-
714
- try {
715
- RabbitMq.validateName('queue', queue);
716
- await this.assertQueue(queue, options);
717
- } catch (e) {
718
- logger.error(`rabbit sendToCeleryQueue: failed to assert queue ${queue}`, { e });
719
- throw e;
720
- }
721
-
722
- try {
723
- // Create Celery-compatible message format
724
- const celeryMessage = {
725
- task: taskName,
726
- id: randomUUID(),
727
- args: [data],
728
- };
729
-
730
- const celeryHeaders = {
731
- ...RabbitMq.getPublishOptions(customHeaders),
732
- properties: {
733
- delivery_mode: 2,
734
- content_type: 'application/json',
735
- content_encoding: 'utf-8',
736
- },
737
- };
738
-
739
- const res = await this.channel?.sendToQueue(
740
- queue,
741
- Buffer.from(JSON.stringify(celeryMessage)),
742
- celeryHeaders,
743
- );
744
-
745
- debug(`rabbit: sending to celery queue ${queue}`, { res });
746
- return res;
747
- } catch (e) {
748
- const isConnected = await this.isConnected();
749
- logger.error(`rabbit sendToCeleryQueue: failed to send to queue ${queue}, isConnected: ${isConnected}`, { e });
750
- throw e;
751
- }
752
- }
753
-
754
701
  async isConnected() : Promise<boolean> {
755
702
  const connection = await this.getConnection();
756
703
  const isConnected = connection.isConnected();
@@ -789,3 +736,9 @@ class RabbitMq implements IAfRabbitMq {
789
736
  }
790
737
 
791
738
  export default RabbitMq;
739
+
740
+ export const sendToCelelryQueue = async (queueName: string, taskName: string, payload: any) => {
741
+ const host = process.env.RABBITMQ_SERVICE_HOST || 'localhost';
742
+ const client = celery.createClient(host, undefined, queueName);
743
+ return client.sendTask(taskName, [payload], undefined, randomUUID());
744
+ };