@devbro/pashmak 0.1.20 → 0.1.22
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/app/console/queue/queue_migration.tpl +1 -1
- package/dist/bin/app/console/DefaultCommand.cjs +76 -88
- package/dist/bin/app/console/KeyGenerateCommand.cjs +76 -88
- package/dist/bin/app/console/StartCommand.cjs +76 -88
- package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +76 -88
- package/dist/bin/app/console/generate/index.cjs +76 -88
- package/dist/bin/app/console/index.cjs +76 -88
- package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +76 -88
- package/dist/bin/app/console/migrate/MigrateCommand.cjs +76 -88
- package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +76 -88
- package/dist/bin/app/console/migrate/index.cjs +76 -88
- package/dist/bin/app/console/queue/GenerateQueueMigrateCommand.cjs +76 -88
- package/dist/bin/cache.cjs +76 -88
- package/dist/bin/facades.cjs +76 -88
- package/dist/bin/factories.cjs +68 -84
- package/dist/bin/index.cjs +79 -91
- package/dist/bin/middlewares.cjs +76 -88
- package/dist/bin/queue.cjs +66 -78
- package/dist/facades.mjs +15 -10
- package/dist/facades.mjs.map +1 -1
- package/dist/factories.d.mts +1 -13
- package/dist/factories.mjs +13 -34
- package/dist/factories.mjs.map +1 -1
- package/dist/queue.d.mts +11 -5
- package/dist/queue.mjs +51 -45
- package/dist/queue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bin/facades.cjs
CHANGED
|
@@ -463,7 +463,7 @@ var Router = class {
|
|
|
463
463
|
|
|
464
464
|
// src/facades.mts
|
|
465
465
|
var import_neko_scheduler = require("@devbro/neko-scheduler");
|
|
466
|
-
var
|
|
466
|
+
var import_neko_helper2 = require("@devbro/neko-helper");
|
|
467
467
|
var import_neko_context2 = require("@devbro/neko-context");
|
|
468
468
|
var import_neko_storage2 = require("@devbro/neko-storage");
|
|
469
469
|
var import_neko_mailer2 = require("@devbro/neko-mailer");
|
|
@@ -489,11 +489,11 @@ __export(queue_exports, {
|
|
|
489
489
|
DatabaseTransport: () => DatabaseTransport
|
|
490
490
|
});
|
|
491
491
|
__reExport(queue_exports, require("@devbro/neko-queue"));
|
|
492
|
+
var import_neko_helper = require("@devbro/neko-helper");
|
|
492
493
|
var DatabaseTransport = class {
|
|
493
494
|
static {
|
|
494
495
|
__name(this, "DatabaseTransport");
|
|
495
496
|
}
|
|
496
|
-
activeIntervals = /* @__PURE__ */ new Set();
|
|
497
497
|
config = {
|
|
498
498
|
queue_table: "queue_messages",
|
|
499
499
|
db_connection: "default",
|
|
@@ -502,14 +502,48 @@ var DatabaseTransport = class {
|
|
|
502
502
|
message_limit: 10
|
|
503
503
|
// messages per each fetch
|
|
504
504
|
};
|
|
505
|
-
|
|
505
|
+
channels = /* @__PURE__ */ new Map();
|
|
506
|
+
messageQueues = [];
|
|
507
|
+
repeater;
|
|
508
|
+
processMessage = /* @__PURE__ */ __name(async () => {
|
|
509
|
+
const conn = db(this.config.db_connection);
|
|
510
|
+
try {
|
|
511
|
+
await conn.connect();
|
|
512
|
+
let q = conn.getQuery();
|
|
513
|
+
let messages = await q.table(this.config.queue_table).whereOp("channel", "in", Array.from(this.channels.keys())).whereOp("status", "in", ["pending", "failed"]).limit(this.config.message_limit).orderBy("last_tried_at", "asc").get();
|
|
514
|
+
for (let msg of messages) {
|
|
515
|
+
try {
|
|
516
|
+
let callback = this.channels.get(msg.channel);
|
|
517
|
+
await callback(msg.message);
|
|
518
|
+
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
519
|
+
status: "processed",
|
|
520
|
+
updated_at: /* @__PURE__ */ new Date(),
|
|
521
|
+
last_tried_at: /* @__PURE__ */ new Date(),
|
|
522
|
+
retried_count: (msg.retried_count || 0) + 1
|
|
523
|
+
});
|
|
524
|
+
} catch (error) {
|
|
525
|
+
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
526
|
+
status: "failed",
|
|
527
|
+
last_tried_at: /* @__PURE__ */ new Date(),
|
|
528
|
+
retried_count: (msg.retried_count || 0) + 1,
|
|
529
|
+
process_message: error.message || "Error processing message"
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
} catch (error) {
|
|
534
|
+
logger().error("Error in DatabaseTransport listen interval:", {
|
|
535
|
+
error
|
|
536
|
+
});
|
|
537
|
+
} finally {
|
|
538
|
+
await conn.disconnect();
|
|
539
|
+
}
|
|
540
|
+
}, "processMessage");
|
|
541
|
+
constructor(config2 = {}) {
|
|
506
542
|
this.config = { ...this.config, ...config2 };
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
setMessageLimit(limit) {
|
|
512
|
-
this.config.message_limit = limit;
|
|
543
|
+
this.repeater = (0, import_neko_helper.createRepeater)(
|
|
544
|
+
this.processMessage,
|
|
545
|
+
this.config.listen_interval * 1e3
|
|
546
|
+
);
|
|
513
547
|
}
|
|
514
548
|
async dispatch(channel, message) {
|
|
515
549
|
const conn = db(this.config.db_connection);
|
|
@@ -527,50 +561,22 @@ var DatabaseTransport = class {
|
|
|
527
561
|
created_at: /* @__PURE__ */ new Date(),
|
|
528
562
|
updated_at: /* @__PURE__ */ new Date(),
|
|
529
563
|
last_tried_at: null,
|
|
530
|
-
process_message: ""
|
|
564
|
+
process_message: "",
|
|
565
|
+
retried_count: 0,
|
|
566
|
+
status: "pending"
|
|
531
567
|
});
|
|
532
568
|
} finally {
|
|
533
569
|
await conn.disconnect();
|
|
534
570
|
}
|
|
535
571
|
}
|
|
536
|
-
async
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
await conn.connect();
|
|
542
|
-
let q = conn.getQuery();
|
|
543
|
-
let messages = await q.table(this.config.queue_table).whereOp("channel", "=", channel).whereOp("processed", "=", false).limit(this.config.message_limit).orderBy("last_tried_at", "asc").get();
|
|
544
|
-
for (let msg of messages) {
|
|
545
|
-
try {
|
|
546
|
-
await callback(msg.message);
|
|
547
|
-
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
548
|
-
processed: true,
|
|
549
|
-
updated_at: /* @__PURE__ */ new Date()
|
|
550
|
-
});
|
|
551
|
-
} catch (error) {
|
|
552
|
-
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
553
|
-
processed: false,
|
|
554
|
-
last_tried_at: /* @__PURE__ */ new Date(),
|
|
555
|
-
process_message: error.message || "Error processing message"
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
} catch (error) {
|
|
560
|
-
this.activeIntervals.delete(intervalId);
|
|
561
|
-
logger().error("Error in DatabaseTransport listen interval:", { error });
|
|
562
|
-
} finally {
|
|
563
|
-
await conn.disconnect();
|
|
564
|
-
}
|
|
565
|
-
}, this.config.listen_interval * 1e3);
|
|
566
|
-
this.activeIntervals.add(intervalId);
|
|
567
|
-
});
|
|
572
|
+
async registerListener(channel, callback) {
|
|
573
|
+
this.channels.set(channel, callback);
|
|
574
|
+
}
|
|
575
|
+
async startListening() {
|
|
576
|
+
this.repeater.start();
|
|
568
577
|
}
|
|
569
578
|
async stopListening() {
|
|
570
|
-
|
|
571
|
-
clearInterval(intervalId);
|
|
572
|
-
}
|
|
573
|
-
this.activeIntervals.clear();
|
|
579
|
+
this.repeater.stop();
|
|
574
580
|
}
|
|
575
581
|
};
|
|
576
582
|
|
|
@@ -593,19 +599,7 @@ var FlexibleFactory = class {
|
|
|
593
599
|
return ctor(...args);
|
|
594
600
|
}
|
|
595
601
|
};
|
|
596
|
-
|
|
597
|
-
static {
|
|
598
|
-
__name(this, "MailerFactory");
|
|
599
|
-
}
|
|
600
|
-
static instance = new FlexibleFactory();
|
|
601
|
-
static register(key, factory) {
|
|
602
|
-
_MailerFactory.instance.register(key, factory);
|
|
603
|
-
}
|
|
604
|
-
static create(key, ...args) {
|
|
605
|
-
return _MailerFactory.instance.create(key, ...args);
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
MailerFactory.register("logger", (opt) => {
|
|
602
|
+
import_neko_mailer.MailerProviderFactory.register("logger", (opt) => {
|
|
609
603
|
return new import_neko_mailer.FunctionProvider((mail) => {
|
|
610
604
|
logger().info({
|
|
611
605
|
msg: "Sending email",
|
|
@@ -613,32 +607,20 @@ MailerFactory.register("logger", (opt) => {
|
|
|
613
607
|
});
|
|
614
608
|
});
|
|
615
609
|
});
|
|
616
|
-
|
|
610
|
+
import_neko_mailer.MailerProviderFactory.register("ses", (opt) => {
|
|
617
611
|
return new import_neko_mailer.SESProvider(opt);
|
|
618
612
|
});
|
|
619
|
-
|
|
613
|
+
import_neko_mailer.MailerProviderFactory.register("smtp", (opt) => {
|
|
620
614
|
return new import_neko_mailer.SMTPProvider(opt);
|
|
621
615
|
});
|
|
622
|
-
|
|
616
|
+
import_neko_mailer.MailerProviderFactory.register("memory", (opt) => {
|
|
623
617
|
return new import_neko_mailer.MemoryProvider();
|
|
624
618
|
});
|
|
625
|
-
|
|
626
|
-
static {
|
|
627
|
-
__name(this, "QueueTransportFactory");
|
|
628
|
-
}
|
|
629
|
-
static instance = new FlexibleFactory();
|
|
630
|
-
static register(key, factory) {
|
|
631
|
-
_QueueTransportFactory.instance.register(key, factory);
|
|
632
|
-
}
|
|
633
|
-
static create(key, ...args) {
|
|
634
|
-
return _QueueTransportFactory.instance.create(key, ...args);
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
QueueTransportFactory.register("database", (opt) => {
|
|
619
|
+
import_neko_queue2.QueueTransportFactory.register("database", (opt) => {
|
|
638
620
|
let transport = new DatabaseTransport(opt);
|
|
639
621
|
return new import_neko_queue.QueueConnection(transport);
|
|
640
622
|
});
|
|
641
|
-
QueueTransportFactory.register("memory", (opt) => {
|
|
623
|
+
import_neko_queue2.QueueTransportFactory.register("memory", (opt) => {
|
|
642
624
|
let transport = new import_neko_queue2.MemoryTransport(opt);
|
|
643
625
|
return new import_neko_queue.QueueConnection(transport);
|
|
644
626
|
});
|
|
@@ -676,8 +658,8 @@ import_neko_storage.StorageProviderFactory.register("s3", (opt) => {
|
|
|
676
658
|
// src/facades.mts
|
|
677
659
|
var import_neko_cache2 = require("@devbro/neko-cache");
|
|
678
660
|
var import_neko_queue3 = require("@devbro/neko-queue");
|
|
679
|
-
var router = (0,
|
|
680
|
-
var scheduler = (0,
|
|
661
|
+
var router = (0, import_neko_helper2.createSingleton)(() => new Router());
|
|
662
|
+
var scheduler = (0, import_neko_helper2.createSingleton)(() => {
|
|
681
663
|
const rc = new import_neko_scheduler.Scheduler();
|
|
682
664
|
rc.setErrorHandler((err, job) => {
|
|
683
665
|
logger().error({
|
|
@@ -689,12 +671,15 @@ var scheduler = (0, import_neko_helper.createSingleton)(() => {
|
|
|
689
671
|
return rc;
|
|
690
672
|
});
|
|
691
673
|
var db = /* @__PURE__ */ __name((label = "default") => (0, import_neko_context2.ctx)().getOrThrow(["database", label]), "db");
|
|
692
|
-
var storage = (0,
|
|
674
|
+
var storage = (0, import_neko_helper2.createSingleton)((label = "default") => {
|
|
693
675
|
let storage_config = import_neko_config.config.get(["storages", label].join("."));
|
|
694
|
-
const provider = import_neko_storage2.StorageProviderFactory.create(
|
|
676
|
+
const provider = import_neko_storage2.StorageProviderFactory.create(
|
|
677
|
+
storage_config.provider,
|
|
678
|
+
storage_config.config
|
|
679
|
+
);
|
|
695
680
|
return new import_neko_storage2.Storage(provider);
|
|
696
681
|
});
|
|
697
|
-
var cli = (0,
|
|
682
|
+
var cli = (0, import_neko_helper2.createSingleton)(() => {
|
|
698
683
|
const [node, app, ...args] = process.argv;
|
|
699
684
|
return new import_clipanion.Cli({
|
|
700
685
|
binaryLabel: `My Application`,
|
|
@@ -702,7 +687,7 @@ var cli = (0, import_neko_helper.createSingleton)(() => {
|
|
|
702
687
|
binaryVersion: `1.0.0`
|
|
703
688
|
});
|
|
704
689
|
});
|
|
705
|
-
var httpServer = (0,
|
|
690
|
+
var httpServer = (0, import_neko_helper2.createSingleton)(() => {
|
|
706
691
|
const server = new http_exports.HttpServer();
|
|
707
692
|
server.setErrorHandler(async (err, req, res) => {
|
|
708
693
|
if (err instanceof http_exports.HttpError) {
|
|
@@ -737,7 +722,7 @@ var httpServer = (0, import_neko_helper.createSingleton)(() => {
|
|
|
737
722
|
server.setRouter(router());
|
|
738
723
|
return server;
|
|
739
724
|
});
|
|
740
|
-
var logger = (0,
|
|
725
|
+
var logger = (0, import_neko_helper2.createSingleton)((label) => {
|
|
741
726
|
const logger_config = import_neko_config.config.get(["loggers", label].join("."));
|
|
742
727
|
const rc = new import_neko_logger.Logger(logger_config);
|
|
743
728
|
rc.setExtrasFunction((message) => {
|
|
@@ -746,25 +731,28 @@ var logger = (0, import_neko_helper.createSingleton)((label) => {
|
|
|
746
731
|
});
|
|
747
732
|
return rc;
|
|
748
733
|
});
|
|
749
|
-
var mailer = (0,
|
|
734
|
+
var mailer = (0, import_neko_helper2.createSingleton)((label) => {
|
|
750
735
|
const mailer_config = import_neko_config.config.get(["mailer", label].join("."));
|
|
751
|
-
const provider =
|
|
736
|
+
const provider = import_neko_mailer2.MailerProviderFactory.create(
|
|
752
737
|
mailer_config.provider,
|
|
753
738
|
mailer_config.config
|
|
754
739
|
);
|
|
755
740
|
const rc = new import_neko_mailer2.Mailer(provider);
|
|
756
741
|
return rc;
|
|
757
742
|
});
|
|
758
|
-
var queue = (0,
|
|
743
|
+
var queue = (0, import_neko_helper2.createSingleton)((label) => {
|
|
759
744
|
const queue_config = import_neko_config.config.get(["queues", label].join("."));
|
|
760
745
|
if (!queue_config) {
|
|
761
746
|
throw new Error(`Queue configuration for '${label}' not found`);
|
|
762
747
|
}
|
|
763
|
-
const provider = QueueTransportFactory.create(
|
|
748
|
+
const provider = import_neko_queue3.QueueTransportFactory.create(
|
|
749
|
+
queue_config.provider,
|
|
750
|
+
queue_config.config
|
|
751
|
+
);
|
|
764
752
|
const rc = new import_neko_queue3.QueueConnection(provider);
|
|
765
753
|
return rc;
|
|
766
754
|
});
|
|
767
|
-
var cache = (0,
|
|
755
|
+
var cache = (0, import_neko_helper2.createSingleton)((label) => {
|
|
768
756
|
const cache_config = import_neko_config.config.get(["caches", label].join("."));
|
|
769
757
|
if (!cache_config) {
|
|
770
758
|
throw new Error(`Cache configuration for '${label}' not found`);
|
package/dist/bin/factories.cjs
CHANGED
|
@@ -33,9 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
var factories_exports = {};
|
|
34
34
|
__export(factories_exports, {
|
|
35
35
|
CacheProviderFactory: () => CacheProviderFactory,
|
|
36
|
-
FlexibleFactory: () => FlexibleFactory
|
|
37
|
-
MailerFactory: () => MailerFactory,
|
|
38
|
-
QueueTransportFactory: () => QueueTransportFactory
|
|
36
|
+
FlexibleFactory: () => FlexibleFactory
|
|
39
37
|
});
|
|
40
38
|
module.exports = __toCommonJS(factories_exports);
|
|
41
39
|
var import_neko_mailer2 = require("@devbro/neko-mailer");
|
|
@@ -489,7 +487,10 @@ var scheduler = (0, import_neko_helper.createSingleton)(() => {
|
|
|
489
487
|
var db = /* @__PURE__ */ __name((label = "default") => (0, import_neko_context2.ctx)().getOrThrow(["database", label]), "db");
|
|
490
488
|
var storage = (0, import_neko_helper.createSingleton)((label = "default") => {
|
|
491
489
|
let storage_config = import_neko_config.config.get(["storages", label].join("."));
|
|
492
|
-
const provider = import_neko_storage.StorageProviderFactory.create(
|
|
490
|
+
const provider = import_neko_storage.StorageProviderFactory.create(
|
|
491
|
+
storage_config.provider,
|
|
492
|
+
storage_config.config
|
|
493
|
+
);
|
|
493
494
|
return new import_neko_storage.Storage(provider);
|
|
494
495
|
});
|
|
495
496
|
var cli = (0, import_neko_helper.createSingleton)(() => {
|
|
@@ -546,7 +547,7 @@ var logger = (0, import_neko_helper.createSingleton)((label) => {
|
|
|
546
547
|
});
|
|
547
548
|
var mailer = (0, import_neko_helper.createSingleton)((label) => {
|
|
548
549
|
const mailer_config = import_neko_config.config.get(["mailer", label].join("."));
|
|
549
|
-
const provider =
|
|
550
|
+
const provider = import_neko_mailer.MailerProviderFactory.create(
|
|
550
551
|
mailer_config.provider,
|
|
551
552
|
mailer_config.config
|
|
552
553
|
);
|
|
@@ -558,7 +559,10 @@ var queue = (0, import_neko_helper.createSingleton)((label) => {
|
|
|
558
559
|
if (!queue_config) {
|
|
559
560
|
throw new Error(`Queue configuration for '${label}' not found`);
|
|
560
561
|
}
|
|
561
|
-
const provider = QueueTransportFactory.create(
|
|
562
|
+
const provider = import_neko_queue.QueueTransportFactory.create(
|
|
563
|
+
queue_config.provider,
|
|
564
|
+
queue_config.config
|
|
565
|
+
);
|
|
562
566
|
const rc = new import_neko_queue.QueueConnection(provider);
|
|
563
567
|
return rc;
|
|
564
568
|
});
|
|
@@ -584,11 +588,11 @@ __export(queue_exports, {
|
|
|
584
588
|
DatabaseTransport: () => DatabaseTransport
|
|
585
589
|
});
|
|
586
590
|
__reExport(queue_exports, require("@devbro/neko-queue"));
|
|
591
|
+
var import_neko_helper2 = require("@devbro/neko-helper");
|
|
587
592
|
var DatabaseTransport = class {
|
|
588
593
|
static {
|
|
589
594
|
__name(this, "DatabaseTransport");
|
|
590
595
|
}
|
|
591
|
-
activeIntervals = /* @__PURE__ */ new Set();
|
|
592
596
|
config = {
|
|
593
597
|
queue_table: "queue_messages",
|
|
594
598
|
db_connection: "default",
|
|
@@ -597,14 +601,48 @@ var DatabaseTransport = class {
|
|
|
597
601
|
message_limit: 10
|
|
598
602
|
// messages per each fetch
|
|
599
603
|
};
|
|
600
|
-
|
|
604
|
+
channels = /* @__PURE__ */ new Map();
|
|
605
|
+
messageQueues = [];
|
|
606
|
+
repeater;
|
|
607
|
+
processMessage = /* @__PURE__ */ __name(async () => {
|
|
608
|
+
const conn = db(this.config.db_connection);
|
|
609
|
+
try {
|
|
610
|
+
await conn.connect();
|
|
611
|
+
let q = conn.getQuery();
|
|
612
|
+
let messages = await q.table(this.config.queue_table).whereOp("channel", "in", Array.from(this.channels.keys())).whereOp("status", "in", ["pending", "failed"]).limit(this.config.message_limit).orderBy("last_tried_at", "asc").get();
|
|
613
|
+
for (let msg of messages) {
|
|
614
|
+
try {
|
|
615
|
+
let callback = this.channels.get(msg.channel);
|
|
616
|
+
await callback(msg.message);
|
|
617
|
+
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
618
|
+
status: "processed",
|
|
619
|
+
updated_at: /* @__PURE__ */ new Date(),
|
|
620
|
+
last_tried_at: /* @__PURE__ */ new Date(),
|
|
621
|
+
retried_count: (msg.retried_count || 0) + 1
|
|
622
|
+
});
|
|
623
|
+
} catch (error) {
|
|
624
|
+
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
625
|
+
status: "failed",
|
|
626
|
+
last_tried_at: /* @__PURE__ */ new Date(),
|
|
627
|
+
retried_count: (msg.retried_count || 0) + 1,
|
|
628
|
+
process_message: error.message || "Error processing message"
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
} catch (error) {
|
|
633
|
+
logger().error("Error in DatabaseTransport listen interval:", {
|
|
634
|
+
error
|
|
635
|
+
});
|
|
636
|
+
} finally {
|
|
637
|
+
await conn.disconnect();
|
|
638
|
+
}
|
|
639
|
+
}, "processMessage");
|
|
640
|
+
constructor(config2 = {}) {
|
|
601
641
|
this.config = { ...this.config, ...config2 };
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
setMessageLimit(limit) {
|
|
607
|
-
this.config.message_limit = limit;
|
|
642
|
+
this.repeater = (0, import_neko_helper2.createRepeater)(
|
|
643
|
+
this.processMessage,
|
|
644
|
+
this.config.listen_interval * 1e3
|
|
645
|
+
);
|
|
608
646
|
}
|
|
609
647
|
async dispatch(channel, message) {
|
|
610
648
|
const conn = db(this.config.db_connection);
|
|
@@ -622,50 +660,22 @@ var DatabaseTransport = class {
|
|
|
622
660
|
created_at: /* @__PURE__ */ new Date(),
|
|
623
661
|
updated_at: /* @__PURE__ */ new Date(),
|
|
624
662
|
last_tried_at: null,
|
|
625
|
-
process_message: ""
|
|
663
|
+
process_message: "",
|
|
664
|
+
retried_count: 0,
|
|
665
|
+
status: "pending"
|
|
626
666
|
});
|
|
627
667
|
} finally {
|
|
628
668
|
await conn.disconnect();
|
|
629
669
|
}
|
|
630
670
|
}
|
|
631
|
-
async
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
await conn.connect();
|
|
637
|
-
let q = conn.getQuery();
|
|
638
|
-
let messages = await q.table(this.config.queue_table).whereOp("channel", "=", channel).whereOp("processed", "=", false).limit(this.config.message_limit).orderBy("last_tried_at", "asc").get();
|
|
639
|
-
for (let msg of messages) {
|
|
640
|
-
try {
|
|
641
|
-
await callback(msg.message);
|
|
642
|
-
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
643
|
-
processed: true,
|
|
644
|
-
updated_at: /* @__PURE__ */ new Date()
|
|
645
|
-
});
|
|
646
|
-
} catch (error) {
|
|
647
|
-
await q.table(this.config.queue_table).whereOp("id", "=", msg.id).update({
|
|
648
|
-
processed: false,
|
|
649
|
-
last_tried_at: /* @__PURE__ */ new Date(),
|
|
650
|
-
process_message: error.message || "Error processing message"
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
} catch (error) {
|
|
655
|
-
this.activeIntervals.delete(intervalId);
|
|
656
|
-
logger().error("Error in DatabaseTransport listen interval:", { error });
|
|
657
|
-
} finally {
|
|
658
|
-
await conn.disconnect();
|
|
659
|
-
}
|
|
660
|
-
}, this.config.listen_interval * 1e3);
|
|
661
|
-
this.activeIntervals.add(intervalId);
|
|
662
|
-
});
|
|
671
|
+
async registerListener(channel, callback) {
|
|
672
|
+
this.channels.set(channel, callback);
|
|
673
|
+
}
|
|
674
|
+
async startListening() {
|
|
675
|
+
this.repeater.start();
|
|
663
676
|
}
|
|
664
677
|
async stopListening() {
|
|
665
|
-
|
|
666
|
-
clearInterval(intervalId);
|
|
667
|
-
}
|
|
668
|
-
this.activeIntervals.clear();
|
|
678
|
+
this.repeater.stop();
|
|
669
679
|
}
|
|
670
680
|
};
|
|
671
681
|
|
|
@@ -688,19 +698,7 @@ var FlexibleFactory = class {
|
|
|
688
698
|
return ctor(...args);
|
|
689
699
|
}
|
|
690
700
|
};
|
|
691
|
-
|
|
692
|
-
static {
|
|
693
|
-
__name(this, "MailerFactory");
|
|
694
|
-
}
|
|
695
|
-
static instance = new FlexibleFactory();
|
|
696
|
-
static register(key, factory) {
|
|
697
|
-
_MailerFactory.instance.register(key, factory);
|
|
698
|
-
}
|
|
699
|
-
static create(key, ...args) {
|
|
700
|
-
return _MailerFactory.instance.create(key, ...args);
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
MailerFactory.register("logger", (opt) => {
|
|
701
|
+
import_neko_mailer2.MailerProviderFactory.register("logger", (opt) => {
|
|
704
702
|
return new import_neko_mailer2.FunctionProvider((mail) => {
|
|
705
703
|
logger().info({
|
|
706
704
|
msg: "Sending email",
|
|
@@ -708,32 +706,20 @@ MailerFactory.register("logger", (opt) => {
|
|
|
708
706
|
});
|
|
709
707
|
});
|
|
710
708
|
});
|
|
711
|
-
|
|
709
|
+
import_neko_mailer2.MailerProviderFactory.register("ses", (opt) => {
|
|
712
710
|
return new import_neko_mailer2.SESProvider(opt);
|
|
713
711
|
});
|
|
714
|
-
|
|
712
|
+
import_neko_mailer2.MailerProviderFactory.register("smtp", (opt) => {
|
|
715
713
|
return new import_neko_mailer2.SMTPProvider(opt);
|
|
716
714
|
});
|
|
717
|
-
|
|
715
|
+
import_neko_mailer2.MailerProviderFactory.register("memory", (opt) => {
|
|
718
716
|
return new import_neko_mailer2.MemoryProvider();
|
|
719
717
|
});
|
|
720
|
-
|
|
721
|
-
static {
|
|
722
|
-
__name(this, "QueueTransportFactory");
|
|
723
|
-
}
|
|
724
|
-
static instance = new FlexibleFactory();
|
|
725
|
-
static register(key, factory) {
|
|
726
|
-
_QueueTransportFactory.instance.register(key, factory);
|
|
727
|
-
}
|
|
728
|
-
static create(key, ...args) {
|
|
729
|
-
return _QueueTransportFactory.instance.create(key, ...args);
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
QueueTransportFactory.register("database", (opt) => {
|
|
718
|
+
import_neko_queue3.QueueTransportFactory.register("database", (opt) => {
|
|
733
719
|
let transport = new DatabaseTransport(opt);
|
|
734
720
|
return new import_neko_queue2.QueueConnection(transport);
|
|
735
721
|
});
|
|
736
|
-
QueueTransportFactory.register("memory", (opt) => {
|
|
722
|
+
import_neko_queue3.QueueTransportFactory.register("memory", (opt) => {
|
|
737
723
|
let transport = new import_neko_queue3.MemoryTransport(opt);
|
|
738
724
|
return new import_neko_queue2.QueueConnection(transport);
|
|
739
725
|
});
|
|
@@ -770,7 +756,5 @@ import_neko_storage2.StorageProviderFactory.register("s3", (opt) => {
|
|
|
770
756
|
// Annotate the CommonJS export names for ESM import in node:
|
|
771
757
|
0 && (module.exports = {
|
|
772
758
|
CacheProviderFactory,
|
|
773
|
-
FlexibleFactory
|
|
774
|
-
MailerFactory,
|
|
775
|
-
QueueTransportFactory
|
|
759
|
+
FlexibleFactory
|
|
776
760
|
});
|