@hotmeshio/hotmesh 0.0.4 → 0.0.6
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 +2 -2
- package/build/{package.json → cjs/package.json} +12 -5
- package/build/{services → cjs/services}/activities/trigger.js +2 -2
- package/build/{services → cjs/services}/connector/index.js +3 -3
- 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/worker.d.ts +1 -0
- package/build/{services → cjs/services}/durable/worker.js +13 -3
- package/build/{services → cjs/services}/hotmesh/index.js +2 -2
- package/build/{services → cjs/services}/mapper/index.d.ts +3 -3
- package/build/{services → cjs/services}/store/index.js +1 -1
- 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 +37 -0
- package/build/esm/services/durable/worker.js +268 -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 +1 -1
- package/services/activities/trigger.ts +2 -2
- package/services/connector/index.ts +3 -3
- package/services/durable/client.ts +2 -2
- package/services/durable/connection.ts +2 -2
- package/services/durable/worker.ts +13 -3
- package/services/hotmesh/index.ts +2 -2
- package/services/mapper/index.ts +6 -7
- package/services/store/index.ts +3 -3
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +9 -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/activity.d.ts +0 -0
- package/build/{services → cjs/services}/activities/activity.js +1 -1
- /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}/activities/worker.js +0 -0
- /package/build/{services → cjs/services}/collator/index.d.ts +0 -0
- /package/build/{services → cjs/services}/collator/index.js +0 -0
- /package/build/{services → cjs/services}/compiler/deployer.d.ts +0 -0
- /package/build/{services → cjs/services}/compiler/deployer.js +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.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.d.ts +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/workflow.d.ts +0 -0
- /package/build/{services → cjs/services}/durable/workflow.js +0 -0
- /package/build/{services → cjs/services}/engine/index.d.ts +0 -0
- /package/build/{services → cjs/services}/engine/index.js +0 -0
- /package/build/{services → cjs/services}/hotmesh/index.d.ts +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}/serializer/index.d.ts +0 -0
- /package/build/{services → cjs/services}/serializer/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}/signaler/stream.js +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}/store/index.d.ts +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.d.ts +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,112 @@
|
|
|
1
|
+
import { KeyService, PSNS } from '../../../modules/key';
|
|
2
|
+
import { StreamService } from '../index';
|
|
3
|
+
class IORedisStreamService extends StreamService {
|
|
4
|
+
constructor(redisClient) {
|
|
5
|
+
super(redisClient);
|
|
6
|
+
}
|
|
7
|
+
async init(namespace = PSNS, appId, logger) {
|
|
8
|
+
this.namespace = namespace;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.appId = appId;
|
|
11
|
+
}
|
|
12
|
+
getMulti() {
|
|
13
|
+
return this.redisClient.multi();
|
|
14
|
+
}
|
|
15
|
+
mintKey(type, params) {
|
|
16
|
+
if (!this.namespace)
|
|
17
|
+
throw new Error('namespace not set');
|
|
18
|
+
return KeyService.mintKey(this.namespace, type, params);
|
|
19
|
+
}
|
|
20
|
+
async xgroup(command, key, groupName, id, mkStream) {
|
|
21
|
+
if (mkStream === 'MKSTREAM') {
|
|
22
|
+
try {
|
|
23
|
+
return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
this.logger.info(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
try {
|
|
32
|
+
return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
this.logger.info(`Consumer group not created for key: ${key} and group: ${groupName}`);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async xadd(key, id, messageId, messageValue, multi) {
|
|
41
|
+
try {
|
|
42
|
+
return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async xreadgroup(command, groupName, consumerName, blockOption, blockTime, streamsOption, streamName, id) {
|
|
50
|
+
try {
|
|
51
|
+
//@ts-ignore
|
|
52
|
+
return await this.redisClient.xreadgroup(command, groupName, consumerName,
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
blockOption, blockTime, streamsOption, streamName, id);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
this.logger.error(`Error reading stream data [Stream ${streamName}] [Group ${groupName}]`, err);
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async xpending(key, group, start, end, count, consumer) {
|
|
62
|
+
try {
|
|
63
|
+
const args = [key, group];
|
|
64
|
+
if (start)
|
|
65
|
+
args.push(start);
|
|
66
|
+
if (end)
|
|
67
|
+
args.push(end);
|
|
68
|
+
if (count !== undefined)
|
|
69
|
+
args.push(count.toString());
|
|
70
|
+
if (consumer)
|
|
71
|
+
args.push(consumer);
|
|
72
|
+
try {
|
|
73
|
+
return await this.redisClient.call('XPENDING', ...args);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this.logger.error('err, args', err, args);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, err);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async xclaim(key, group, consumer, minIdleTime, id, ...args) {
|
|
85
|
+
try {
|
|
86
|
+
return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async xack(key, group, id, multi) {
|
|
94
|
+
try {
|
|
95
|
+
return await (multi || this.redisClient).xack(key, group, id);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async xdel(key, id, multi) {
|
|
103
|
+
try {
|
|
104
|
+
return await (multi || this.redisClient).xdel(key, id);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, err);
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export { IORedisStreamService };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { KeyStoreParams, KeyType } from '../../../modules/key';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { StreamService } from '../index';
|
|
4
|
+
import { RedisClientType, RedisMultiType } from '../../../types/redisclient';
|
|
5
|
+
import { ReclaimedMessageType } from '../../../types/stream';
|
|
6
|
+
declare class RedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
|
|
7
|
+
redisClient: RedisClientType;
|
|
8
|
+
namespace: string;
|
|
9
|
+
logger: ILogger;
|
|
10
|
+
appId: string;
|
|
11
|
+
constructor(redisClient: RedisClientType);
|
|
12
|
+
init(namespace: string, appId: string, logger: ILogger): Promise<void>;
|
|
13
|
+
getMulti(): RedisMultiType;
|
|
14
|
+
mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
15
|
+
xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
|
|
16
|
+
xadd(key: string, id: string, ...args: any[]): Promise<string | RedisMultiType>;
|
|
17
|
+
xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: 'BLOCK' | 'COUNT', blockTime: number | string, streamsOption: 'STREAMS', streamName: string, id: string): Promise<string[][][] | null>;
|
|
18
|
+
xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number]>;
|
|
19
|
+
xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
|
|
20
|
+
xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
21
|
+
xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
22
|
+
}
|
|
23
|
+
export { RedisStreamService };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { KeyService, PSNS } from '../../../modules/key';
|
|
2
|
+
import { StreamService } from '../index';
|
|
3
|
+
class RedisStreamService extends StreamService {
|
|
4
|
+
constructor(redisClient) {
|
|
5
|
+
super(redisClient);
|
|
6
|
+
}
|
|
7
|
+
async init(namespace = PSNS, appId, logger) {
|
|
8
|
+
this.namespace = namespace;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.appId = appId;
|
|
11
|
+
}
|
|
12
|
+
getMulti() {
|
|
13
|
+
return this.redisClient.MULTI();
|
|
14
|
+
}
|
|
15
|
+
mintKey(type, params) {
|
|
16
|
+
if (!this.namespace)
|
|
17
|
+
throw new Error('namespace not set');
|
|
18
|
+
return KeyService.mintKey(this.namespace, type, params);
|
|
19
|
+
}
|
|
20
|
+
async xgroup(command, key, groupName, id, mkStream) {
|
|
21
|
+
const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
|
|
22
|
+
try {
|
|
23
|
+
return (await this.redisClient.sendCommand(['XGROUP', 'CREATE', key, groupName, id, ...args])) === 1;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
|
|
27
|
+
this.logger.error(`x-group-error ${streamType} for key: ${key} and group: ${groupName}`, err);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async xadd(key, id, ...args) {
|
|
32
|
+
let multi;
|
|
33
|
+
if (typeof args[args.length - 1] !== 'string') {
|
|
34
|
+
multi = args.pop();
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return await (multi || this.redisClient).XADD(key, id, { [args[0]]: args[1] });
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async xreadgroup(command, groupName, consumerName, blockOption, blockTime, streamsOption, streamName, id) {
|
|
45
|
+
try {
|
|
46
|
+
return await this.redisClient.sendCommand(['XREADGROUP', command, groupName, consumerName, blockOption, blockTime.toString(), streamsOption, streamName, id]);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
this.logger.error(`Error in reading data from group: ${groupName} in stream: ${streamName}`, err);
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async xpending(key, group, start, end, count, consumer) {
|
|
54
|
+
try {
|
|
55
|
+
const args = [key, group];
|
|
56
|
+
if (start)
|
|
57
|
+
args.push(start);
|
|
58
|
+
if (end)
|
|
59
|
+
args.push(end);
|
|
60
|
+
if (count !== undefined)
|
|
61
|
+
args.push(count.toString());
|
|
62
|
+
if (consumer)
|
|
63
|
+
args.push(consumer);
|
|
64
|
+
try {
|
|
65
|
+
return await this.redisClient.sendCommand(['XPENDING', ...args]);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
this.logger.error('err, args', err, args);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
this.logger.error(`Error in retrieving pending messages for group: ${group} in key: ${key}`, err);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async xclaim(key, group, consumer, minIdleTime, id, ...args) {
|
|
77
|
+
try {
|
|
78
|
+
return await this.redisClient.sendCommand(['XCLAIM', key, group, consumer, minIdleTime.toString(), id, ...args]);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async xack(key, group, id, multi) {
|
|
86
|
+
try {
|
|
87
|
+
if (multi) {
|
|
88
|
+
multi.XACK(key, group, id);
|
|
89
|
+
return multi;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return await this.redisClient.XACK(key, group, id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async xdel(key, id, multi) {
|
|
101
|
+
try {
|
|
102
|
+
if (multi) {
|
|
103
|
+
multi.XDEL(key, id);
|
|
104
|
+
return multi;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return await this.redisClient.XDEL(key, id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
this.logger.error(`Error in deleting messages with ids: ${id} for key: ${key}`, err);
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export { RedisStreamService };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { KeyStoreParams, KeyType } from '../../modules/key';
|
|
2
|
+
import { ReclaimedMessageType } from '../../types/stream';
|
|
3
|
+
import { ILogger } from '../logger';
|
|
4
|
+
declare abstract class StreamService<T, U> {
|
|
5
|
+
redisClient: T;
|
|
6
|
+
namespace: string;
|
|
7
|
+
logger: ILogger;
|
|
8
|
+
appId: string;
|
|
9
|
+
constructor(redisClient: T);
|
|
10
|
+
abstract init(namespace: string, appId: string, logger: ILogger): Promise<void>;
|
|
11
|
+
abstract getMulti(): U;
|
|
12
|
+
abstract mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
13
|
+
abstract xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
|
|
14
|
+
abstract xadd(key: string, id: string, messageId: string, messageValue: string, multi?: U): Promise<string | U>;
|
|
15
|
+
abstract xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: 'BLOCK' | 'COUNT', blockTime: number | string, streamsOption: 'STREAMS', streamName: string, id: string): Promise<string[][][] | null | unknown[]>;
|
|
16
|
+
abstract xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
|
|
17
|
+
abstract xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
|
|
18
|
+
abstract xack(key: string, group: string, id: string, multi?: U): Promise<number | U>;
|
|
19
|
+
abstract xdel(key: string, id: string, multi?: U): Promise<number | U>;
|
|
20
|
+
}
|
|
21
|
+
export { StreamService };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KeyStoreParams, KeyType } from '../../../modules/key';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { SubService } from '../index';
|
|
4
|
+
import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
|
|
5
|
+
import { SubscriptionCallback } from '../../../types/quorum';
|
|
6
|
+
declare class IORedisSubService extends SubService<RedisClientType, RedisMultiType> {
|
|
7
|
+
redisClient: RedisClientType;
|
|
8
|
+
namespace: string;
|
|
9
|
+
logger: ILogger;
|
|
10
|
+
appId: string;
|
|
11
|
+
constructor(redisClient: RedisClientType);
|
|
12
|
+
init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
|
|
13
|
+
getMulti(): RedisMultiType;
|
|
14
|
+
mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
15
|
+
subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
16
|
+
unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
17
|
+
psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
18
|
+
punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export { IORedisSubService };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { KeyService, PSNS } from '../../../modules/key';
|
|
2
|
+
import { SubService } from '../index';
|
|
3
|
+
class IORedisSubService extends SubService {
|
|
4
|
+
constructor(redisClient) {
|
|
5
|
+
super(redisClient);
|
|
6
|
+
}
|
|
7
|
+
async init(namespace = PSNS, appId, engineId, logger) {
|
|
8
|
+
this.namespace = namespace;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.appId = appId;
|
|
11
|
+
}
|
|
12
|
+
getMulti() {
|
|
13
|
+
return this.redisClient.multi();
|
|
14
|
+
}
|
|
15
|
+
mintKey(type, params) {
|
|
16
|
+
if (!this.namespace)
|
|
17
|
+
throw new Error('namespace not set');
|
|
18
|
+
return KeyService.mintKey(this.namespace, type, params);
|
|
19
|
+
}
|
|
20
|
+
async subscribe(keyType, callback, appId, engineId) {
|
|
21
|
+
const self = this;
|
|
22
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
23
|
+
await this.redisClient.subscribe(topic, (err) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
self.logger.error(`Error subscribing to: ${topic}`, err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.redisClient.on('message', (channel, message) => {
|
|
29
|
+
if (channel === topic) {
|
|
30
|
+
try {
|
|
31
|
+
const payload = JSON.parse(message);
|
|
32
|
+
callback(topic, payload);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
self.logger.error(`Error parsing message: ${message}`, e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async unsubscribe(keyType, appId, engineId) {
|
|
41
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
42
|
+
await this.redisClient.unsubscribe(topic);
|
|
43
|
+
}
|
|
44
|
+
async psubscribe(keyType, callback, appId, engineId) {
|
|
45
|
+
const self = this;
|
|
46
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
47
|
+
await this.redisClient.psubscribe(topic, (err) => {
|
|
48
|
+
if (err) {
|
|
49
|
+
self.logger.error(`Error subscribing to: ${topic}`, err);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
this.redisClient.on('pmessage', (pattern, channel, message) => {
|
|
53
|
+
if (pattern === topic) {
|
|
54
|
+
try {
|
|
55
|
+
const payload = JSON.parse(message);
|
|
56
|
+
callback(channel, payload);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
self.logger.error(`Error parsing message: ${message}`, e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async punsubscribe(keyType, appId, engineId) {
|
|
65
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
66
|
+
await this.redisClient.punsubscribe(topic);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export { IORedisSubService };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { KeyStoreParams, KeyType } from '../../../modules/key';
|
|
2
|
+
import { ILogger } from '../../logger';
|
|
3
|
+
import { SubService } from '../index';
|
|
4
|
+
import { RedisClientType, RedisMultiType } from '../../../types/redisclient';
|
|
5
|
+
import { SubscriptionCallback } from '../../../types/quorum';
|
|
6
|
+
declare class RedisSubService extends SubService<RedisClientType, RedisMultiType> {
|
|
7
|
+
redisClient: RedisClientType;
|
|
8
|
+
namespace: string;
|
|
9
|
+
logger: ILogger;
|
|
10
|
+
appId: string;
|
|
11
|
+
constructor(redisClient: RedisClientType);
|
|
12
|
+
init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
|
|
13
|
+
getMulti(): RedisMultiType;
|
|
14
|
+
mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
15
|
+
subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
16
|
+
unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
17
|
+
psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
18
|
+
punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export { RedisSubService };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { KeyService, PSNS } from '../../../modules/key';
|
|
2
|
+
import { SubService } from '../index';
|
|
3
|
+
class RedisSubService extends SubService {
|
|
4
|
+
constructor(redisClient) {
|
|
5
|
+
super(redisClient);
|
|
6
|
+
}
|
|
7
|
+
async init(namespace = PSNS, appId, engineId, logger) {
|
|
8
|
+
this.namespace = namespace;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.appId = appId;
|
|
11
|
+
}
|
|
12
|
+
getMulti() {
|
|
13
|
+
const multi = this.redisClient.MULTI();
|
|
14
|
+
return multi;
|
|
15
|
+
}
|
|
16
|
+
mintKey(type, params) {
|
|
17
|
+
if (!this.namespace)
|
|
18
|
+
throw new Error('namespace not set');
|
|
19
|
+
return KeyService.mintKey(this.namespace, type, params);
|
|
20
|
+
}
|
|
21
|
+
async subscribe(keyType, callback, appId, engineId) {
|
|
22
|
+
if (this.redisClient) {
|
|
23
|
+
const self = this;
|
|
24
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
25
|
+
await this.redisClient.subscribe(topic, (message) => {
|
|
26
|
+
try {
|
|
27
|
+
const payload = JSON.parse(message);
|
|
28
|
+
callback(topic, payload);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
self.logger.error(`Error parsing message: ${message}`, e);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async unsubscribe(keyType, appId, engineId) {
|
|
37
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
38
|
+
await this.redisClient.unsubscribe(topic);
|
|
39
|
+
}
|
|
40
|
+
async psubscribe(keyType, callback, appId, engineId) {
|
|
41
|
+
if (this.redisClient) {
|
|
42
|
+
const self = this;
|
|
43
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
44
|
+
await this.redisClient.pSubscribe(topic, (message, channel) => {
|
|
45
|
+
try {
|
|
46
|
+
const payload = JSON.parse(message);
|
|
47
|
+
callback(channel, payload);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
self.logger.error(`Error parsing message: ${message}`, e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async punsubscribe(keyType, appId, engineId) {
|
|
56
|
+
const topic = this.mintKey(keyType, { appId, engineId });
|
|
57
|
+
await this.redisClient.pUnsubscribe(topic);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export { RedisSubService };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KeyStoreParams, KeyType } from '../../modules/key';
|
|
2
|
+
import { ILogger } from '../logger';
|
|
3
|
+
import { SubscriptionCallback } from '../../types/quorum';
|
|
4
|
+
declare abstract class SubService<T, U> {
|
|
5
|
+
redisClient: T;
|
|
6
|
+
namespace: string;
|
|
7
|
+
logger: ILogger;
|
|
8
|
+
appId: string;
|
|
9
|
+
constructor(redisClient: T);
|
|
10
|
+
abstract init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
|
|
11
|
+
abstract getMulti(): U;
|
|
12
|
+
abstract mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
13
|
+
abstract subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
14
|
+
abstract unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
15
|
+
abstract psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
|
|
16
|
+
abstract punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export { SubService };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ILogger } from '../logger';
|
|
3
|
+
import { StoreService } from '../store';
|
|
4
|
+
import { RedisClient, RedisMulti } from '../../types/redis';
|
|
5
|
+
import { HookInterface } from '../../types/hook';
|
|
6
|
+
declare class TaskService {
|
|
7
|
+
store: StoreService<RedisClient, RedisMulti>;
|
|
8
|
+
logger: ILogger;
|
|
9
|
+
cleanupTimeout: NodeJS.Timeout | null;
|
|
10
|
+
constructor(store: StoreService<RedisClient, RedisMulti>, logger: ILogger);
|
|
11
|
+
processWebHooks(hookEventCallback: HookInterface): Promise<void>;
|
|
12
|
+
enqueueWorkItems(keys: string[]): Promise<void>;
|
|
13
|
+
registerJobForCleanup(jobId: string, inSeconds?: number): Promise<void>;
|
|
14
|
+
registerTimeHook(jobId: string, activityId: string, type: 'sleep' | 'expire' | 'cron', inSeconds?: number, multi?: RedisMulti): Promise<void>;
|
|
15
|
+
processTimeHooks(timeEventCallback: (jobId: string, activityId: string) => Promise<void>, listKey?: string): Promise<void>;
|
|
16
|
+
cancelCleanup(): void;
|
|
17
|
+
}
|
|
18
|
+
export { TaskService };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { XSleepFor, sleepFor } from '../../modules/utils';
|
|
2
|
+
//system timer granularity limit (task queues organize)
|
|
3
|
+
const FIDELITY_SECONDS = 15; //note: this can be reduced using 'watch' or scout role
|
|
4
|
+
//default resolution/fidelity when expiring
|
|
5
|
+
const EXPIRATION_FIDELITY_SECONDS = 60;
|
|
6
|
+
class TaskService {
|
|
7
|
+
constructor(store, logger) {
|
|
8
|
+
this.cleanupTimeout = null;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.store = store;
|
|
11
|
+
}
|
|
12
|
+
async processWebHooks(hookEventCallback) {
|
|
13
|
+
const workItemKey = await this.store.getActiveTaskQueue();
|
|
14
|
+
if (workItemKey) {
|
|
15
|
+
const [topic, sourceKey, ...sdata] = workItemKey.split('::');
|
|
16
|
+
const data = JSON.parse(sdata.join('::'));
|
|
17
|
+
const destinationKey = `${sourceKey}:processed`;
|
|
18
|
+
const jobId = await this.store.processTaskQueue(sourceKey, destinationKey);
|
|
19
|
+
if (jobId) {
|
|
20
|
+
await hookEventCallback(topic, { ...data, id: jobId });
|
|
21
|
+
//todo: do final checksum count (values are tracked in the stats hash)
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
await this.store.deleteProcessedTaskQueue(workItemKey, sourceKey, destinationKey);
|
|
25
|
+
}
|
|
26
|
+
setImmediate(() => this.processWebHooks(hookEventCallback));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async enqueueWorkItems(keys) {
|
|
30
|
+
await this.store.addTaskQueues(keys);
|
|
31
|
+
}
|
|
32
|
+
async registerJobForCleanup(jobId, inSeconds = EXPIRATION_FIDELITY_SECONDS) {
|
|
33
|
+
if (inSeconds > -1) {
|
|
34
|
+
await this.store.expireJob(jobId, inSeconds);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async registerTimeHook(jobId, activityId, type, inSeconds = FIDELITY_SECONDS, multi) {
|
|
38
|
+
const awakenTimeSlot = Math.floor((Date.now() + inSeconds * 1000) / (FIDELITY_SECONDS * 1000)) * (FIDELITY_SECONDS * 1000); //n second awaken groups
|
|
39
|
+
await this.store.registerTimeHook(jobId, activityId, type, awakenTimeSlot, multi);
|
|
40
|
+
}
|
|
41
|
+
//todo: need 'scout' role in quorum to check for this and then alert the quorum to get to work
|
|
42
|
+
async processTimeHooks(timeEventCallback, listKey) {
|
|
43
|
+
try {
|
|
44
|
+
const job = await this.store.getNextTimeJob(listKey);
|
|
45
|
+
if (job) {
|
|
46
|
+
const [listKey, jobId, activityId] = job;
|
|
47
|
+
await timeEventCallback(jobId, activityId);
|
|
48
|
+
await sleepFor(0);
|
|
49
|
+
this.processTimeHooks(timeEventCallback, listKey);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
let sleep = XSleepFor(FIDELITY_SECONDS * 1000);
|
|
53
|
+
this.cleanupTimeout = sleep.timerId;
|
|
54
|
+
await sleep.promise;
|
|
55
|
+
this.processTimeHooks(timeEventCallback);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
//todo: retry connect to redis
|
|
60
|
+
this.logger.error('task-process-timehooks-error', err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
cancelCleanup() {
|
|
64
|
+
if (this.cleanupTimeout !== undefined) {
|
|
65
|
+
clearTimeout(this.cleanupTimeout);
|
|
66
|
+
this.cleanupTimeout = undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export { TaskService };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ActivityMetadata, ActivityType, Consumes } from '../../types/activity';
|
|
2
|
+
import { JobState } from '../../types/job';
|
|
3
|
+
import { StringAnyType, StringScalarType, StringStringType } from '../../types/serializer';
|
|
4
|
+
import { StreamData, StreamRole } from '../../types/stream';
|
|
5
|
+
import { Span, Context } from '../../types/telemetry';
|
|
6
|
+
declare class TelemetryService {
|
|
7
|
+
span: Span;
|
|
8
|
+
jobSpan: Span;
|
|
9
|
+
config: ActivityType;
|
|
10
|
+
traceId: string | null;
|
|
11
|
+
spanId: string | null;
|
|
12
|
+
appId: string;
|
|
13
|
+
metadata: ActivityMetadata;
|
|
14
|
+
context: JobState;
|
|
15
|
+
leg: number;
|
|
16
|
+
constructor(appId: string, config?: ActivityType, metadata?: ActivityMetadata, context?: JobState);
|
|
17
|
+
getJobParentSpanId(): string | undefined;
|
|
18
|
+
getActivityParentSpanId(leg: number): string | undefined;
|
|
19
|
+
getTraceId(): string | undefined;
|
|
20
|
+
startJobSpan(): TelemetryService;
|
|
21
|
+
startActivitySpan(leg?: number): TelemetryService;
|
|
22
|
+
startStreamSpan(data: StreamData, role: StreamRole): TelemetryService;
|
|
23
|
+
startSpan(traceId: string, spanId: string, spanName: string, attributes: StringScalarType): Span;
|
|
24
|
+
mapActivityAttributes(): void;
|
|
25
|
+
setActivityAttributes(attributes: StringScalarType): void;
|
|
26
|
+
setStreamAttributes(attributes: StringScalarType): void;
|
|
27
|
+
setJobAttributes(attributes: StringScalarType): void;
|
|
28
|
+
endJobSpan(): void;
|
|
29
|
+
endActivitySpan(): void;
|
|
30
|
+
endStreamSpan(): void;
|
|
31
|
+
endSpan(span: Span): void;
|
|
32
|
+
getParentSpanContext(): undefined | Context;
|
|
33
|
+
getSpanAttrs(leg: number): StringAnyType;
|
|
34
|
+
getStreamSpanAttrs(input: StreamData): StringAnyType;
|
|
35
|
+
setTelemetryContext(span: Span, leg: number): void;
|
|
36
|
+
setActivityError(message: string): void;
|
|
37
|
+
setStreamError(message: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Adds the paths (HGET) necessary to restore telemetry state for an activity
|
|
40
|
+
* @param consumes
|
|
41
|
+
* @param config
|
|
42
|
+
* @param metadata
|
|
43
|
+
* @param leg
|
|
44
|
+
*/
|
|
45
|
+
static addTargetTelemetryPaths(consumes: Consumes, config: ActivityType, metadata: ActivityMetadata, leg: number): void;
|
|
46
|
+
static bindJobTelemetryToState(state: StringStringType, config: ActivityType, context: JobState): void;
|
|
47
|
+
static bindActivityTelemetryToState(state: StringAnyType, config: ActivityType, metadata: ActivityMetadata, context: JobState, leg: number): void;
|
|
48
|
+
}
|
|
49
|
+
export { TelemetryService };
|