@hotmeshio/hotmesh 0.0.3 → 0.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/README.md +3 -3
- package/build/{package.json → cjs/package.json} +12 -5
- package/build/{services → cjs/services}/activities/activity.d.ts +2 -0
- package/build/{services → cjs/services}/activities/activity.js +27 -9
- package/build/{services → cjs/services}/activities/trigger.js +2 -2
- package/build/{services → cjs/services}/activities/worker.js +1 -0
- package/build/{services → cjs/services}/collator/index.d.ts +7 -5
- package/build/{services → cjs/services}/collator/index.js +29 -6
- package/build/{services → cjs/services}/compiler/deployer.d.ts +4 -3
- package/build/{services → cjs/services}/compiler/deployer.js +14 -0
- package/build/{services → cjs/services}/connector/index.js +3 -3
- package/build/{services → cjs/services}/dimension/index.d.ts +1 -1
- package/build/{services → cjs/services}/durable/client.js +2 -2
- package/build/{services → cjs/services}/durable/connection.js +2 -2
- package/build/{services → cjs/services}/durable/handle.d.ts +1 -1
- package/build/{services → cjs/services}/engine/index.d.ts +1 -1
- package/build/{services → cjs/services}/engine/index.js +22 -5
- package/build/{services → cjs/services}/hotmesh/index.d.ts +1 -1
- package/build/{services → cjs/services}/hotmesh/index.js +4 -4
- package/build/{services → cjs/services}/mapper/index.d.ts +3 -3
- package/build/{services → cjs/services}/serializer/index.d.ts +6 -1
- package/build/{services → cjs/services}/serializer/index.js +55 -22
- package/build/{services → cjs/services}/signaler/stream.js +1 -0
- package/build/{services → cjs/services}/store/index.d.ts +3 -3
- package/build/{services → cjs/services}/store/index.js +11 -24
- package/build/{types → cjs/types}/activity.d.ts +1 -0
- package/build/esm/index.d.ts +4 -0
- package/build/esm/index.js +3 -0
- package/build/esm/modules/errors.d.ts +28 -0
- package/build/esm/modules/errors.js +41 -0
- package/build/esm/modules/key.d.ts +75 -0
- package/build/esm/modules/key.js +111 -0
- package/build/esm/modules/utils.d.ts +34 -0
- package/build/esm/modules/utils.js +154 -0
- package/build/esm/package.json +80 -0
- package/build/esm/services/activities/activity.d.ts +61 -0
- package/build/esm/services/activities/activity.js +411 -0
- package/build/esm/services/activities/await.d.ts +16 -0
- package/build/esm/services/activities/await.js +140 -0
- package/build/esm/services/activities/emit.d.ts +9 -0
- package/build/esm/services/activities/emit.js +10 -0
- package/build/esm/services/activities/index.d.ts +15 -0
- package/build/esm/services/activities/index.js +14 -0
- package/build/esm/services/activities/iterate.d.ts +9 -0
- package/build/esm/services/activities/iterate.js +10 -0
- package/build/esm/services/activities/trigger.d.ts +22 -0
- package/build/esm/services/activities/trigger.js +158 -0
- package/build/esm/services/activities/worker.d.ts +17 -0
- package/build/esm/services/activities/worker.js +162 -0
- package/build/esm/services/collator/index.d.ts +56 -0
- package/build/esm/services/collator/index.js +191 -0
- package/build/esm/services/compiler/deployer.d.ts +36 -0
- package/build/esm/services/compiler/deployer.js +423 -0
- package/build/esm/services/compiler/index.d.ts +30 -0
- package/build/esm/services/compiler/index.js +82 -0
- package/build/esm/services/compiler/validator.d.ts +32 -0
- package/build/esm/services/compiler/validator.js +131 -0
- package/build/esm/services/connector/clients/ioredis.d.ts +13 -0
- package/build/esm/services/connector/clients/ioredis.js +47 -0
- package/build/esm/services/connector/clients/redis.d.ts +13 -0
- package/build/esm/services/connector/clients/redis.js +59 -0
- package/build/esm/services/connector/index.d.ts +5 -0
- package/build/esm/services/connector/index.js +27 -0
- package/build/esm/services/dimension/index.d.ts +29 -0
- package/build/esm/services/dimension/index.js +32 -0
- package/build/esm/services/durable/asyncLocalStorage.d.ts +3 -0
- package/build/esm/services/durable/asyncLocalStorage.js +2 -0
- package/build/esm/services/durable/client.d.ts +15 -0
- package/build/esm/services/durable/client.js +114 -0
- package/build/esm/services/durable/connection.d.ts +4 -0
- package/build/esm/services/durable/connection.js +47 -0
- package/build/esm/services/durable/factory.d.ts +3 -0
- package/build/esm/services/durable/factory.js +119 -0
- package/build/esm/services/durable/handle.d.ts +8 -0
- package/build/esm/services/durable/handle.js +34 -0
- package/build/esm/services/durable/index.d.ts +57 -0
- package/build/esm/services/durable/index.js +55 -0
- package/build/esm/services/durable/native.d.ts +4 -0
- package/build/esm/services/durable/native.js +43 -0
- package/build/esm/services/durable/worker.d.ts +36 -0
- package/build/esm/services/durable/worker.js +258 -0
- package/build/esm/services/durable/workflow.d.ts +6 -0
- package/build/esm/services/durable/workflow.js +128 -0
- package/build/esm/services/engine/index.d.ts +82 -0
- package/build/esm/services/engine/index.js +522 -0
- package/build/esm/services/hotmesh/index.d.ts +45 -0
- package/build/esm/services/hotmesh/index.js +131 -0
- package/build/esm/services/logger/index.d.ts +17 -0
- package/build/esm/services/logger/index.js +70 -0
- package/build/esm/services/mapper/index.d.ts +24 -0
- package/build/esm/services/mapper/index.js +69 -0
- package/build/esm/services/pipe/functions/array.d.ts +24 -0
- package/build/esm/services/pipe/functions/array.js +66 -0
- package/build/esm/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/esm/services/pipe/functions/bitwise.js +21 -0
- package/build/esm/services/pipe/functions/conditional.d.ts +10 -0
- package/build/esm/services/pipe/functions/conditional.js +24 -0
- package/build/esm/services/pipe/functions/date.d.ts +57 -0
- package/build/esm/services/pipe/functions/date.js +164 -0
- package/build/esm/services/pipe/functions/index.d.ts +25 -0
- package/build/esm/services/pipe/functions/index.js +24 -0
- package/build/esm/services/pipe/functions/json.d.ts +5 -0
- package/build/esm/services/pipe/functions/json.js +9 -0
- package/build/esm/services/pipe/functions/math.d.ts +38 -0
- package/build/esm/services/pipe/functions/math.js +108 -0
- package/build/esm/services/pipe/functions/number.d.ts +25 -0
- package/build/esm/services/pipe/functions/number.js +130 -0
- package/build/esm/services/pipe/functions/object.d.ts +22 -0
- package/build/esm/services/pipe/functions/object.js +60 -0
- package/build/esm/services/pipe/functions/string.d.ts +23 -0
- package/build/esm/services/pipe/functions/string.js +66 -0
- package/build/esm/services/pipe/functions/symbol.d.ts +12 -0
- package/build/esm/services/pipe/functions/symbol.js +30 -0
- package/build/esm/services/pipe/functions/unary.d.ts +7 -0
- package/build/esm/services/pipe/functions/unary.js +15 -0
- package/build/esm/services/pipe/index.d.ts +30 -0
- package/build/esm/services/pipe/index.js +122 -0
- package/build/esm/services/quorum/index.d.ts +34 -0
- package/build/esm/services/quorum/index.js +144 -0
- package/build/esm/services/reporter/index.d.ts +47 -0
- package/build/esm/services/reporter/index.js +327 -0
- package/build/esm/services/serializer/index.d.ts +41 -0
- package/build/esm/services/serializer/index.js +251 -0
- package/build/esm/services/signaler/store.d.ts +15 -0
- package/build/esm/services/signaler/store.js +50 -0
- package/build/esm/services/signaler/stream.d.ts +43 -0
- package/build/esm/services/signaler/stream.js +315 -0
- package/build/esm/services/store/cache.d.ts +66 -0
- package/build/esm/services/store/cache.js +124 -0
- package/build/esm/services/store/clients/ioredis.d.ts +27 -0
- package/build/esm/services/store/clients/ioredis.js +93 -0
- package/build/esm/services/store/clients/redis.d.ts +29 -0
- package/build/esm/services/store/clients/redis.js +140 -0
- package/build/esm/services/store/index.d.ts +88 -0
- package/build/esm/services/store/index.js +623 -0
- package/build/esm/services/stream/clients/ioredis.d.ts +23 -0
- package/build/esm/services/stream/clients/ioredis.js +112 -0
- package/build/esm/services/stream/clients/redis.d.ts +23 -0
- package/build/esm/services/stream/clients/redis.js +116 -0
- package/build/esm/services/stream/index.d.ts +21 -0
- package/build/esm/services/stream/index.js +6 -0
- package/build/esm/services/sub/clients/ioredis.d.ts +20 -0
- package/build/esm/services/sub/clients/ioredis.js +69 -0
- package/build/esm/services/sub/clients/redis.d.ts +20 -0
- package/build/esm/services/sub/clients/redis.js +60 -0
- package/build/esm/services/sub/index.d.ts +18 -0
- package/build/esm/services/sub/index.js +6 -0
- package/build/esm/services/task/index.d.ts +18 -0
- package/build/esm/services/task/index.js +70 -0
- package/build/esm/services/telemetry/index.d.ts +49 -0
- package/build/esm/services/telemetry/index.js +217 -0
- package/build/esm/services/worker/index.d.ts +30 -0
- package/build/esm/services/worker/index.js +102 -0
- package/build/esm/types/activity.d.ts +87 -0
- package/build/esm/types/activity.js +1 -0
- package/build/esm/types/app.d.ts +16 -0
- package/build/esm/types/app.js +1 -0
- package/build/esm/types/async.d.ts +5 -0
- package/build/esm/types/async.js +1 -0
- package/build/esm/types/cache.d.ts +1 -0
- package/build/esm/types/cache.js +1 -0
- package/build/esm/types/collator.d.ts +8 -0
- package/build/esm/types/collator.js +8 -0
- package/build/esm/types/durable.d.ts +59 -0
- package/build/esm/types/durable.js +1 -0
- package/build/esm/types/hook.d.ts +31 -0
- package/build/esm/types/hook.js +6 -0
- package/build/esm/types/hotmesh.d.ts +82 -0
- package/build/esm/types/hotmesh.js +1 -0
- package/build/esm/types/index.d.ts +20 -0
- package/build/esm/types/index.js +5 -0
- package/build/esm/types/ioredisclient.d.ts +5 -0
- package/build/esm/types/ioredisclient.js +2 -0
- package/build/esm/types/job.d.ts +50 -0
- package/build/esm/types/job.js +1 -0
- package/build/esm/types/logger.d.ts +6 -0
- package/build/esm/types/logger.js +1 -0
- package/build/esm/types/map.d.ts +4 -0
- package/build/esm/types/map.js +1 -0
- package/build/esm/types/pipe.d.ts +4 -0
- package/build/esm/types/pipe.js +1 -0
- package/build/esm/types/quorum.d.ts +46 -0
- package/build/esm/types/quorum.js +1 -0
- package/build/esm/types/redis.d.ts +8 -0
- package/build/esm/types/redis.js +1 -0
- package/build/esm/types/redisclient.d.ts +25 -0
- package/build/esm/types/redisclient.js +1 -0
- package/build/esm/types/serializer.d.ts +33 -0
- package/build/esm/types/serializer.js +1 -0
- package/build/esm/types/stats.d.ts +83 -0
- package/build/esm/types/stats.js +1 -0
- package/build/esm/types/stream.d.ts +67 -0
- package/build/esm/types/stream.js +22 -0
- package/build/esm/types/telemetry.d.ts +1 -0
- package/build/esm/types/telemetry.js +1 -0
- package/build/esm/types/transition.d.ts +17 -0
- package/build/esm/types/transition.js +1 -0
- package/package.json +12 -5
- package/services/activities/activity.ts +28 -9
- package/services/activities/trigger.ts +2 -2
- package/services/activities/worker.ts +1 -0
- package/services/collator/index.ts +38 -13
- package/services/compiler/deployer.ts +24 -9
- package/services/connector/index.ts +3 -3
- package/services/dimension/index.ts +1 -1
- package/services/durable/client.ts +2 -2
- package/services/durable/connection.ts +2 -2
- package/services/durable/handle.ts +2 -2
- package/services/engine/index.ts +23 -5
- package/services/hotmesh/index.ts +4 -4
- package/services/mapper/index.ts +6 -8
- package/services/serializer/index.ts +57 -22
- package/services/signaler/stream.ts +1 -0
- package/services/store/index.ts +13 -25
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +9 -0
- package/types/activity.ts +1 -0
- /package/build/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/build/{index.js → cjs/index.js} +0 -0
- /package/build/{modules → cjs/modules}/errors.d.ts +0 -0
- /package/build/{modules → cjs/modules}/errors.js +0 -0
- /package/build/{modules → cjs/modules}/key.d.ts +0 -0
- /package/build/{modules → cjs/modules}/key.js +0 -0
- /package/build/{modules → cjs/modules}/utils.d.ts +0 -0
- /package/build/{modules → cjs/modules}/utils.js +0 -0
- /package/build/{services → cjs/services}/activities/await.d.ts +0 -0
- /package/build/{services → cjs/services}/activities/await.js +0 -0
- /package/build/{services → cjs/services}/activities/emit.d.ts +0 -0
- /package/build/{services → cjs/services}/activities/emit.js +0 -0
- /package/build/{services → cjs/services}/activities/index.d.ts +0 -0
- /package/build/{services → cjs/services}/activities/index.js +0 -0
- /package/build/{services → cjs/services}/activities/iterate.d.ts +0 -0
- /package/build/{services → cjs/services}/activities/iterate.js +0 -0
- /package/build/{services → cjs/services}/activities/trigger.d.ts +0 -0
- /package/build/{services → cjs/services}/activities/worker.d.ts +0 -0
- /package/build/{services → cjs/services}/compiler/index.d.ts +0 -0
- /package/build/{services → cjs/services}/compiler/index.js +0 -0
- /package/build/{services → cjs/services}/compiler/validator.d.ts +0 -0
- /package/build/{services → cjs/services}/compiler/validator.js +0 -0
- /package/build/{services → cjs/services}/connector/clients/ioredis.d.ts +0 -0
- /package/build/{services → cjs/services}/connector/clients/ioredis.js +0 -0
- /package/build/{services → cjs/services}/connector/clients/redis.d.ts +0 -0
- /package/build/{services → cjs/services}/connector/clients/redis.js +0 -0
- /package/build/{services → cjs/services}/connector/index.d.ts +0 -0
- /package/build/{services → cjs/services}/dimension/index.js +0 -0
- /package/build/{services → cjs/services}/durable/asyncLocalStorage.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/asyncLocalStorage.js +0 -0
- /package/build/{services → cjs/services}/durable/client.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/connection.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/factory.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/factory.js +0 -0
- /package/build/{services → cjs/services}/durable/handle.js +0 -0
- /package/build/{services → cjs/services}/durable/index.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/index.js +0 -0
- /package/build/{services → cjs/services}/durable/native.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/native.js +0 -0
- /package/build/{services → cjs/services}/durable/worker.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/worker.js +0 -0
- /package/build/{services → cjs/services}/durable/workflow.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/workflow.js +0 -0
- /package/build/{services → cjs/services}/logger/index.d.ts +0 -0
- /package/build/{services → cjs/services}/logger/index.js +0 -0
- /package/build/{services → cjs/services}/mapper/index.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/array.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/array.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/bitwise.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/bitwise.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/conditional.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/conditional.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/date.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/date.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/index.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/index.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/json.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/json.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/math.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/math.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/number.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/number.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/object.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/object.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/string.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/string.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/symbol.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/symbol.js +0 -0
- /package/build/{services → cjs/services}/pipe/functions/unary.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/functions/unary.js +0 -0
- /package/build/{services → cjs/services}/pipe/index.d.ts +0 -0
- /package/build/{services → cjs/services}/pipe/index.js +0 -0
- /package/build/{services → cjs/services}/quorum/index.d.ts +0 -0
- /package/build/{services → cjs/services}/quorum/index.js +0 -0
- /package/build/{services → cjs/services}/reporter/index.d.ts +0 -0
- /package/build/{services → cjs/services}/reporter/index.js +0 -0
- /package/build/{services → cjs/services}/signaler/store.d.ts +0 -0
- /package/build/{services → cjs/services}/signaler/store.js +0 -0
- /package/build/{services → cjs/services}/signaler/stream.d.ts +0 -0
- /package/build/{services → cjs/services}/store/cache.d.ts +0 -0
- /package/build/{services → cjs/services}/store/cache.js +0 -0
- /package/build/{services → cjs/services}/store/clients/ioredis.d.ts +0 -0
- /package/build/{services → cjs/services}/store/clients/ioredis.js +0 -0
- /package/build/{services → cjs/services}/store/clients/redis.d.ts +0 -0
- /package/build/{services → cjs/services}/store/clients/redis.js +0 -0
- /package/build/{services → cjs/services}/stream/clients/ioredis.d.ts +0 -0
- /package/build/{services → cjs/services}/stream/clients/ioredis.js +0 -0
- /package/build/{services → cjs/services}/stream/clients/redis.d.ts +0 -0
- /package/build/{services → cjs/services}/stream/clients/redis.js +0 -0
- /package/build/{services → cjs/services}/stream/index.d.ts +0 -0
- /package/build/{services → cjs/services}/stream/index.js +0 -0
- /package/build/{services → cjs/services}/sub/clients/ioredis.d.ts +0 -0
- /package/build/{services → cjs/services}/sub/clients/ioredis.js +0 -0
- /package/build/{services → cjs/services}/sub/clients/redis.d.ts +0 -0
- /package/build/{services → cjs/services}/sub/clients/redis.js +0 -0
- /package/build/{services → cjs/services}/sub/index.d.ts +0 -0
- /package/build/{services → cjs/services}/sub/index.js +0 -0
- /package/build/{services → cjs/services}/task/index.d.ts +0 -0
- /package/build/{services → cjs/services}/task/index.js +0 -0
- /package/build/{services → cjs/services}/telemetry/index.d.ts +0 -0
- /package/build/{services → cjs/services}/telemetry/index.js +0 -0
- /package/build/{services → cjs/services}/worker/index.d.ts +0 -0
- /package/build/{services → cjs/services}/worker/index.js +0 -0
- /package/build/{types → cjs/types}/activity.js +0 -0
- /package/build/{types → cjs/types}/app.d.ts +0 -0
- /package/build/{types → cjs/types}/app.js +0 -0
- /package/build/{types → cjs/types}/async.d.ts +0 -0
- /package/build/{types → cjs/types}/async.js +0 -0
- /package/build/{types → cjs/types}/cache.d.ts +0 -0
- /package/build/{types → cjs/types}/cache.js +0 -0
- /package/build/{types → cjs/types}/collator.d.ts +0 -0
- /package/build/{types → cjs/types}/collator.js +0 -0
- /package/build/{types → cjs/types}/durable.d.ts +0 -0
- /package/build/{types → cjs/types}/durable.js +0 -0
- /package/build/{types → cjs/types}/hook.d.ts +0 -0
- /package/build/{types → cjs/types}/hook.js +0 -0
- /package/build/{types → cjs/types}/hotmesh.d.ts +0 -0
- /package/build/{types → cjs/types}/hotmesh.js +0 -0
- /package/build/{types → cjs/types}/index.d.ts +0 -0
- /package/build/{types → cjs/types}/index.js +0 -0
- /package/build/{types → cjs/types}/ioredisclient.d.ts +0 -0
- /package/build/{types → cjs/types}/ioredisclient.js +0 -0
- /package/build/{types → cjs/types}/job.d.ts +0 -0
- /package/build/{types → cjs/types}/job.js +0 -0
- /package/build/{types → cjs/types}/logger.d.ts +0 -0
- /package/build/{types → cjs/types}/logger.js +0 -0
- /package/build/{types → cjs/types}/map.d.ts +0 -0
- /package/build/{types → cjs/types}/map.js +0 -0
- /package/build/{types → cjs/types}/pipe.d.ts +0 -0
- /package/build/{types → cjs/types}/pipe.js +0 -0
- /package/build/{types → cjs/types}/quorum.d.ts +0 -0
- /package/build/{types → cjs/types}/quorum.js +0 -0
- /package/build/{types → cjs/types}/redis.d.ts +0 -0
- /package/build/{types → cjs/types}/redis.js +0 -0
- /package/build/{types → cjs/types}/redisclient.d.ts +0 -0
- /package/build/{types → cjs/types}/redisclient.js +0 -0
- /package/build/{types → cjs/types}/serializer.d.ts +0 -0
- /package/build/{types → cjs/types}/serializer.js +0 -0
- /package/build/{types → cjs/types}/stats.d.ts +0 -0
- /package/build/{types → cjs/types}/stats.js +0 -0
- /package/build/{types → cjs/types}/stream.d.ts +0 -0
- /package/build/{types → cjs/types}/stream.js +0 -0
- /package/build/{types → cjs/types}/telemetry.d.ts +0 -0
- /package/build/{types → cjs/types}/telemetry.js +0 -0
- /package/build/{types → cjs/types}/transition.d.ts +0 -0
- /package/build/{types → cjs/types}/transition.js +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ILogger } from '../logger';
|
|
3
|
+
import { StoreService } from '../store';
|
|
4
|
+
import { StreamService } from '../stream';
|
|
5
|
+
import { RedisClient, RedisMulti } from '../../types/redis';
|
|
6
|
+
import { ReclaimedMessageType, StreamConfig, StreamData, StreamDataResponse, StreamRole } from '../../types/stream';
|
|
7
|
+
declare class StreamSignaler {
|
|
8
|
+
static signalers: Set<StreamSignaler>;
|
|
9
|
+
appId: string;
|
|
10
|
+
guid: string;
|
|
11
|
+
role: StreamRole;
|
|
12
|
+
topic: string | undefined;
|
|
13
|
+
store: StoreService<RedisClient, RedisMulti>;
|
|
14
|
+
stream: StreamService<RedisClient, RedisMulti>;
|
|
15
|
+
reclaimDelay: number;
|
|
16
|
+
reclaimCount: number;
|
|
17
|
+
logger: ILogger;
|
|
18
|
+
throttle: number;
|
|
19
|
+
errorCount: number;
|
|
20
|
+
currentTimerId: NodeJS.Timeout | null;
|
|
21
|
+
shouldConsume: boolean;
|
|
22
|
+
constructor(config: StreamConfig, stream: StreamService<RedisClient, RedisMulti>, store: StoreService<RedisClient, RedisMulti>, logger: ILogger);
|
|
23
|
+
createGroup(stream: string, group: string): Promise<void>;
|
|
24
|
+
publishMessage(topic: string, streamData: StreamData | StreamDataResponse, multi?: RedisMulti): Promise<string | RedisMulti>;
|
|
25
|
+
consumeMessages(stream: string, group: string, consumer: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;
|
|
26
|
+
isStreamMessage(result: any): boolean;
|
|
27
|
+
consumeOne(stream: string, group: string, id: string, message: string[], callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;
|
|
28
|
+
execStreamLeg(input: StreamData, stream: string, id: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<StreamDataResponse>;
|
|
29
|
+
ackAndDelete(stream: string, group: string, id: string): Promise<void>;
|
|
30
|
+
publishResponse(input: StreamData, output: StreamDataResponse | void): Promise<string>;
|
|
31
|
+
shouldRetry(input: StreamData, output: StreamDataResponse): [boolean, number];
|
|
32
|
+
structureUnhandledError(input: StreamData, err: Error): StreamDataResponse;
|
|
33
|
+
structureUnacknowledgedError(input: StreamData): StreamDataResponse;
|
|
34
|
+
structureError(input: StreamData, output: StreamDataResponse): StreamDataResponse;
|
|
35
|
+
static stopConsuming(): Promise<void>;
|
|
36
|
+
stopConsuming(): Promise<void>;
|
|
37
|
+
cancelThrottle(): void;
|
|
38
|
+
setThrottle(delayInMillis: number): void;
|
|
39
|
+
claimUnacknowledged(stream: string, group: string, consumer: string, idleTimeMs?: number, limit?: number): Promise<[string, [string, string]][]>;
|
|
40
|
+
expireUnacknowledged(reclaimedMessage: ReclaimedMessageType, stream: string, group: string, consumer: string, id: string, count: number): Promise<void>;
|
|
41
|
+
parseStreamData(str: string): [undefined, StreamData] | [Error];
|
|
42
|
+
}
|
|
43
|
+
export { StreamSignaler };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { KeyType } from '../../modules/key';
|
|
2
|
+
import { XSleepFor, sleepFor } from '../../modules/utils';
|
|
3
|
+
import { TelemetryService } from '../telemetry';
|
|
4
|
+
import { StreamDataType, StreamRole, StreamStatus } from '../../types/stream';
|
|
5
|
+
const MAX_RETRIES = 4; //max delay (10s using exponential backoff);
|
|
6
|
+
const MAX_TIMEOUT_MS = 60000;
|
|
7
|
+
const GRADUATED_INTERVAL_MS = 5000;
|
|
8
|
+
const BLOCK_DURATION = 15000; //Set to `15` so SIGINT/SIGTERM can interrupt; set to `0` to BLOCK indefinitely
|
|
9
|
+
const TEST_BLOCK_DURATION = 1000; //Set to `1000` so tests can interrupt quickly
|
|
10
|
+
const BLOCK_TIME_MS = process.env.NODE_ENV === 'test' ? TEST_BLOCK_DURATION : BLOCK_DURATION;
|
|
11
|
+
const SYSTEM_STATUS_CODE = 999;
|
|
12
|
+
const UNKNOWN_STATUS_CODE = 500;
|
|
13
|
+
const UNKNOWN_STATUS_MESSAGE = 'unknown';
|
|
14
|
+
const XCLAIM_DELAY_MS = 1000 * 60; //max time a message can be unacked before it is claimed by another
|
|
15
|
+
const XCLAIM_COUNT = 3; //max number of times a message can be claimed by another before it is dead-lettered
|
|
16
|
+
const XPENDING_COUNT = 10;
|
|
17
|
+
class StreamSignaler {
|
|
18
|
+
constructor(config, stream, store, logger) {
|
|
19
|
+
this.throttle = 0;
|
|
20
|
+
this.errorCount = 0;
|
|
21
|
+
this.currentTimerId = null;
|
|
22
|
+
this.appId = config.appId;
|
|
23
|
+
this.guid = config.guid;
|
|
24
|
+
this.role = config.role;
|
|
25
|
+
this.topic = config.topic;
|
|
26
|
+
this.stream = stream;
|
|
27
|
+
this.store = store;
|
|
28
|
+
this.reclaimDelay = config.reclaimDelay || XCLAIM_DELAY_MS;
|
|
29
|
+
this.reclaimCount = config.reclaimCount || XCLAIM_COUNT;
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
}
|
|
32
|
+
async createGroup(stream, group) {
|
|
33
|
+
try {
|
|
34
|
+
await this.store.xgroup('CREATE', stream, group, '$', 'MKSTREAM');
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
this.logger.info('consumer-group-exists', { stream, group });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async publishMessage(topic, streamData, multi) {
|
|
41
|
+
const stream = this.store.mintKey(KeyType.STREAMS, { appId: this.store.appId, topic });
|
|
42
|
+
return await this.store.xadd(stream, '*', 'message', JSON.stringify(streamData), multi);
|
|
43
|
+
}
|
|
44
|
+
async consumeMessages(stream, group, consumer, callback) {
|
|
45
|
+
this.logger.info(`stream-consumer-starting`, { group, consumer, stream });
|
|
46
|
+
StreamSignaler.signalers.add(this);
|
|
47
|
+
this.shouldConsume = true;
|
|
48
|
+
await this.createGroup(stream, group);
|
|
49
|
+
let lastCheckedPendingMessagesAt = Date.now();
|
|
50
|
+
async function consume() {
|
|
51
|
+
let sleep = XSleepFor(this.throttle);
|
|
52
|
+
this.currentTimerId = sleep.timerId;
|
|
53
|
+
await sleep.promise;
|
|
54
|
+
if (!this.shouldConsume) {
|
|
55
|
+
this.logger.info(`stream-consumer-stopping`, { group, consumer, stream });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const result = await this.stream.xreadgroup('GROUP', group, consumer, 'BLOCK', BLOCK_TIME_MS, 'STREAMS', stream, '>');
|
|
60
|
+
if (this.isStreamMessage(result)) {
|
|
61
|
+
const [[, messages]] = result;
|
|
62
|
+
for (const [id, message] of messages) {
|
|
63
|
+
await this.consumeOne(stream, group, id, message, callback);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Check for pending messages (note: Redis 6.2 simplifies)
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
if (now - lastCheckedPendingMessagesAt > this.reclaimDelay) {
|
|
69
|
+
lastCheckedPendingMessagesAt = now;
|
|
70
|
+
const pendingMessages = await this.claimUnacknowledged(stream, group, consumer);
|
|
71
|
+
for (const [id, message] of pendingMessages) {
|
|
72
|
+
await this.consumeOne(stream, group, id, message, callback);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setImmediate(consume.bind(this));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (this.shouldConsume && process.env.NODE_ENV !== 'test') {
|
|
79
|
+
this.logger.error(`stream-consume-message-error`, { err, stream, group, consumer });
|
|
80
|
+
this.errorCount++;
|
|
81
|
+
const timeout = Math.min(GRADUATED_INTERVAL_MS * (2 ** this.errorCount), MAX_TIMEOUT_MS);
|
|
82
|
+
setTimeout(consume.bind(this), timeout);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
consume.call(this);
|
|
87
|
+
}
|
|
88
|
+
isStreamMessage(result) {
|
|
89
|
+
return Array.isArray(result) && Array.isArray(result[0]);
|
|
90
|
+
}
|
|
91
|
+
async consumeOne(stream, group, id, message, callback) {
|
|
92
|
+
this.logger.debug(`stream-consume-one`, { group, stream, id });
|
|
93
|
+
const [err, input] = this.parseStreamData(message[1]);
|
|
94
|
+
let output;
|
|
95
|
+
let telemetry;
|
|
96
|
+
try {
|
|
97
|
+
telemetry = new TelemetryService(this.appId);
|
|
98
|
+
telemetry.startStreamSpan(input, this.role);
|
|
99
|
+
output = await this.execStreamLeg(input, stream, id, callback.bind(this));
|
|
100
|
+
if (output?.status === StreamStatus.ERROR) {
|
|
101
|
+
telemetry.setStreamError(`Function Status Code ${output.code || UNKNOWN_STATUS_CODE}`);
|
|
102
|
+
}
|
|
103
|
+
this.errorCount = 0;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
this.logger.error(`stream-consume-one-error`, { group, stream, id, err });
|
|
107
|
+
telemetry.setStreamError(err.message);
|
|
108
|
+
}
|
|
109
|
+
const messageId = await this.publishResponse(input, output);
|
|
110
|
+
telemetry.setStreamAttributes({ 'app.worker.mid': messageId });
|
|
111
|
+
await this.ackAndDelete(stream, group, id);
|
|
112
|
+
telemetry.endStreamSpan();
|
|
113
|
+
this.logger.debug(`stream-consume-one-end`, { group, stream, id });
|
|
114
|
+
}
|
|
115
|
+
async execStreamLeg(input, stream, id, callback) {
|
|
116
|
+
let output;
|
|
117
|
+
try {
|
|
118
|
+
output = await callback(input);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.error(err);
|
|
122
|
+
this.logger.error(`stream-call-function-error`, { stream, id, err });
|
|
123
|
+
output = this.structureUnhandledError(input, err);
|
|
124
|
+
}
|
|
125
|
+
return output;
|
|
126
|
+
}
|
|
127
|
+
async ackAndDelete(stream, group, id) {
|
|
128
|
+
const multi = this.stream.getMulti();
|
|
129
|
+
await this.stream.xack(stream, group, id, multi);
|
|
130
|
+
await this.stream.xdel(stream, id, multi);
|
|
131
|
+
await multi.exec();
|
|
132
|
+
}
|
|
133
|
+
async publishResponse(input, output) {
|
|
134
|
+
if (output && typeof output === 'object') {
|
|
135
|
+
if (output.status === 'error') {
|
|
136
|
+
const [shouldRetry, timeout] = this.shouldRetry(input, output);
|
|
137
|
+
if (shouldRetry) {
|
|
138
|
+
await sleepFor(timeout);
|
|
139
|
+
return await this.publishMessage(input.metadata.topic, {
|
|
140
|
+
data: input.data,
|
|
141
|
+
metadata: { ...input.metadata, try: (input.metadata.try || 0) + 1 },
|
|
142
|
+
policies: input.policies,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
output = this.structureError(input, output);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
output.type = StreamDataType.RESPONSE;
|
|
150
|
+
return await this.publishMessage(null, output);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
shouldRetry(input, output) {
|
|
154
|
+
const policies = input.policies?.retry;
|
|
155
|
+
const errorCode = output.code.toString();
|
|
156
|
+
const policy = policies?.[errorCode];
|
|
157
|
+
const maxRetries = policy?.[0];
|
|
158
|
+
const tryCount = Math.min(input.metadata.try || 0, MAX_RETRIES);
|
|
159
|
+
if (maxRetries >= tryCount) {
|
|
160
|
+
return [true, Math.pow(10, tryCount)];
|
|
161
|
+
}
|
|
162
|
+
return [false, 0];
|
|
163
|
+
}
|
|
164
|
+
structureUnhandledError(input, err) {
|
|
165
|
+
let error = {};
|
|
166
|
+
if (typeof err.message === 'string') {
|
|
167
|
+
error.message = err.message;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
error.message = UNKNOWN_STATUS_MESSAGE;
|
|
171
|
+
}
|
|
172
|
+
if (typeof err.stack === 'string') {
|
|
173
|
+
error.stack = err.stack;
|
|
174
|
+
}
|
|
175
|
+
if (typeof err.name === 'string') {
|
|
176
|
+
error.name = err.name;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
status: 'error',
|
|
180
|
+
code: UNKNOWN_STATUS_CODE,
|
|
181
|
+
metadata: { ...input.metadata },
|
|
182
|
+
data: error
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
structureUnacknowledgedError(input) {
|
|
186
|
+
const message = 'stream message max delivery count exceeded';
|
|
187
|
+
const code = SYSTEM_STATUS_CODE;
|
|
188
|
+
const data = { message, code };
|
|
189
|
+
const output = {
|
|
190
|
+
metadata: { ...input.metadata },
|
|
191
|
+
status: StreamStatus.ERROR,
|
|
192
|
+
code,
|
|
193
|
+
data,
|
|
194
|
+
};
|
|
195
|
+
//send unacknowleded errors to the engine (it has no topic)
|
|
196
|
+
delete output.metadata.topic;
|
|
197
|
+
return output;
|
|
198
|
+
}
|
|
199
|
+
structureError(input, output) {
|
|
200
|
+
const message = output.data?.message ? output.data?.message.toString() : UNKNOWN_STATUS_MESSAGE;
|
|
201
|
+
const statusCode = output.code || output.data?.code;
|
|
202
|
+
const code = isNaN(statusCode) ? UNKNOWN_STATUS_CODE : parseInt(statusCode.toString());
|
|
203
|
+
const data = { message, code };
|
|
204
|
+
if (typeof output.data?.error === 'object') {
|
|
205
|
+
data.error = { ...output.data.error };
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
status: StreamStatus.ERROR,
|
|
209
|
+
code,
|
|
210
|
+
metadata: { ...input.metadata },
|
|
211
|
+
data
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
static async stopConsuming() {
|
|
215
|
+
for (const instance of [...StreamSignaler.signalers]) {
|
|
216
|
+
instance.stopConsuming();
|
|
217
|
+
}
|
|
218
|
+
await sleepFor(BLOCK_TIME_MS);
|
|
219
|
+
}
|
|
220
|
+
async stopConsuming() {
|
|
221
|
+
this.shouldConsume = false;
|
|
222
|
+
this.logger.info(`stream-consumer-stopping`, this.topic ? { topic: this.topic } : undefined);
|
|
223
|
+
this.cancelThrottle();
|
|
224
|
+
await sleepFor(BLOCK_TIME_MS);
|
|
225
|
+
}
|
|
226
|
+
cancelThrottle() {
|
|
227
|
+
if (this.currentTimerId !== undefined) {
|
|
228
|
+
clearTimeout(this.currentTimerId);
|
|
229
|
+
this.currentTimerId = undefined;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
setThrottle(delayInMillis) {
|
|
233
|
+
if (!Number.isInteger(delayInMillis) || delayInMillis < 0) {
|
|
234
|
+
throw new Error('Throttle must be a non-negative integer');
|
|
235
|
+
}
|
|
236
|
+
this.throttle = delayInMillis;
|
|
237
|
+
this.logger.info(`stream-throttle-reset`, { delay: this.throttle, topic: this.topic });
|
|
238
|
+
}
|
|
239
|
+
async claimUnacknowledged(stream, group, consumer, idleTimeMs = this.reclaimDelay, limit = XPENDING_COUNT) {
|
|
240
|
+
let pendingMessages = [];
|
|
241
|
+
const pendingMessagesInfo = await this.stream.xpending(stream, group, '-', '+', limit); //[[ '1688768134881-0', 'testConsumer1', 1017, 1 ]]
|
|
242
|
+
for (const pendingMessageInfo of pendingMessagesInfo) {
|
|
243
|
+
if (Array.isArray(pendingMessageInfo)) {
|
|
244
|
+
const [id, , elapsedTimeMs, deliveryCount] = pendingMessageInfo;
|
|
245
|
+
if (elapsedTimeMs > idleTimeMs) {
|
|
246
|
+
const reclaimedMessage = await this.stream.xclaim(stream, group, consumer, idleTimeMs, id);
|
|
247
|
+
if (reclaimedMessage.length) {
|
|
248
|
+
if (deliveryCount <= this.reclaimCount) {
|
|
249
|
+
pendingMessages = pendingMessages.concat(reclaimedMessage);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
await this.expireUnacknowledged(reclaimedMessage, stream, group, consumer, id, deliveryCount);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return pendingMessages;
|
|
259
|
+
}
|
|
260
|
+
async expireUnacknowledged(reclaimedMessage, stream, group, consumer, id, count) {
|
|
261
|
+
//The stream activity was not processed within established limits. Possibilities Include:
|
|
262
|
+
// 1) user error: the workers were not properly configured and are timing out
|
|
263
|
+
// 2a) system error: JSON is corrupt
|
|
264
|
+
// i) bad/unwitting actor
|
|
265
|
+
// ii) corrupt hardware/network/transport/etc
|
|
266
|
+
// 3b) system error: Redis unable to accept `xadd` request
|
|
267
|
+
// 4c) system error: Redis unable to accept `xdel`/`xack` request
|
|
268
|
+
this.logger.error('stream-message-max-delivery-count-exceeded', { id, stream, group, consumer, code: SYSTEM_STATUS_CODE, count });
|
|
269
|
+
const streamData = reclaimedMessage[0]?.[1]?.[1];
|
|
270
|
+
//fatal risk point 1 of 3): json is corrupt
|
|
271
|
+
const [err, input] = this.parseStreamData(streamData);
|
|
272
|
+
if (err) {
|
|
273
|
+
return this.logger.error('expire-unacknowledged-parse-fatal-error', { id, err });
|
|
274
|
+
}
|
|
275
|
+
else if (!input || !input.metadata) {
|
|
276
|
+
return this.logger.error('expire-unacknowledged-parse-fatal-error', { id });
|
|
277
|
+
}
|
|
278
|
+
let telemetry;
|
|
279
|
+
let messageId;
|
|
280
|
+
try {
|
|
281
|
+
telemetry = new TelemetryService(this.appId);
|
|
282
|
+
telemetry.startStreamSpan(input, StreamRole.SYSTEM);
|
|
283
|
+
telemetry.setStreamError(`Stream Message Max Delivery Count Exceeded`);
|
|
284
|
+
//fatal risk point 2 of 3): unable to publish error message (to notify the parent job)
|
|
285
|
+
const output = this.structureUnacknowledgedError(input);
|
|
286
|
+
messageId = await this.publishResponse(input, output);
|
|
287
|
+
telemetry.setStreamAttributes({ 'app.worker.mid': messageId });
|
|
288
|
+
//fatal risk point 3 of 3): unable to ack and delete stream message
|
|
289
|
+
await this.ackAndDelete(stream, group, id);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
if (messageId) {
|
|
293
|
+
this.logger.error('expire-unacknowledged-pub-fatal-error', { id, err, ...input.metadata });
|
|
294
|
+
telemetry.setStreamAttributes({ 'app.system.fatal': 'expire-unacknowledged-pub-fatal-error' });
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
this.logger.error('expire-unacknowledged-ack-fatal-error', { id, err, ...input.metadata });
|
|
298
|
+
telemetry.setStreamAttributes({ 'app.system.fatal': 'expire-unacknowledged-ack-fatal-error' });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
telemetry.endStreamSpan();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
parseStreamData(str) {
|
|
306
|
+
try {
|
|
307
|
+
return [, JSON.parse(str)];
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
return [e];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
StreamSignaler.signalers = new Set();
|
|
315
|
+
export { StreamSignaler };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cache is a key/value store and used to store commonly accessed Redis metadata
|
|
3
|
+
* (mainly the execution rules for the app) to save time accessing them as they
|
|
4
|
+
* are immutable per verison. The only time the rules are ejected are when
|
|
5
|
+
* a new version is deployed to the quorum and the cache is invalidated/cleared.
|
|
6
|
+
*/
|
|
7
|
+
import { ActivityType } from "../../types/activity";
|
|
8
|
+
import { HookRule } from "../../types/hook";
|
|
9
|
+
import { HotMeshApp, HotMeshSettings } from "../../types/hotmesh";
|
|
10
|
+
import { Symbols } from "../../types/serializer";
|
|
11
|
+
import { Transitions } from "../../types/transition";
|
|
12
|
+
declare class Cache {
|
|
13
|
+
settings: HotMeshSettings;
|
|
14
|
+
appId: string;
|
|
15
|
+
apps: Record<string, HotMeshApp>;
|
|
16
|
+
schemas: Record<string, ActivityType>;
|
|
17
|
+
subscriptions: Record<string, Record<string, string>>;
|
|
18
|
+
symbols: Record<string, Symbols>;
|
|
19
|
+
symvals: Record<string, Symbols>;
|
|
20
|
+
transitions: Record<string, Record<string, unknown>>;
|
|
21
|
+
hookRules: Record<string, Record<string, HookRule[]>>;
|
|
22
|
+
workItems: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
|
|
25
|
+
* @param settings
|
|
26
|
+
* @param apps
|
|
27
|
+
* @param schemas
|
|
28
|
+
* @param subscriptions
|
|
29
|
+
* @param transitions
|
|
30
|
+
* @param hookRules
|
|
31
|
+
*/
|
|
32
|
+
constructor(appId: string, settings: HotMeshSettings, apps?: Record<string, HotMeshApp>, schemas?: Record<string, ActivityType>, subscriptions?: Record<string, Record<string, string>>, symbols?: Record<string, Symbols>, symvals?: Record<string, Symbols>, transitions?: Record<string, Record<string, unknown>>, hookRules?: Record<string, Record<string, HookRule[]>>, workItems?: Record<string, string>);
|
|
33
|
+
/**
|
|
34
|
+
* invalidate the cache; settings are not invalidated!
|
|
35
|
+
*/
|
|
36
|
+
invalidate(): void;
|
|
37
|
+
getSettings(): HotMeshSettings;
|
|
38
|
+
setSettings(settings: HotMeshSettings): void;
|
|
39
|
+
getApps(): Record<string, HotMeshApp>;
|
|
40
|
+
getApp(appId: string): HotMeshApp;
|
|
41
|
+
setApps(apps: Record<string, HotMeshApp>): void;
|
|
42
|
+
setApp(appId: string, app: HotMeshApp): void;
|
|
43
|
+
getSchemas(appId: string, version: string): Record<string, ActivityType>;
|
|
44
|
+
getSchema(appId: string, version: string, activityId: string): ActivityType;
|
|
45
|
+
setSchemas(appId: string, version: string, schemas: Record<string, ActivityType>): void;
|
|
46
|
+
setSchema(appId: string, version: string, activityId: string, schema: ActivityType): void;
|
|
47
|
+
getSubscriptions(appId: string, version: string): Record<string, string>;
|
|
48
|
+
getSubscription(appId: string, version: string, topic: string): unknown;
|
|
49
|
+
setSubscriptions(appId: string, version: string, subscriptions: Record<string, string>): void;
|
|
50
|
+
getSymbols(appId: string, targetEntityId: string): Symbols;
|
|
51
|
+
setSymbols(appId: string, targetEntityId: string, symbols: Symbols): void;
|
|
52
|
+
deleteSymbols(appId: string, targetEntityId: string): void;
|
|
53
|
+
getSymbolValues(appId: string): Symbols;
|
|
54
|
+
setSymbolValues(appId: string, symvals: Symbols): void;
|
|
55
|
+
deleteSymbolValues(appId: string): void;
|
|
56
|
+
getTransitions(appId: string, version: string): Transitions;
|
|
57
|
+
setTransitions(appId: string, version: string, transitions: Transitions): void;
|
|
58
|
+
getHookRules(appId: string): Record<string, HookRule[]>;
|
|
59
|
+
setHookRules(appId: string, hookRules: Record<string, HookRule[]>): void;
|
|
60
|
+
getSignals(appId: string, version: string): Record<string, unknown>;
|
|
61
|
+
setSignals(appId: string, version: string): Record<string, unknown>;
|
|
62
|
+
getActiveTaskQueue(appId: string): string;
|
|
63
|
+
setWorkItem(appId: string, workItem: string): void;
|
|
64
|
+
removeWorkItem(appId: string): void;
|
|
65
|
+
}
|
|
66
|
+
export { Cache };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cache is a key/value store and used to store commonly accessed Redis metadata
|
|
3
|
+
* (mainly the execution rules for the app) to save time accessing them as they
|
|
4
|
+
* are immutable per verison. The only time the rules are ejected are when
|
|
5
|
+
* a new version is deployed to the quorum and the cache is invalidated/cleared.
|
|
6
|
+
*/
|
|
7
|
+
class Cache {
|
|
8
|
+
/**
|
|
9
|
+
* The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
|
|
10
|
+
* @param settings
|
|
11
|
+
* @param apps
|
|
12
|
+
* @param schemas
|
|
13
|
+
* @param subscriptions
|
|
14
|
+
* @param transitions
|
|
15
|
+
* @param hookRules
|
|
16
|
+
*/
|
|
17
|
+
constructor(appId, settings, apps = {}, schemas = {}, subscriptions = {}, symbols = {}, symvals = {}, transitions = {}, hookRules = {}, workItems = {}) {
|
|
18
|
+
this.appId = appId;
|
|
19
|
+
this.settings = settings;
|
|
20
|
+
this.apps = apps;
|
|
21
|
+
this.schemas = schemas;
|
|
22
|
+
this.subscriptions = subscriptions;
|
|
23
|
+
this.symbols = symbols;
|
|
24
|
+
this.symvals = symvals;
|
|
25
|
+
this.transitions = transitions;
|
|
26
|
+
this.hookRules = hookRules;
|
|
27
|
+
this.workItems = workItems;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* invalidate the cache; settings are not invalidated!
|
|
31
|
+
*/
|
|
32
|
+
invalidate() {
|
|
33
|
+
this.apps = {};
|
|
34
|
+
this.schemas = {};
|
|
35
|
+
this.subscriptions = {};
|
|
36
|
+
this.transitions = {};
|
|
37
|
+
this.hookRules = {};
|
|
38
|
+
}
|
|
39
|
+
getSettings() {
|
|
40
|
+
return this.settings;
|
|
41
|
+
}
|
|
42
|
+
setSettings(settings) {
|
|
43
|
+
this.settings = settings;
|
|
44
|
+
}
|
|
45
|
+
getApps() {
|
|
46
|
+
return this.apps;
|
|
47
|
+
}
|
|
48
|
+
getApp(appId) {
|
|
49
|
+
return this.apps[appId];
|
|
50
|
+
}
|
|
51
|
+
setApps(apps) {
|
|
52
|
+
this.apps = apps;
|
|
53
|
+
}
|
|
54
|
+
setApp(appId, app) {
|
|
55
|
+
this.apps[appId] = app;
|
|
56
|
+
}
|
|
57
|
+
getSchemas(appId, version) {
|
|
58
|
+
return this.schemas[`${appId}/${version}`];
|
|
59
|
+
}
|
|
60
|
+
getSchema(appId, version, activityId) {
|
|
61
|
+
return this.schemas?.[`${appId}/${version}`]?.[activityId];
|
|
62
|
+
}
|
|
63
|
+
setSchemas(appId, version, schemas) {
|
|
64
|
+
this.schemas[`${appId}/${version}`] = schemas;
|
|
65
|
+
}
|
|
66
|
+
setSchema(appId, version, activityId, schema) {
|
|
67
|
+
this.schemas[`${appId}/${version}`][activityId] = schema;
|
|
68
|
+
}
|
|
69
|
+
getSubscriptions(appId, version) {
|
|
70
|
+
return this.subscriptions[`${appId}/${version}`];
|
|
71
|
+
}
|
|
72
|
+
getSubscription(appId, version, topic) {
|
|
73
|
+
return this.subscriptions?.[`${appId}/${version}`]?.[topic];
|
|
74
|
+
}
|
|
75
|
+
setSubscriptions(appId, version, subscriptions) {
|
|
76
|
+
this.subscriptions[`${appId}/${version}`] = subscriptions;
|
|
77
|
+
}
|
|
78
|
+
getSymbols(appId, targetEntityId) {
|
|
79
|
+
return this.symbols[`${appId}/${targetEntityId}`];
|
|
80
|
+
}
|
|
81
|
+
setSymbols(appId, targetEntityId, symbols) {
|
|
82
|
+
this.symbols[`${appId}/${targetEntityId}`] = symbols;
|
|
83
|
+
}
|
|
84
|
+
deleteSymbols(appId, targetEntityId) {
|
|
85
|
+
delete this.symbols[`${appId}/${targetEntityId}`];
|
|
86
|
+
}
|
|
87
|
+
getSymbolValues(appId) {
|
|
88
|
+
return this.symvals[`${appId}`];
|
|
89
|
+
}
|
|
90
|
+
setSymbolValues(appId, symvals) {
|
|
91
|
+
this.symvals[`${appId}`] = symvals;
|
|
92
|
+
}
|
|
93
|
+
deleteSymbolValues(appId) {
|
|
94
|
+
delete this.symvals[`${appId}`];
|
|
95
|
+
}
|
|
96
|
+
getTransitions(appId, version) {
|
|
97
|
+
return this.transitions[`${appId}/${version}`];
|
|
98
|
+
}
|
|
99
|
+
setTransitions(appId, version, transitions) {
|
|
100
|
+
this.transitions[`${appId}/${version}`] = transitions;
|
|
101
|
+
}
|
|
102
|
+
getHookRules(appId) {
|
|
103
|
+
return this.hookRules[`${appId}`];
|
|
104
|
+
}
|
|
105
|
+
setHookRules(appId, hookRules) {
|
|
106
|
+
this.hookRules[`${appId}`] = hookRules;
|
|
107
|
+
}
|
|
108
|
+
getSignals(appId, version) {
|
|
109
|
+
throw new Error("SIGNAL (getHooks) is not supported");
|
|
110
|
+
}
|
|
111
|
+
setSignals(appId, version) {
|
|
112
|
+
throw new Error("SIGNAL (setHook) is not supported");
|
|
113
|
+
}
|
|
114
|
+
getActiveTaskQueue(appId) {
|
|
115
|
+
return this.workItems[appId];
|
|
116
|
+
}
|
|
117
|
+
setWorkItem(appId, workItem) {
|
|
118
|
+
this.workItems[appId] = workItem;
|
|
119
|
+
}
|
|
120
|
+
removeWorkItem(appId) {
|
|
121
|
+
delete this.workItems[appId];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export { Cache };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { KeyType } from '../../../modules/key';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { SerializerService as Serializer } from '../../serializer';
|
|
4
|
+
import { Cache } from '../cache';
|
|
5
|
+
import { StoreService } from '../index';
|
|
6
|
+
import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
|
|
7
|
+
import { ReclaimedMessageType } from '../../../types/stream';
|
|
8
|
+
declare class IORedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
|
|
9
|
+
redisClient: RedisClientType;
|
|
10
|
+
cache: Cache;
|
|
11
|
+
namespace: string;
|
|
12
|
+
appId: string;
|
|
13
|
+
logger: ILogger;
|
|
14
|
+
serializer: Serializer;
|
|
15
|
+
constructor(redisClient: RedisClientType);
|
|
16
|
+
getMulti(): RedisMultiType;
|
|
17
|
+
hGetAllResult(result: any): any;
|
|
18
|
+
addTaskQueues(keys: string[]): Promise<void>;
|
|
19
|
+
publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
|
|
20
|
+
xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
|
|
21
|
+
xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType>;
|
|
22
|
+
xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
|
|
23
|
+
xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
|
|
24
|
+
xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
25
|
+
xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
26
|
+
}
|
|
27
|
+
export { IORedisStoreService };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { KeyType } from '../../../modules/key';
|
|
2
|
+
import { StoreService } from '../index';
|
|
3
|
+
class IORedisStoreService extends StoreService {
|
|
4
|
+
constructor(redisClient) {
|
|
5
|
+
super(redisClient);
|
|
6
|
+
}
|
|
7
|
+
getMulti() {
|
|
8
|
+
return this.redisClient.multi();
|
|
9
|
+
}
|
|
10
|
+
hGetAllResult(result) {
|
|
11
|
+
//ioredis response signature is [null, {}] or [null, null]
|
|
12
|
+
return result[1];
|
|
13
|
+
}
|
|
14
|
+
async addTaskQueues(keys) {
|
|
15
|
+
const multi = this.redisClient.multi();
|
|
16
|
+
const zsetKey = this.mintKey(KeyType.WORK_ITEMS, { appId: this.appId });
|
|
17
|
+
for (const key of keys) {
|
|
18
|
+
multi.zadd(zsetKey, 'NX', Date.now(), key);
|
|
19
|
+
}
|
|
20
|
+
await multi.exec();
|
|
21
|
+
}
|
|
22
|
+
async publish(keyType, message, appId, engineId) {
|
|
23
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
24
|
+
const status = await this.redisClient.publish(topic, JSON.stringify(message));
|
|
25
|
+
return status === 1;
|
|
26
|
+
}
|
|
27
|
+
async xgroup(command, key, groupName, id, mkStream) {
|
|
28
|
+
if (mkStream === 'MKSTREAM') {
|
|
29
|
+
try {
|
|
30
|
+
return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
this.logger.info(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
try {
|
|
39
|
+
return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
this.logger.info(`Consumer group not created for key: ${key} and group: ${groupName}`);
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async xadd(key, id, messageId, messageValue, multi) {
|
|
48
|
+
try {
|
|
49
|
+
return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async xpending(key, group, start, end, count, consumer) {
|
|
57
|
+
try {
|
|
58
|
+
return await this.redisClient.xpending(key, group, start, end, count, consumer);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, err);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async xclaim(key, group, consumer, minIdleTime, id, ...args) {
|
|
66
|
+
try {
|
|
67
|
+
return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async xack(key, group, id, multi) {
|
|
75
|
+
try {
|
|
76
|
+
return await (multi || this.redisClient).xack(key, group, id);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async xdel(key, id, multi) {
|
|
84
|
+
try {
|
|
85
|
+
return await (multi || this.redisClient).xdel(key, id);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, err);
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export { IORedisStoreService };
|