semola 0.5.3 → 0.6.0
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/README.md +18 -45
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/lib/api/index.cjs +536 -4
- package/dist/lib/api/index.d.cts +270 -4
- package/dist/lib/api/index.d.mts +270 -4
- package/dist/lib/api/index.mjs +534 -2
- package/dist/lib/cache/index.cjs +47 -22
- package/dist/lib/cache/index.d.cts +14 -23
- package/dist/lib/cache/index.d.mts +14 -23
- package/dist/lib/cache/index.mjs +48 -25
- package/dist/lib/cron/index.cjs +734 -12
- package/dist/lib/cron/index.d.cts +145 -3
- package/dist/lib/cron/index.d.mts +145 -3
- package/dist/lib/cron/index.mjs +725 -3
- package/dist/lib/errors/index.d.cts +4 -4
- package/dist/lib/errors/index.d.mts +4 -4
- package/dist/lib/errors/index.mjs +0 -2
- package/dist/lib/i18n/index.d.cts +12 -4
- package/dist/lib/i18n/index.d.mts +12 -4
- package/dist/lib/i18n/index.mjs +0 -2
- package/dist/lib/logging/index.cjs +387 -17
- package/dist/lib/logging/index.d.cts +107 -6
- package/dist/lib/logging/index.d.mts +107 -6
- package/dist/lib/logging/index.mjs +373 -4
- package/dist/lib/orm/index.cjs +1641 -19
- package/dist/lib/orm/index.d.cts +402 -7
- package/dist/lib/orm/index.d.mts +402 -7
- package/dist/lib/orm/index.mjs +1630 -6
- package/dist/lib/policy/index.cjs +206 -20
- package/dist/lib/policy/index.d.cts +61 -5
- package/dist/lib/policy/index.d.mts +61 -5
- package/dist/lib/policy/index.mjs +187 -3
- package/dist/lib/prompts/index.cjs +374 -14
- package/dist/lib/prompts/index.d.cts +73 -29
- package/dist/lib/prompts/index.d.mts +73 -29
- package/dist/lib/prompts/index.mjs +361 -4
- package/dist/lib/pubsub/index.cjs +43 -19
- package/dist/lib/pubsub/index.d.cts +12 -22
- package/dist/lib/pubsub/index.d.mts +12 -22
- package/dist/lib/pubsub/index.mjs +44 -22
- package/dist/lib/queue/index.cjs +40 -10
- package/dist/lib/queue/index.d.cts +57 -8
- package/dist/lib/queue/index.d.mts +57 -8
- package/dist/lib/queue/index.mjs +39 -13
- package/dist/lib/workflow/index.cjs +285 -282
- package/dist/lib/workflow/index.d.cts +147 -4
- package/dist/lib/workflow/index.d.mts +147 -4
- package/dist/lib/workflow/index.mjs +278 -286
- package/package.json +11 -1
- package/dist/api/core/index.cjs +0 -206
- package/dist/api/core/index.d.cts +0 -21
- package/dist/api/core/index.d.cts.map +0 -1
- package/dist/api/core/index.d.mts +0 -21
- package/dist/api/core/index.d.mts.map +0 -1
- package/dist/api/core/index.mjs +0 -208
- package/dist/api/core/index.mjs.map +0 -1
- package/dist/api/core/types.d.cts +0 -107
- package/dist/api/core/types.d.cts.map +0 -1
- package/dist/api/core/types.d.mts +0 -107
- package/dist/api/core/types.d.mts.map +0 -1
- package/dist/api/middleware/index.cjs +0 -8
- package/dist/api/middleware/index.d.cts +0 -11
- package/dist/api/middleware/index.d.cts.map +0 -1
- package/dist/api/middleware/index.d.mts +0 -11
- package/dist/api/middleware/index.d.mts.map +0 -1
- package/dist/api/middleware/index.mjs +0 -10
- package/dist/api/middleware/index.mjs.map +0 -1
- package/dist/api/middleware/types.d.cts +0 -16
- package/dist/api/middleware/types.d.cts.map +0 -1
- package/dist/api/middleware/types.d.mts +0 -16
- package/dist/api/middleware/types.d.mts.map +0 -1
- package/dist/api/openapi/index.cjs +0 -254
- package/dist/api/openapi/index.mjs +0 -256
- package/dist/api/openapi/index.mjs.map +0 -1
- package/dist/api/openapi/types.d.cts +0 -60
- package/dist/api/openapi/types.d.cts.map +0 -1
- package/dist/api/openapi/types.d.mts +0 -60
- package/dist/api/openapi/types.d.mts.map +0 -1
- package/dist/api/validation/index.cjs +0 -64
- package/dist/api/validation/index.mjs +0 -61
- package/dist/api/validation/index.mjs.map +0 -1
- package/dist/cache/types.d.cts +0 -17
- package/dist/cache/types.d.cts.map +0 -1
- package/dist/cache/types.d.mts +0 -17
- package/dist/cache/types.d.mts.map +0 -1
- package/dist/cron/builder/index.cjs +0 -166
- package/dist/cron/builder/index.d.cts +0 -28
- package/dist/cron/builder/index.d.cts.map +0 -1
- package/dist/cron/builder/index.d.mts +0 -28
- package/dist/cron/builder/index.d.mts.map +0 -1
- package/dist/cron/builder/index.mjs +0 -163
- package/dist/cron/builder/index.mjs.map +0 -1
- package/dist/cron/builder/types.cjs +0 -27
- package/dist/cron/builder/types.d.cts +0 -79
- package/dist/cron/builder/types.d.cts.map +0 -1
- package/dist/cron/builder/types.d.mts +0 -79
- package/dist/cron/builder/types.d.mts.map +0 -1
- package/dist/cron/builder/types.mjs +0 -28
- package/dist/cron/builder/types.mjs.map +0 -1
- package/dist/cron/core/index.cjs +0 -308
- package/dist/cron/core/index.d.cts +0 -39
- package/dist/cron/core/index.d.cts.map +0 -1
- package/dist/cron/core/index.d.mts +0 -39
- package/dist/cron/core/index.d.mts.map +0 -1
- package/dist/cron/core/index.mjs +0 -310
- package/dist/cron/core/index.mjs.map +0 -1
- package/dist/cron/core/scanner.cjs +0 -237
- package/dist/cron/core/scanner.mjs +0 -238
- package/dist/cron/core/scanner.mjs.map +0 -1
- package/dist/cron/core/types.d.cts +0 -11
- package/dist/cron/core/types.d.cts.map +0 -1
- package/dist/cron/core/types.d.mts +0 -11
- package/dist/cron/core/types.d.mts.map +0 -1
- package/dist/errors/types.d.cts +0 -5
- package/dist/errors/types.d.cts.map +0 -1
- package/dist/errors/types.d.mts +0 -5
- package/dist/errors/types.d.mts.map +0 -1
- package/dist/i18n/types.d.cts +0 -13
- package/dist/i18n/types.d.cts.map +0 -1
- package/dist/i18n/types.d.mts +0 -13
- package/dist/i18n/types.d.mts.map +0 -1
- package/dist/lib/cache/index.d.cts.map +0 -1
- package/dist/lib/cache/index.d.mts.map +0 -1
- package/dist/lib/cache/index.mjs.map +0 -1
- package/dist/lib/errors/index.d.cts.map +0 -1
- package/dist/lib/errors/index.d.mts.map +0 -1
- package/dist/lib/errors/index.mjs.map +0 -1
- package/dist/lib/i18n/index.d.cts.map +0 -1
- package/dist/lib/i18n/index.d.mts.map +0 -1
- package/dist/lib/i18n/index.mjs.map +0 -1
- package/dist/lib/policy/index.d.cts.map +0 -1
- package/dist/lib/policy/index.d.mts.map +0 -1
- package/dist/lib/policy/index.mjs.map +0 -1
- package/dist/lib/prompts/index.d.cts.map +0 -1
- package/dist/lib/prompts/index.d.mts.map +0 -1
- package/dist/lib/prompts/index.mjs.map +0 -1
- package/dist/lib/pubsub/index.d.cts.map +0 -1
- package/dist/lib/pubsub/index.d.mts.map +0 -1
- package/dist/lib/pubsub/index.mjs.map +0 -1
- package/dist/lib/queue/index.d.cts.map +0 -1
- package/dist/lib/queue/index.d.mts.map +0 -1
- package/dist/lib/queue/index.mjs.map +0 -1
- package/dist/lib/workflow/index.d.cts.map +0 -1
- package/dist/lib/workflow/index.d.mts.map +0 -1
- package/dist/lib/workflow/index.mjs.map +0 -1
- package/dist/logging/core/index.cjs +0 -99
- package/dist/logging/core/index.d.cts +0 -26
- package/dist/logging/core/index.d.cts.map +0 -1
- package/dist/logging/core/index.d.mts +0 -26
- package/dist/logging/core/index.d.mts.map +0 -1
- package/dist/logging/core/index.mjs +0 -99
- package/dist/logging/core/index.mjs.map +0 -1
- package/dist/logging/core/types.cjs +0 -10
- package/dist/logging/core/types.d.cts +0 -22
- package/dist/logging/core/types.d.cts.map +0 -1
- package/dist/logging/core/types.d.mts +0 -22
- package/dist/logging/core/types.d.mts.map +0 -1
- package/dist/logging/core/types.mjs +0 -12
- package/dist/logging/core/types.mjs.map +0 -1
- package/dist/logging/formatter/index.cjs +0 -119
- package/dist/logging/formatter/index.d.cts +0 -27
- package/dist/logging/formatter/index.d.cts.map +0 -1
- package/dist/logging/formatter/index.d.mts +0 -27
- package/dist/logging/formatter/index.d.mts.map +0 -1
- package/dist/logging/formatter/index.mjs +0 -115
- package/dist/logging/formatter/index.mjs.map +0 -1
- package/dist/logging/formatter/types.d.cts +0 -5
- package/dist/logging/formatter/types.d.cts.map +0 -1
- package/dist/logging/formatter/types.d.mts +0 -5
- package/dist/logging/formatter/types.d.mts.map +0 -1
- package/dist/logging/provider/index.cjs +0 -165
- package/dist/logging/provider/index.d.cts +0 -28
- package/dist/logging/provider/index.d.cts.map +0 -1
- package/dist/logging/provider/index.d.mts +0 -28
- package/dist/logging/provider/index.d.mts.map +0 -1
- package/dist/logging/provider/index.mjs +0 -165
- package/dist/logging/provider/index.mjs.map +0 -1
- package/dist/logging/provider/types.d.cts +0 -23
- package/dist/logging/provider/types.d.cts.map +0 -1
- package/dist/logging/provider/types.d.mts +0 -23
- package/dist/logging/provider/types.d.mts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
- package/dist/orm/column.cjs +0 -137
- package/dist/orm/column.d.cts +0 -121
- package/dist/orm/column.d.cts.map +0 -1
- package/dist/orm/column.d.mts +0 -121
- package/dist/orm/column.d.mts.map +0 -1
- package/dist/orm/column.mjs +0 -132
- package/dist/orm/column.mjs.map +0 -1
- package/dist/orm/dialect/index.cjs +0 -14
- package/dist/orm/dialect/index.mjs +0 -16
- package/dist/orm/dialect/index.mjs.map +0 -1
- package/dist/orm/dialect/mysql.cjs +0 -31
- package/dist/orm/dialect/mysql.mjs +0 -33
- package/dist/orm/dialect/mysql.mjs.map +0 -1
- package/dist/orm/dialect/postgres.cjs +0 -23
- package/dist/orm/dialect/postgres.mjs +0 -25
- package/dist/orm/dialect/postgres.mjs.map +0 -1
- package/dist/orm/dialect/sqlite.cjs +0 -31
- package/dist/orm/dialect/sqlite.mjs +0 -33
- package/dist/orm/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/dialect/utils.cjs +0 -8
- package/dist/orm/dialect/utils.mjs +0 -10
- package/dist/orm/dialect/utils.mjs.map +0 -1
- package/dist/orm/internal/table-columns.cjs +0 -31
- package/dist/orm/internal/table-columns.mjs +0 -32
- package/dist/orm/internal/table-columns.mjs.map +0 -1
- package/dist/orm/internal/table-lookup.cjs +0 -35
- package/dist/orm/internal/table-lookup.mjs +0 -35
- package/dist/orm/internal/table-lookup.mjs.map +0 -1
- package/dist/orm/internal/table-relations.cjs +0 -28
- package/dist/orm/internal/table-relations.mjs +0 -29
- package/dist/orm/internal/table-relations.mjs.map +0 -1
- package/dist/orm/migration/config.cjs +0 -7
- package/dist/orm/migration/config.d.cts +0 -7
- package/dist/orm/migration/config.d.cts.map +0 -1
- package/dist/orm/migration/config.d.mts +0 -7
- package/dist/orm/migration/config.d.mts.map +0 -1
- package/dist/orm/migration/config.mjs +0 -8
- package/dist/orm/migration/config.mjs.map +0 -1
- package/dist/orm/migration/types.d.cts +0 -20
- package/dist/orm/migration/types.d.cts.map +0 -1
- package/dist/orm/migration/types.d.mts +0 -20
- package/dist/orm/migration/types.d.mts.map +0 -1
- package/dist/orm/orm.cjs +0 -41
- package/dist/orm/orm.d.cts +0 -18
- package/dist/orm/orm.d.cts.map +0 -1
- package/dist/orm/orm.d.mts +0 -18
- package/dist/orm/orm.d.mts.map +0 -1
- package/dist/orm/orm.mjs +0 -43
- package/dist/orm/orm.mjs.map +0 -1
- package/dist/orm/relation.cjs +0 -18
- package/dist/orm/relation.d.cts +0 -8
- package/dist/orm/relation.d.cts.map +0 -1
- package/dist/orm/relation.d.mts +0 -8
- package/dist/orm/relation.d.mts.map +0 -1
- package/dist/orm/relation.mjs +0 -19
- package/dist/orm/relation.mjs.map +0 -1
- package/dist/orm/runtime/builders/mutations.cjs +0 -29
- package/dist/orm/runtime/builders/mutations.mjs +0 -28
- package/dist/orm/runtime/builders/mutations.mjs.map +0 -1
- package/dist/orm/runtime/builders/select.cjs +0 -18
- package/dist/orm/runtime/builders/select.mjs +0 -19
- package/dist/orm/runtime/builders/select.mjs.map +0 -1
- package/dist/orm/runtime/client.cjs +0 -90
- package/dist/orm/runtime/client.mjs +0 -92
- package/dist/orm/runtime/client.mjs.map +0 -1
- package/dist/orm/runtime/context.cjs +0 -49
- package/dist/orm/runtime/context.mjs +0 -51
- package/dist/orm/runtime/context.mjs.map +0 -1
- package/dist/orm/runtime/dialect/index.cjs +0 -11
- package/dist/orm/runtime/dialect/index.mjs +0 -13
- package/dist/orm/runtime/dialect/index.mjs.map +0 -1
- package/dist/orm/runtime/dialect/mysql.cjs +0 -95
- package/dist/orm/runtime/dialect/mysql.mjs +0 -97
- package/dist/orm/runtime/dialect/mysql.mjs.map +0 -1
- package/dist/orm/runtime/dialect/postgres.cjs +0 -51
- package/dist/orm/runtime/dialect/postgres.mjs +0 -53
- package/dist/orm/runtime/dialect/postgres.mjs.map +0 -1
- package/dist/orm/runtime/dialect/sqlite.cjs +0 -4
- package/dist/orm/runtime/dialect/sqlite.mjs +0 -7
- package/dist/orm/runtime/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/runtime/errors.cjs +0 -19
- package/dist/orm/runtime/errors.mjs +0 -21
- package/dist/orm/runtime/errors.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/many.cjs +0 -46
- package/dist/orm/runtime/hydrate/many.mjs +0 -48
- package/dist/orm/runtime/hydrate/many.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/one.cjs +0 -38
- package/dist/orm/runtime/hydrate/one.mjs +0 -40
- package/dist/orm/runtime/hydrate/one.mjs.map +0 -1
- package/dist/orm/runtime/hydrate.cjs +0 -49
- package/dist/orm/runtime/hydrate.mjs +0 -51
- package/dist/orm/runtime/hydrate.mjs.map +0 -1
- package/dist/orm/runtime/rows.cjs +0 -30
- package/dist/orm/runtime/rows.mjs +0 -31
- package/dist/orm/runtime/rows.mjs.map +0 -1
- package/dist/orm/runtime/utils.cjs +0 -27
- package/dist/orm/runtime/utils.mjs +0 -27
- package/dist/orm/runtime/utils.mjs.map +0 -1
- package/dist/orm/sql/parse-array.cjs +0 -64
- package/dist/orm/sql/parse-array.mjs +0 -66
- package/dist/orm/sql/parse-array.mjs.map +0 -1
- package/dist/orm/sql/plan/select.cjs +0 -36
- package/dist/orm/sql/plan/select.mjs +0 -38
- package/dist/orm/sql/plan/select.mjs.map +0 -1
- package/dist/orm/sql/plan/where/operators.cjs +0 -95
- package/dist/orm/sql/plan/where/operators.mjs +0 -97
- package/dist/orm/sql/plan/where/operators.mjs.map +0 -1
- package/dist/orm/sql/plan/where.cjs +0 -59
- package/dist/orm/sql/plan/where.mjs +0 -61
- package/dist/orm/sql/plan/where.mjs.map +0 -1
- package/dist/orm/sql/serialize/clauses.cjs +0 -36
- package/dist/orm/sql/serialize/clauses.mjs +0 -37
- package/dist/orm/sql/serialize/clauses.mjs.map +0 -1
- package/dist/orm/sql/serialize/joins.cjs +0 -31
- package/dist/orm/sql/serialize/joins.mjs +0 -33
- package/dist/orm/sql/serialize/joins.mjs.map +0 -1
- package/dist/orm/sql/serialize/values.cjs +0 -30
- package/dist/orm/sql/serialize/values.mjs +0 -32
- package/dist/orm/sql/serialize/values.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/predicate.cjs +0 -73
- package/dist/orm/sql/serialize/where/predicate.mjs +0 -75
- package/dist/orm/sql/serialize/where/predicate.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/tree.cjs +0 -26
- package/dist/orm/sql/serialize/where/tree.mjs +0 -28
- package/dist/orm/sql/serialize/where/tree.mjs.map +0 -1
- package/dist/orm/sql/serialize/where.cjs +0 -10
- package/dist/orm/sql/serialize/where.mjs +0 -12
- package/dist/orm/sql/serialize/where.mjs.map +0 -1
- package/dist/orm/sql/serialize.cjs +0 -24
- package/dist/orm/sql/serialize.mjs +0 -25
- package/dist/orm/sql/serialize.mjs.map +0 -1
- package/dist/orm/table.cjs +0 -12
- package/dist/orm/table.d.cts +0 -12
- package/dist/orm/table.d.cts.map +0 -1
- package/dist/orm/table.d.mts +0 -12
- package/dist/orm/table.d.mts.map +0 -1
- package/dist/orm/table.mjs +0 -14
- package/dist/orm/table.mjs.map +0 -1
- package/dist/orm/types.d.cts +0 -183
- package/dist/orm/types.d.cts.map +0 -1
- package/dist/orm/types.d.mts +0 -183
- package/dist/orm/types.d.mts.map +0 -1
- package/dist/policy/helpers.cjs +0 -206
- package/dist/policy/helpers.d.cts +0 -50
- package/dist/policy/helpers.d.cts.map +0 -1
- package/dist/policy/helpers.d.mts +0 -50
- package/dist/policy/helpers.d.mts.map +0 -1
- package/dist/policy/helpers.mjs +0 -190
- package/dist/policy/helpers.mjs.map +0 -1
- package/dist/policy/types.d.cts +0 -16
- package/dist/policy/types.d.cts.map +0 -1
- package/dist/policy/types.d.mts +0 -16
- package/dist/policy/types.d.mts.map +0 -1
- package/dist/prompts/core/keys.cjs +0 -165
- package/dist/prompts/core/keys.mjs +0 -167
- package/dist/prompts/core/keys.mjs.map +0 -1
- package/dist/prompts/core/runtime.cjs +0 -104
- package/dist/prompts/core/runtime.mjs +0 -106
- package/dist/prompts/core/runtime.mjs.map +0 -1
- package/dist/prompts/core/session.cjs +0 -98
- package/dist/prompts/core/session.mjs +0 -100
- package/dist/prompts/core/session.mjs.map +0 -1
- package/dist/prompts/core/types.d.cts +0 -21
- package/dist/prompts/core/types.d.cts.map +0 -1
- package/dist/prompts/core/types.d.mts +0 -21
- package/dist/prompts/core/types.d.mts.map +0 -1
- package/dist/prompts/types.d.cts +0 -52
- package/dist/prompts/types.d.cts.map +0 -1
- package/dist/prompts/types.d.mts +0 -52
- package/dist/prompts/types.d.mts.map +0 -1
- package/dist/pubsub/types.d.cts +0 -10
- package/dist/pubsub/types.d.cts.map +0 -1
- package/dist/pubsub/types.d.mts +0 -10
- package/dist/pubsub/types.d.mts.map +0 -1
- package/dist/queue/types.d.cts +0 -47
- package/dist/queue/types.d.cts.map +0 -1
- package/dist/queue/types.d.mts +0 -47
- package/dist/queue/types.d.mts.map +0 -1
- package/dist/workflow/types.d.cts +0 -83
- package/dist/workflow/types.d.cts.map +0 -1
- package/dist/workflow/types.d.mts +0 -83
- package/dist/workflow/types.d.mts.map +0 -1
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mightThrow, mightThrowSync } from "../errors/index.mjs";
|
|
2
|
+
//#region src/lib/pubsub/errors.ts
|
|
3
|
+
var UnsubscribeError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "UnsubscribeError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var SerializationError = class extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "SerializationError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var PublishError = class extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "PublishError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var SubscribeError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "SubscribeError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
2
28
|
//#region src/lib/pubsub/index.ts
|
|
3
29
|
var PubSub = class {
|
|
4
30
|
options;
|
|
@@ -21,33 +47,32 @@ var PubSub = class {
|
|
|
21
47
|
const inFlightUnsubscribe = this.unsubscribeInFlight;
|
|
22
48
|
if (inFlightUnsubscribe) await inFlightUnsubscribe;
|
|
23
49
|
const handler = this.handlers.get(handlerId);
|
|
24
|
-
if (!handler)
|
|
50
|
+
if (!handler) throw new UnsubscribeError("Not subscribed");
|
|
25
51
|
this.handlers.delete(handlerId);
|
|
26
|
-
if (this.handlers.size > 0) return
|
|
52
|
+
if (this.handlers.size > 0) return;
|
|
27
53
|
this.isSubscribed = false;
|
|
28
54
|
this.unsubscribeInFlight = mightThrow(this.options.subscriber.unsubscribe(this.options.channel));
|
|
29
55
|
const unsubscribeInFlight = this.unsubscribeInFlight;
|
|
30
56
|
if (!unsubscribeInFlight) {
|
|
31
57
|
this.handlers.set(handlerId, handler);
|
|
32
58
|
this.isSubscribed = true;
|
|
33
|
-
|
|
59
|
+
throw new UnsubscribeError(`Unable to unsubscribe from ${this.options.channel}`);
|
|
34
60
|
}
|
|
35
61
|
const [unsubscribeError] = await unsubscribeInFlight;
|
|
36
62
|
if (unsubscribeError) {
|
|
37
63
|
this.handlers.set(handlerId, handler);
|
|
38
64
|
this.isSubscribed = true;
|
|
39
65
|
this.unsubscribeInFlight = null;
|
|
40
|
-
|
|
66
|
+
throw new UnsubscribeError(`Unable to unsubscribe from ${this.options.channel}`);
|
|
41
67
|
}
|
|
42
68
|
this.unsubscribeInFlight = null;
|
|
43
|
-
return ok(true);
|
|
44
69
|
}
|
|
45
70
|
async publish(message) {
|
|
46
71
|
const [stringifyError, stringified] = mightThrowSync(() => JSON.stringify(message));
|
|
47
|
-
if (stringifyError || !stringified)
|
|
72
|
+
if (stringifyError || !stringified) throw new SerializationError("Unable to serialize message");
|
|
48
73
|
const [publishError, count] = await mightThrow(this.options.publisher.publish(this.options.channel, stringified));
|
|
49
|
-
if (publishError)
|
|
50
|
-
return
|
|
74
|
+
if (publishError) throw new PublishError(`Unable to publish to ${this.options.channel}`);
|
|
75
|
+
return count;
|
|
51
76
|
}
|
|
52
77
|
async subscribe(handler) {
|
|
53
78
|
const inFlightUnsubscribe = this.unsubscribeInFlight;
|
|
@@ -55,39 +80,39 @@ var PubSub = class {
|
|
|
55
80
|
const handlerId = this.nextHandlerId;
|
|
56
81
|
this.nextHandlerId += 1;
|
|
57
82
|
this.handlers.set(handlerId, handler);
|
|
58
|
-
if (this.isActive()) return
|
|
83
|
+
if (this.isActive()) return () => this.unsubscribeHandler(handlerId);
|
|
59
84
|
const inFlightSubscribe = this.subscribeInFlight;
|
|
60
85
|
if (inFlightSubscribe) {
|
|
61
86
|
const [inFlightError] = await inFlightSubscribe;
|
|
62
87
|
if (inFlightError || !this.isSubscribed) {
|
|
63
88
|
this.handlers.delete(handlerId);
|
|
64
|
-
|
|
89
|
+
throw new SubscribeError(`Unable to subscribe to ${this.options.channel}`);
|
|
65
90
|
}
|
|
66
|
-
return
|
|
91
|
+
return () => this.unsubscribeHandler(handlerId);
|
|
67
92
|
}
|
|
68
93
|
this.subscribeInFlight = mightThrow(this.options.subscriber.subscribe(this.options.channel, async (message, channel) => this.onMessage(message, channel)));
|
|
69
94
|
const subscribeInFlight = this.subscribeInFlight;
|
|
70
95
|
if (!subscribeInFlight) {
|
|
71
96
|
this.handlers.delete(handlerId);
|
|
72
|
-
|
|
97
|
+
throw new SubscribeError(`Unable to subscribe to ${this.options.channel}`);
|
|
73
98
|
}
|
|
74
99
|
const [subscribeError, count] = await subscribeInFlight;
|
|
75
100
|
this.subscribeInFlight = null;
|
|
76
101
|
if (subscribeError) {
|
|
77
102
|
this.handlers.delete(handlerId);
|
|
78
|
-
|
|
103
|
+
throw new SubscribeError(`Unable to subscribe to ${this.options.channel}`);
|
|
79
104
|
}
|
|
80
105
|
if (!count) {
|
|
81
106
|
this.handlers.delete(handlerId);
|
|
82
|
-
|
|
107
|
+
throw new SubscribeError(`Unable to subscribe to ${this.options.channel}`);
|
|
83
108
|
}
|
|
84
109
|
this.isSubscribed = true;
|
|
85
|
-
return
|
|
110
|
+
return () => this.unsubscribeHandler(handlerId);
|
|
86
111
|
}
|
|
87
112
|
async unsubscribe() {
|
|
88
113
|
const inFlightUnsubscribe = this.unsubscribeInFlight;
|
|
89
114
|
if (inFlightUnsubscribe) await inFlightUnsubscribe;
|
|
90
|
-
if (!this.isActive())
|
|
115
|
+
if (!this.isActive()) throw new UnsubscribeError("Not subscribed");
|
|
91
116
|
const handlers = new Map(this.handlers);
|
|
92
117
|
this.handlers.clear();
|
|
93
118
|
this.isSubscribed = false;
|
|
@@ -96,17 +121,16 @@ var PubSub = class {
|
|
|
96
121
|
if (!unsubscribeInFlight) {
|
|
97
122
|
this.handlers = handlers;
|
|
98
123
|
this.isSubscribed = true;
|
|
99
|
-
|
|
124
|
+
throw new UnsubscribeError(`Unable to unsubscribe from ${this.options.channel}`);
|
|
100
125
|
}
|
|
101
126
|
const [unsubscribeError] = await unsubscribeInFlight;
|
|
102
127
|
if (unsubscribeError) {
|
|
103
128
|
this.handlers = handlers;
|
|
104
129
|
this.isSubscribed = true;
|
|
105
130
|
this.unsubscribeInFlight = null;
|
|
106
|
-
|
|
131
|
+
throw new UnsubscribeError(`Unable to unsubscribe from ${this.options.channel}`);
|
|
107
132
|
}
|
|
108
133
|
this.unsubscribeInFlight = null;
|
|
109
|
-
return ok(true);
|
|
110
134
|
}
|
|
111
135
|
isActive() {
|
|
112
136
|
return this.handlers.size > 0 && this.isSubscribed;
|
|
@@ -114,5 +138,3 @@ var PubSub = class {
|
|
|
114
138
|
};
|
|
115
139
|
//#endregion
|
|
116
140
|
export { PubSub };
|
|
117
|
-
|
|
118
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/lib/queue/index.cjs
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("../../chunk-CKQMccvm.cjs");
|
|
2
3
|
const require_lib_errors_index = require("../errors/index.cjs");
|
|
4
|
+
let node_assert = require("node:assert");
|
|
5
|
+
node_assert = require_chunk.__toESM(node_assert);
|
|
6
|
+
//#region src/lib/queue/errors.ts
|
|
7
|
+
var SerializationError = class extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "SerializationError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var EnqueueError = class extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "EnqueueError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
3
20
|
//#region src/lib/queue/index.ts
|
|
4
21
|
const toMinimalJob = (jobState) => ({
|
|
5
22
|
id: jobState.id,
|
|
@@ -12,9 +29,9 @@ const DEFAULT_RETRIES = 3;
|
|
|
12
29
|
const DEFAULT_TIMEOUT = 3e4;
|
|
13
30
|
const DEFAULT_CONCURRENCY = 1;
|
|
14
31
|
const DEFAULT_POLL_INTERVAL = 100;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
32
|
+
const DEFAULT_RETRY_MAX_DELAY = 6e4;
|
|
33
|
+
const DEFAULT_RETRY_BASE_DELAY = 1e3;
|
|
34
|
+
const DEFAULT_RETRY_MULTIPLIER = 2;
|
|
18
35
|
const SHUTDOWN_POLL_INTERVAL = 10;
|
|
19
36
|
var Queue = class {
|
|
20
37
|
options;
|
|
@@ -24,14 +41,26 @@ var Queue = class {
|
|
|
24
41
|
timeout;
|
|
25
42
|
concurrency;
|
|
26
43
|
pollInterval;
|
|
44
|
+
retryBaseDelay;
|
|
45
|
+
retryMultiplier;
|
|
46
|
+
retryMaxDelay;
|
|
27
47
|
constructor(options) {
|
|
28
48
|
this.options = options;
|
|
29
49
|
this.retries = options.retries ?? DEFAULT_RETRIES;
|
|
30
50
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
31
51
|
this.concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
32
52
|
this.pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
53
|
+
this.retryBaseDelay = options.retryBackoff?.baseDelay ?? DEFAULT_RETRY_BASE_DELAY;
|
|
54
|
+
this.retryMultiplier = options.retryBackoff?.multiplier ?? DEFAULT_RETRY_MULTIPLIER;
|
|
55
|
+
this.retryMaxDelay = options.retryBackoff?.maxDelay ?? DEFAULT_RETRY_MAX_DELAY;
|
|
56
|
+
node_assert.default.ok(Number.isFinite(this.retryBaseDelay) && this.retryBaseDelay > 0, "Invalid retryBackoff.baseDelay: must be a positive finite number");
|
|
57
|
+
node_assert.default.ok(Number.isFinite(this.retryMultiplier) && this.retryMultiplier > 0, "Invalid retryBackoff.multiplier: must be a positive finite number");
|
|
58
|
+
node_assert.default.ok(Number.isFinite(this.retryMaxDelay) && this.retryMaxDelay > 0, "Invalid retryBackoff.maxDelay: must be a positive finite number");
|
|
33
59
|
this.startWorkers();
|
|
34
60
|
}
|
|
61
|
+
computeBackoffDelay(attempt) {
|
|
62
|
+
return Math.min(this.retryBaseDelay * this.retryMultiplier ** (attempt - 1), this.retryMaxDelay);
|
|
63
|
+
}
|
|
35
64
|
async enqueue(data) {
|
|
36
65
|
const job = {
|
|
37
66
|
id: crypto.randomUUID(),
|
|
@@ -41,10 +70,10 @@ var Queue = class {
|
|
|
41
70
|
createdAt: Date.now()
|
|
42
71
|
};
|
|
43
72
|
const [serializeError, serialized] = this.serializeJob(job);
|
|
44
|
-
if (serializeError || !serialized)
|
|
73
|
+
if (serializeError || !serialized) throw new SerializationError("Unable to serialize job data");
|
|
45
74
|
const [enqueueError] = await this.enqueueJobData(serialized);
|
|
46
|
-
if (enqueueError)
|
|
47
|
-
return
|
|
75
|
+
if (enqueueError) throw new EnqueueError("Unable to enqueue job");
|
|
76
|
+
return job.id;
|
|
48
77
|
}
|
|
49
78
|
async stop() {
|
|
50
79
|
this.running = false;
|
|
@@ -70,7 +99,8 @@ var Queue = class {
|
|
|
70
99
|
return require_lib_errors_index.mightThrow(this.options.redis.lpush(deadLetterKey, deadLetterEntry));
|
|
71
100
|
}
|
|
72
101
|
formatErrorMessage(error) {
|
|
73
|
-
|
|
102
|
+
if (!error) return "Unknown error";
|
|
103
|
+
return error.message;
|
|
74
104
|
}
|
|
75
105
|
startWorkers() {
|
|
76
106
|
for (let i = 0; i < this.concurrency; i++) this.processJobs();
|
|
@@ -131,13 +161,13 @@ var Queue = class {
|
|
|
131
161
|
});
|
|
132
162
|
if (job.attempts <= job.maxRetries) {
|
|
133
163
|
if (this.options.onRetry) {
|
|
134
|
-
const delay =
|
|
164
|
+
const delay = this.computeBackoffDelay(job.attempts);
|
|
135
165
|
await require_lib_errors_index.mightThrow(Promise.resolve(this.options.onRetry({
|
|
136
166
|
job: toMinimalJob(job),
|
|
137
167
|
error: errorMsg,
|
|
138
168
|
nextRetryDelayMs: delay,
|
|
139
169
|
retriesRemaining: job.maxRetries - job.attempts,
|
|
140
|
-
backoffMultiplier:
|
|
170
|
+
backoffMultiplier: this.retryMultiplier
|
|
141
171
|
})));
|
|
142
172
|
}
|
|
143
173
|
await this.retryJob(job);
|
|
@@ -162,7 +192,7 @@ var Queue = class {
|
|
|
162
192
|
})));
|
|
163
193
|
}
|
|
164
194
|
async retryJob(job) {
|
|
165
|
-
const delay =
|
|
195
|
+
const delay = this.computeBackoffDelay(job.attempts);
|
|
166
196
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
167
197
|
const [stringifyError, serialized] = this.serializeJob(job);
|
|
168
198
|
if (stringifyError || !serialized) {
|
|
@@ -1,5 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/lib/queue/types.d.ts
|
|
2
|
+
type Job<T> = {
|
|
3
|
+
id: string;
|
|
4
|
+
data: T;
|
|
5
|
+
attempts: number;
|
|
6
|
+
maxRetries: number;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
};
|
|
9
|
+
type RetryContext<T> = {
|
|
10
|
+
job: Job<T>;
|
|
11
|
+
error: string;
|
|
12
|
+
nextRetryDelayMs: number;
|
|
13
|
+
retriesRemaining: number;
|
|
14
|
+
backoffMultiplier: number;
|
|
15
|
+
};
|
|
16
|
+
type ErrorContext<T> = {
|
|
17
|
+
job: Job<T>;
|
|
18
|
+
lastError: string;
|
|
19
|
+
totalDurationMs: number;
|
|
20
|
+
totalAttempts: number;
|
|
21
|
+
errorHistory: Array<{
|
|
22
|
+
attempt: number;
|
|
23
|
+
error: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
type ParseErrorContext = {
|
|
28
|
+
rawJobData: string;
|
|
29
|
+
parseError: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
};
|
|
32
|
+
type QueueRetryBackoff = {
|
|
33
|
+
baseDelay?: number;
|
|
34
|
+
multiplier?: number;
|
|
35
|
+
maxDelay?: number;
|
|
36
|
+
};
|
|
37
|
+
type QueueOptions<T> = {
|
|
38
|
+
name: string;
|
|
39
|
+
redis: Bun.RedisClient;
|
|
40
|
+
handler: (data: T, signal?: AbortSignal) => void | Promise<void>;
|
|
41
|
+
onSuccess?: (job: Job<T>) => void | Promise<void>;
|
|
42
|
+
onRetry?: (context: RetryContext<T>) => void | Promise<void>;
|
|
43
|
+
onError?: (context: ErrorContext<T>) => void | Promise<void>;
|
|
44
|
+
onParseError?: (context: ParseErrorContext) => void | Promise<void>;
|
|
45
|
+
retries?: number;
|
|
46
|
+
retryBackoff?: QueueRetryBackoff;
|
|
47
|
+
timeout?: number;
|
|
48
|
+
concurrency?: number;
|
|
49
|
+
pollInterval?: number;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
3
52
|
//#region src/lib/queue/index.d.ts
|
|
4
53
|
declare class Queue<T> {
|
|
5
54
|
private options;
|
|
@@ -9,11 +58,12 @@ declare class Queue<T> {
|
|
|
9
58
|
private timeout;
|
|
10
59
|
private concurrency;
|
|
11
60
|
private pollInterval;
|
|
61
|
+
private retryBaseDelay;
|
|
62
|
+
private retryMultiplier;
|
|
63
|
+
private retryMaxDelay;
|
|
12
64
|
constructor(options: QueueOptions<T>);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly message: string;
|
|
16
|
-
}, null] | readonly [null, string]>;
|
|
65
|
+
private computeBackoffDelay;
|
|
66
|
+
enqueue(data: T): Promise<string>;
|
|
17
67
|
stop(): Promise<void>;
|
|
18
68
|
private waitForPollInterval;
|
|
19
69
|
private serializeJob;
|
|
@@ -28,5 +78,4 @@ declare class Queue<T> {
|
|
|
28
78
|
private retryJob;
|
|
29
79
|
}
|
|
30
80
|
//#endregion
|
|
31
|
-
export { Queue };
|
|
32
|
-
//# sourceMappingURL=index.d.cts.map
|
|
81
|
+
export { Queue };
|
|
@@ -1,5 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/lib/queue/types.d.ts
|
|
2
|
+
type Job<T> = {
|
|
3
|
+
id: string;
|
|
4
|
+
data: T;
|
|
5
|
+
attempts: number;
|
|
6
|
+
maxRetries: number;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
};
|
|
9
|
+
type RetryContext<T> = {
|
|
10
|
+
job: Job<T>;
|
|
11
|
+
error: string;
|
|
12
|
+
nextRetryDelayMs: number;
|
|
13
|
+
retriesRemaining: number;
|
|
14
|
+
backoffMultiplier: number;
|
|
15
|
+
};
|
|
16
|
+
type ErrorContext<T> = {
|
|
17
|
+
job: Job<T>;
|
|
18
|
+
lastError: string;
|
|
19
|
+
totalDurationMs: number;
|
|
20
|
+
totalAttempts: number;
|
|
21
|
+
errorHistory: Array<{
|
|
22
|
+
attempt: number;
|
|
23
|
+
error: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
type ParseErrorContext = {
|
|
28
|
+
rawJobData: string;
|
|
29
|
+
parseError: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
};
|
|
32
|
+
type QueueRetryBackoff = {
|
|
33
|
+
baseDelay?: number;
|
|
34
|
+
multiplier?: number;
|
|
35
|
+
maxDelay?: number;
|
|
36
|
+
};
|
|
37
|
+
type QueueOptions<T> = {
|
|
38
|
+
name: string;
|
|
39
|
+
redis: Bun.RedisClient;
|
|
40
|
+
handler: (data: T, signal?: AbortSignal) => void | Promise<void>;
|
|
41
|
+
onSuccess?: (job: Job<T>) => void | Promise<void>;
|
|
42
|
+
onRetry?: (context: RetryContext<T>) => void | Promise<void>;
|
|
43
|
+
onError?: (context: ErrorContext<T>) => void | Promise<void>;
|
|
44
|
+
onParseError?: (context: ParseErrorContext) => void | Promise<void>;
|
|
45
|
+
retries?: number;
|
|
46
|
+
retryBackoff?: QueueRetryBackoff;
|
|
47
|
+
timeout?: number;
|
|
48
|
+
concurrency?: number;
|
|
49
|
+
pollInterval?: number;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
3
52
|
//#region src/lib/queue/index.d.ts
|
|
4
53
|
declare class Queue<T> {
|
|
5
54
|
private options;
|
|
@@ -9,11 +58,12 @@ declare class Queue<T> {
|
|
|
9
58
|
private timeout;
|
|
10
59
|
private concurrency;
|
|
11
60
|
private pollInterval;
|
|
61
|
+
private retryBaseDelay;
|
|
62
|
+
private retryMultiplier;
|
|
63
|
+
private retryMaxDelay;
|
|
12
64
|
constructor(options: QueueOptions<T>);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly message: string;
|
|
16
|
-
}, null] | readonly [null, string]>;
|
|
65
|
+
private computeBackoffDelay;
|
|
66
|
+
enqueue(data: T): Promise<string>;
|
|
17
67
|
stop(): Promise<void>;
|
|
18
68
|
private waitForPollInterval;
|
|
19
69
|
private serializeJob;
|
|
@@ -28,5 +78,4 @@ declare class Queue<T> {
|
|
|
28
78
|
private retryJob;
|
|
29
79
|
}
|
|
30
80
|
//#endregion
|
|
31
|
-
export { Queue };
|
|
32
|
-
//# sourceMappingURL=index.d.mts.map
|
|
81
|
+
export { Queue };
|
package/dist/lib/queue/index.mjs
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mightThrow, mightThrowSync } from "../errors/index.mjs";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
//#region src/lib/queue/errors.ts
|
|
4
|
+
var SerializationError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "SerializationError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var EnqueueError = class extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "EnqueueError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
2
17
|
//#region src/lib/queue/index.ts
|
|
3
18
|
const toMinimalJob = (jobState) => ({
|
|
4
19
|
id: jobState.id,
|
|
@@ -11,9 +26,9 @@ const DEFAULT_RETRIES = 3;
|
|
|
11
26
|
const DEFAULT_TIMEOUT = 3e4;
|
|
12
27
|
const DEFAULT_CONCURRENCY = 1;
|
|
13
28
|
const DEFAULT_POLL_INTERVAL = 100;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
29
|
+
const DEFAULT_RETRY_MAX_DELAY = 6e4;
|
|
30
|
+
const DEFAULT_RETRY_BASE_DELAY = 1e3;
|
|
31
|
+
const DEFAULT_RETRY_MULTIPLIER = 2;
|
|
17
32
|
const SHUTDOWN_POLL_INTERVAL = 10;
|
|
18
33
|
var Queue = class {
|
|
19
34
|
options;
|
|
@@ -23,14 +38,26 @@ var Queue = class {
|
|
|
23
38
|
timeout;
|
|
24
39
|
concurrency;
|
|
25
40
|
pollInterval;
|
|
41
|
+
retryBaseDelay;
|
|
42
|
+
retryMultiplier;
|
|
43
|
+
retryMaxDelay;
|
|
26
44
|
constructor(options) {
|
|
27
45
|
this.options = options;
|
|
28
46
|
this.retries = options.retries ?? DEFAULT_RETRIES;
|
|
29
47
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
30
48
|
this.concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
31
49
|
this.pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
50
|
+
this.retryBaseDelay = options.retryBackoff?.baseDelay ?? DEFAULT_RETRY_BASE_DELAY;
|
|
51
|
+
this.retryMultiplier = options.retryBackoff?.multiplier ?? DEFAULT_RETRY_MULTIPLIER;
|
|
52
|
+
this.retryMaxDelay = options.retryBackoff?.maxDelay ?? DEFAULT_RETRY_MAX_DELAY;
|
|
53
|
+
assert.ok(Number.isFinite(this.retryBaseDelay) && this.retryBaseDelay > 0, "Invalid retryBackoff.baseDelay: must be a positive finite number");
|
|
54
|
+
assert.ok(Number.isFinite(this.retryMultiplier) && this.retryMultiplier > 0, "Invalid retryBackoff.multiplier: must be a positive finite number");
|
|
55
|
+
assert.ok(Number.isFinite(this.retryMaxDelay) && this.retryMaxDelay > 0, "Invalid retryBackoff.maxDelay: must be a positive finite number");
|
|
32
56
|
this.startWorkers();
|
|
33
57
|
}
|
|
58
|
+
computeBackoffDelay(attempt) {
|
|
59
|
+
return Math.min(this.retryBaseDelay * this.retryMultiplier ** (attempt - 1), this.retryMaxDelay);
|
|
60
|
+
}
|
|
34
61
|
async enqueue(data) {
|
|
35
62
|
const job = {
|
|
36
63
|
id: crypto.randomUUID(),
|
|
@@ -40,10 +67,10 @@ var Queue = class {
|
|
|
40
67
|
createdAt: Date.now()
|
|
41
68
|
};
|
|
42
69
|
const [serializeError, serialized] = this.serializeJob(job);
|
|
43
|
-
if (serializeError || !serialized)
|
|
70
|
+
if (serializeError || !serialized) throw new SerializationError("Unable to serialize job data");
|
|
44
71
|
const [enqueueError] = await this.enqueueJobData(serialized);
|
|
45
|
-
if (enqueueError)
|
|
46
|
-
return
|
|
72
|
+
if (enqueueError) throw new EnqueueError("Unable to enqueue job");
|
|
73
|
+
return job.id;
|
|
47
74
|
}
|
|
48
75
|
async stop() {
|
|
49
76
|
this.running = false;
|
|
@@ -69,7 +96,8 @@ var Queue = class {
|
|
|
69
96
|
return mightThrow(this.options.redis.lpush(deadLetterKey, deadLetterEntry));
|
|
70
97
|
}
|
|
71
98
|
formatErrorMessage(error) {
|
|
72
|
-
|
|
99
|
+
if (!error) return "Unknown error";
|
|
100
|
+
return error.message;
|
|
73
101
|
}
|
|
74
102
|
startWorkers() {
|
|
75
103
|
for (let i = 0; i < this.concurrency; i++) this.processJobs();
|
|
@@ -130,13 +158,13 @@ var Queue = class {
|
|
|
130
158
|
});
|
|
131
159
|
if (job.attempts <= job.maxRetries) {
|
|
132
160
|
if (this.options.onRetry) {
|
|
133
|
-
const delay =
|
|
161
|
+
const delay = this.computeBackoffDelay(job.attempts);
|
|
134
162
|
await mightThrow(Promise.resolve(this.options.onRetry({
|
|
135
163
|
job: toMinimalJob(job),
|
|
136
164
|
error: errorMsg,
|
|
137
165
|
nextRetryDelayMs: delay,
|
|
138
166
|
retriesRemaining: job.maxRetries - job.attempts,
|
|
139
|
-
backoffMultiplier:
|
|
167
|
+
backoffMultiplier: this.retryMultiplier
|
|
140
168
|
})));
|
|
141
169
|
}
|
|
142
170
|
await this.retryJob(job);
|
|
@@ -161,7 +189,7 @@ var Queue = class {
|
|
|
161
189
|
})));
|
|
162
190
|
}
|
|
163
191
|
async retryJob(job) {
|
|
164
|
-
const delay =
|
|
192
|
+
const delay = this.computeBackoffDelay(job.attempts);
|
|
165
193
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
166
194
|
const [stringifyError, serialized] = this.serializeJob(job);
|
|
167
195
|
if (stringifyError || !serialized) {
|
|
@@ -179,5 +207,3 @@ var Queue = class {
|
|
|
179
207
|
};
|
|
180
208
|
//#endregion
|
|
181
209
|
export { Queue };
|
|
182
|
-
|
|
183
|
-
//# sourceMappingURL=index.mjs.map
|