@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,8 @@
|
|
|
1
|
+
import { HotMeshService as HotMesh } from '../hotmesh';
|
|
2
|
+
export declare class WorkflowHandleService {
|
|
3
|
+
hotMesh: HotMesh;
|
|
4
|
+
workflowTopic: string;
|
|
5
|
+
workflowId: string;
|
|
6
|
+
constructor(hotMesh: HotMesh, workflowTopic: string, workflowId: string);
|
|
7
|
+
result(): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class WorkflowHandleService {
|
|
2
|
+
constructor(hotMesh, workflowTopic, workflowId) {
|
|
3
|
+
this.workflowTopic = workflowTopic;
|
|
4
|
+
this.workflowId = workflowId;
|
|
5
|
+
this.hotMesh = hotMesh;
|
|
6
|
+
}
|
|
7
|
+
async result() {
|
|
8
|
+
let status = await this.hotMesh.getStatus(this.workflowId);
|
|
9
|
+
const topic = `${this.workflowTopic}.${this.workflowId}`;
|
|
10
|
+
if (status == 0) {
|
|
11
|
+
return (await this.hotMesh.getState(this.workflowTopic, this.workflowId)).data?.response;
|
|
12
|
+
}
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
let isResolved = false;
|
|
15
|
+
//common fulfill/unsubscribe
|
|
16
|
+
const complete = async (response) => {
|
|
17
|
+
if (isResolved)
|
|
18
|
+
return;
|
|
19
|
+
isResolved = true;
|
|
20
|
+
this.hotMesh.unsub(topic);
|
|
21
|
+
resolve(response || (await this.hotMesh.getState(this.workflowTopic, this.workflowId)).data?.response);
|
|
22
|
+
};
|
|
23
|
+
this.hotMesh.sub(topic, async (topic, message) => {
|
|
24
|
+
await complete(message.data?.response);
|
|
25
|
+
});
|
|
26
|
+
setTimeout(async () => {
|
|
27
|
+
status = await this.hotMesh.getStatus(this.workflowId);
|
|
28
|
+
if (status == 0) {
|
|
29
|
+
await complete();
|
|
30
|
+
}
|
|
31
|
+
}, 0);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ClientService } from './client';
|
|
2
|
+
import { ConnectionService } from './connection';
|
|
3
|
+
import { NativeConnectionService } from './native';
|
|
4
|
+
import { WorkerService } from './worker';
|
|
5
|
+
import { WorkflowService } from './workflow';
|
|
6
|
+
import { ContextType } from '../../types/durable';
|
|
7
|
+
/**
|
|
8
|
+
* As a durable integration platform, HotMesh
|
|
9
|
+
* can model and emulate other durable systems
|
|
10
|
+
* (like Temporal). As you review the code in
|
|
11
|
+
* this file, note the following:
|
|
12
|
+
*
|
|
13
|
+
* 1) There is no central governing server.
|
|
14
|
+
* HotMesh is a client-side SDK that connects to Redis
|
|
15
|
+
* using CQRS principles to implicitly drive
|
|
16
|
+
* orchestrations using a headless quorum. Stream
|
|
17
|
+
* semantics guarantee that all events are
|
|
18
|
+
* processed by the quorum of connected clients.
|
|
19
|
+
*
|
|
20
|
+
* 2) Every developer-defined `workflow` function
|
|
21
|
+
* is assigned a HotMesh workflow (which runs in
|
|
22
|
+
* the background) to support it.
|
|
23
|
+
*
|
|
24
|
+
* If the HotMesh workflow is not yet defined,
|
|
25
|
+
* it will be deployed and activated on-the-fly.
|
|
26
|
+
* (The generated DAG will have one Trigger Activity
|
|
27
|
+
* and one Worker Activity.) The Worker Activity
|
|
28
|
+
* is configured to catch execution errors and
|
|
29
|
+
* return them, using a 'pending' status to
|
|
30
|
+
* indicate that the workflow is still running.
|
|
31
|
+
* It is possible for workflow activities to throw
|
|
32
|
+
* errors that will force the entire workflow to
|
|
33
|
+
* fail. This is not the case here. The workflow will
|
|
34
|
+
* continue to run until it is completed or cancelled.
|
|
35
|
+
*
|
|
36
|
+
* 2) Every developer-defined `activity` function
|
|
37
|
+
* is assigned a HotMesh workflow (which runs in
|
|
38
|
+
* the background) to support it.
|
|
39
|
+
*
|
|
40
|
+
* (The generated DAG will have one Trigger Activity and one
|
|
41
|
+
* Worker Activity.) The JOB ID for Worker Activity executions
|
|
42
|
+
* is derived from the containing JOB ID,
|
|
43
|
+
* allowing Activity state to be 'replayed' when the workflow
|
|
44
|
+
* is run again. The Activity Function Runner (activity proxy)
|
|
45
|
+
* is configured similar to how the workflow worker is and will
|
|
46
|
+
* catch execution errors and return them to the caller, using a
|
|
47
|
+
* 'pending' status to indicate that the activity is still running.
|
|
48
|
+
* This allows the activity to be retried until it succeeds.
|
|
49
|
+
*/
|
|
50
|
+
export declare const Durable: {
|
|
51
|
+
Client: typeof ClientService;
|
|
52
|
+
Connection: typeof ConnectionService;
|
|
53
|
+
NativeConnection: typeof NativeConnectionService;
|
|
54
|
+
Worker: typeof WorkerService;
|
|
55
|
+
workflow: typeof WorkflowService;
|
|
56
|
+
};
|
|
57
|
+
export type { ContextType };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ClientService } from './client';
|
|
2
|
+
import { ConnectionService } from './connection';
|
|
3
|
+
import { NativeConnectionService } from './native';
|
|
4
|
+
import { WorkerService } from './worker';
|
|
5
|
+
import { WorkflowService } from './workflow';
|
|
6
|
+
/**
|
|
7
|
+
* As a durable integration platform, HotMesh
|
|
8
|
+
* can model and emulate other durable systems
|
|
9
|
+
* (like Temporal). As you review the code in
|
|
10
|
+
* this file, note the following:
|
|
11
|
+
*
|
|
12
|
+
* 1) There is no central governing server.
|
|
13
|
+
* HotMesh is a client-side SDK that connects to Redis
|
|
14
|
+
* using CQRS principles to implicitly drive
|
|
15
|
+
* orchestrations using a headless quorum. Stream
|
|
16
|
+
* semantics guarantee that all events are
|
|
17
|
+
* processed by the quorum of connected clients.
|
|
18
|
+
*
|
|
19
|
+
* 2) Every developer-defined `workflow` function
|
|
20
|
+
* is assigned a HotMesh workflow (which runs in
|
|
21
|
+
* the background) to support it.
|
|
22
|
+
*
|
|
23
|
+
* If the HotMesh workflow is not yet defined,
|
|
24
|
+
* it will be deployed and activated on-the-fly.
|
|
25
|
+
* (The generated DAG will have one Trigger Activity
|
|
26
|
+
* and one Worker Activity.) The Worker Activity
|
|
27
|
+
* is configured to catch execution errors and
|
|
28
|
+
* return them, using a 'pending' status to
|
|
29
|
+
* indicate that the workflow is still running.
|
|
30
|
+
* It is possible for workflow activities to throw
|
|
31
|
+
* errors that will force the entire workflow to
|
|
32
|
+
* fail. This is not the case here. The workflow will
|
|
33
|
+
* continue to run until it is completed or cancelled.
|
|
34
|
+
*
|
|
35
|
+
* 2) Every developer-defined `activity` function
|
|
36
|
+
* is assigned a HotMesh workflow (which runs in
|
|
37
|
+
* the background) to support it.
|
|
38
|
+
*
|
|
39
|
+
* (The generated DAG will have one Trigger Activity and one
|
|
40
|
+
* Worker Activity.) The JOB ID for Worker Activity executions
|
|
41
|
+
* is derived from the containing JOB ID,
|
|
42
|
+
* allowing Activity state to be 'replayed' when the workflow
|
|
43
|
+
* is run again. The Activity Function Runner (activity proxy)
|
|
44
|
+
* is configured similar to how the workflow worker is and will
|
|
45
|
+
* catch execution errors and return them to the caller, using a
|
|
46
|
+
* 'pending' status to indicate that the activity is still running.
|
|
47
|
+
* This allows the activity to be retried until it succeeds.
|
|
48
|
+
*/
|
|
49
|
+
export const Durable = {
|
|
50
|
+
Client: ClientService,
|
|
51
|
+
Connection: ConnectionService,
|
|
52
|
+
NativeConnection: NativeConnectionService,
|
|
53
|
+
Worker: WorkerService,
|
|
54
|
+
workflow: WorkflowService,
|
|
55
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Here is an example of how the methods in this file are used:
|
|
4
|
+
|
|
5
|
+
./worker.ts
|
|
6
|
+
|
|
7
|
+
import { Durable: { NativeConnection, Worker } } from '@hotmeshio/hotmesh';
|
|
8
|
+
import Redis from 'ioredis'; //OR `import * as Redis from 'redis';`
|
|
9
|
+
|
|
10
|
+
import * as activities from './activities';
|
|
11
|
+
|
|
12
|
+
async function run() {
|
|
13
|
+
const connection = await NativeConnection.connect({
|
|
14
|
+
class: Redis,
|
|
15
|
+
options: {
|
|
16
|
+
host: 'localhost',
|
|
17
|
+
port: 6379,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const worker = await Worker.create({
|
|
21
|
+
connection,
|
|
22
|
+
namespace: 'default',
|
|
23
|
+
taskQueue: 'hello-world',
|
|
24
|
+
workflowsPath: require.resolve('./workflows'),
|
|
25
|
+
activities,
|
|
26
|
+
});
|
|
27
|
+
await worker.run();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
run().catch((err) => {
|
|
31
|
+
console.error(err);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
*/
|
|
36
|
+
export class NativeConnectionService {
|
|
37
|
+
static async connect(config) {
|
|
38
|
+
return {
|
|
39
|
+
class: config.class,
|
|
40
|
+
options: { ...config.options },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HotMeshService as HotMesh } from '../hotmesh';
|
|
2
|
+
import { Connection, Registry, WorkerConfig } from "../../types/durable";
|
|
3
|
+
export declare class WorkerService {
|
|
4
|
+
static activityRegistry: Registry;
|
|
5
|
+
static connection: Connection;
|
|
6
|
+
static instances: Map<string, HotMesh | Promise<HotMesh>>;
|
|
7
|
+
workflowRunner: HotMesh;
|
|
8
|
+
static getHotMesh: (worflowTopic: string) => Promise<HotMesh>;
|
|
9
|
+
static activateWorkflow(hotMesh: HotMesh, topic: string, factory: Function): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* The `worker` calls `registerActivities` immediately BEFORE
|
|
12
|
+
* dynamically importing the user's workflow module. That file
|
|
13
|
+
* contains a call, `proxyActivities`, which needs this info.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: The `worker` and `client` both call `proxyActivities`,
|
|
16
|
+
* as a natural result of importing worflows.ts. However,
|
|
17
|
+
* because the worker imports the workflows dynamically AFTER
|
|
18
|
+
* the activities are loaded, there will be items in the registry,
|
|
19
|
+
* allowing proxyActivities to succeed.
|
|
20
|
+
*/
|
|
21
|
+
static registerActivities<ACT>(activities: ACT): Registry;
|
|
22
|
+
static create(config: WorkerConfig): Promise<WorkerService>;
|
|
23
|
+
static resolveWorkflowTarget(workflow: object | Function): [string, Function];
|
|
24
|
+
run(): Promise<void>;
|
|
25
|
+
initActivityWorkflow(config: WorkerConfig, activityTopic: string): Promise<HotMesh>;
|
|
26
|
+
wrapActivityFunctions(): Function;
|
|
27
|
+
activateActivityWorkflow(hotMesh: HotMesh, activityTopic: string): Promise<void>;
|
|
28
|
+
initWorkerWorkflow(config: WorkerConfig, workflowTopic: string, workflowFunction: Function): Promise<HotMesh>;
|
|
29
|
+
static Context: {
|
|
30
|
+
info: () => {
|
|
31
|
+
workflowId: string;
|
|
32
|
+
workflowTopic: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
wrapWorkflowFunction(workflowFunction: Function, workflowTopic: string): Function;
|
|
36
|
+
static shutdown(): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { asyncLocalStorage } from './asyncLocalStorage';
|
|
3
|
+
import { HotMeshService as HotMesh } from '../hotmesh';
|
|
4
|
+
import { StreamStatus } from '../../types/stream';
|
|
5
|
+
import { getWorkflowYAML, getActivityYAML } from './factory';
|
|
6
|
+
/*
|
|
7
|
+
Here is an example of how the methods in this file are used:
|
|
8
|
+
|
|
9
|
+
./worker.ts
|
|
10
|
+
|
|
11
|
+
import { Durable: { NativeConnection, Worker } } from '@hotmeshio/hotmesh';
|
|
12
|
+
import Redis from 'ioredis'; //OR `import * as Redis from 'redis';`
|
|
13
|
+
|
|
14
|
+
import * as activities from './activities';
|
|
15
|
+
|
|
16
|
+
async function run() {
|
|
17
|
+
const connection = await NativeConnection.connect({
|
|
18
|
+
class: Redis,
|
|
19
|
+
options: {
|
|
20
|
+
host: 'localhost',
|
|
21
|
+
port: 6379,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const worker = await Worker.create({
|
|
25
|
+
connection,
|
|
26
|
+
namespace: 'default',
|
|
27
|
+
taskQueue: 'hello-world',
|
|
28
|
+
workflowsPath: require.resolve('./workflows'),
|
|
29
|
+
activities,
|
|
30
|
+
});
|
|
31
|
+
await worker.run();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
run().catch((err) => {
|
|
35
|
+
console.error(err);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
*/
|
|
39
|
+
class WorkerService {
|
|
40
|
+
static async activateWorkflow(hotMesh, topic, factory) {
|
|
41
|
+
const version = '1';
|
|
42
|
+
const app = await hotMesh.engine.store.getApp(topic);
|
|
43
|
+
const appVersion = app?.version;
|
|
44
|
+
if (!appVersion) {
|
|
45
|
+
try {
|
|
46
|
+
await hotMesh.deploy(factory(topic, version));
|
|
47
|
+
await hotMesh.activate(version);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
hotMesh.engine.logger.error('durable-worker-deploy-activate-err', err);
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (app && !app.active) {
|
|
55
|
+
try {
|
|
56
|
+
await hotMesh.activate(version);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
hotMesh.engine.logger.error('durable-worker-activate-err', err);
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The `worker` calls `registerActivities` immediately BEFORE
|
|
66
|
+
* dynamically importing the user's workflow module. That file
|
|
67
|
+
* contains a call, `proxyActivities`, which needs this info.
|
|
68
|
+
*
|
|
69
|
+
* NOTE: The `worker` and `client` both call `proxyActivities`,
|
|
70
|
+
* as a natural result of importing worflows.ts. However,
|
|
71
|
+
* because the worker imports the workflows dynamically AFTER
|
|
72
|
+
* the activities are loaded, there will be items in the registry,
|
|
73
|
+
* allowing proxyActivities to succeed.
|
|
74
|
+
*/
|
|
75
|
+
static registerActivities(activities) {
|
|
76
|
+
Object.keys(activities).forEach(key => {
|
|
77
|
+
WorkerService.activityRegistry[key] = activities[key];
|
|
78
|
+
});
|
|
79
|
+
return WorkerService.activityRegistry;
|
|
80
|
+
}
|
|
81
|
+
static async create(config) {
|
|
82
|
+
WorkerService.connection = config.connection;
|
|
83
|
+
//pre-cache user activity functions
|
|
84
|
+
WorkerService.registerActivities(config.activities);
|
|
85
|
+
//import the user's workflow file (triggers activity functions to be wrapped)
|
|
86
|
+
const workflow = await import(config.workflowsPath);
|
|
87
|
+
const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
|
|
88
|
+
const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
|
|
89
|
+
const activityTopic = `${baseTopic}-activity`;
|
|
90
|
+
const workflowTopic = `${baseTopic}`;
|
|
91
|
+
//initialize supporting workflows
|
|
92
|
+
const worker = new WorkerService();
|
|
93
|
+
const activityRunner = await worker.initActivityWorkflow(config, activityTopic);
|
|
94
|
+
await WorkerService.activateWorkflow(activityRunner, activityTopic, getActivityYAML);
|
|
95
|
+
worker.workflowRunner = await worker.initWorkerWorkflow(config, workflowTopic, workflowFunction);
|
|
96
|
+
await WorkerService.activateWorkflow(worker.workflowRunner, workflowTopic, getWorkflowYAML);
|
|
97
|
+
return worker;
|
|
98
|
+
}
|
|
99
|
+
static resolveWorkflowTarget(workflow) {
|
|
100
|
+
let workflowFunction;
|
|
101
|
+
if (typeof workflow === 'function') {
|
|
102
|
+
workflowFunction = workflow;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const workflowFunctionNames = Object.keys(workflow);
|
|
106
|
+
workflowFunction = workflow[workflowFunctionNames[workflowFunctionNames.length - 1]];
|
|
107
|
+
return WorkerService.resolveWorkflowTarget(workflowFunction);
|
|
108
|
+
}
|
|
109
|
+
return [workflowFunction.name, workflowFunction];
|
|
110
|
+
}
|
|
111
|
+
async run() {
|
|
112
|
+
if (this.workflowRunner) {
|
|
113
|
+
this.workflowRunner.engine.logger.info('WorkerService is running');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.log('WorkerService is running');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async initActivityWorkflow(config, activityTopic) {
|
|
120
|
+
const redisConfig = {
|
|
121
|
+
class: config.connection.class,
|
|
122
|
+
options: config.connection.options
|
|
123
|
+
};
|
|
124
|
+
const hmshInstance = await HotMesh.init({
|
|
125
|
+
appId: activityTopic,
|
|
126
|
+
engine: { redis: redisConfig },
|
|
127
|
+
workers: [
|
|
128
|
+
{ topic: activityTopic,
|
|
129
|
+
redis: redisConfig,
|
|
130
|
+
callback: this.wrapActivityFunctions().bind(this)
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
});
|
|
134
|
+
WorkerService.instances.set(activityTopic, hmshInstance);
|
|
135
|
+
return hmshInstance;
|
|
136
|
+
}
|
|
137
|
+
wrapActivityFunctions() {
|
|
138
|
+
return async (data) => {
|
|
139
|
+
try {
|
|
140
|
+
//always run the activity function when instructed; return the response
|
|
141
|
+
const activityInput = data.data;
|
|
142
|
+
const activityName = activityInput.activityName;
|
|
143
|
+
const activityFunction = WorkerService.activityRegistry[activityName];
|
|
144
|
+
const pojoResponse = await activityFunction.apply(this, activityInput.arguments);
|
|
145
|
+
return {
|
|
146
|
+
status: StreamStatus.SUCCESS,
|
|
147
|
+
metadata: { ...data.metadata },
|
|
148
|
+
data: { response: pojoResponse }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
console.error(err);
|
|
153
|
+
//todo (make retry configurable)
|
|
154
|
+
return {
|
|
155
|
+
status: StreamStatus.PENDING,
|
|
156
|
+
metadata: { ...data.metadata },
|
|
157
|
+
data: { error: err }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async activateActivityWorkflow(hotMesh, activityTopic) {
|
|
163
|
+
const version = '1';
|
|
164
|
+
const app = await hotMesh.engine.store.getApp(activityTopic);
|
|
165
|
+
const appVersion = app?.version;
|
|
166
|
+
if (isNaN(appVersion)) {
|
|
167
|
+
try {
|
|
168
|
+
await hotMesh.deploy(getActivityYAML(activityTopic, version));
|
|
169
|
+
await hotMesh.activate(version);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
console.log('durable-worker-activity-deploy-activate-error', err);
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (app && !app.active) {
|
|
177
|
+
try {
|
|
178
|
+
await hotMesh.activate(version);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
hotMesh.engine.logger.error('durable-worker-activity-activate-err', err);
|
|
182
|
+
throw err;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async initWorkerWorkflow(config, workflowTopic, workflowFunction) {
|
|
187
|
+
const redisConfig = {
|
|
188
|
+
class: config.connection.class,
|
|
189
|
+
options: config.connection.options
|
|
190
|
+
};
|
|
191
|
+
const hmshInstance = await HotMesh.init({
|
|
192
|
+
appId: workflowTopic,
|
|
193
|
+
engine: { redis: redisConfig },
|
|
194
|
+
workers: [
|
|
195
|
+
{ topic: workflowTopic,
|
|
196
|
+
redis: redisConfig,
|
|
197
|
+
callback: this.wrapWorkflowFunction(workflowFunction, workflowTopic).bind(this)
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
});
|
|
201
|
+
WorkerService.instances.set(workflowTopic, hmshInstance);
|
|
202
|
+
return hmshInstance;
|
|
203
|
+
}
|
|
204
|
+
wrapWorkflowFunction(workflowFunction, workflowTopic) {
|
|
205
|
+
return async (data) => {
|
|
206
|
+
try {
|
|
207
|
+
//incoming data payload has arguments and workflowId
|
|
208
|
+
const workflowInput = data.data;
|
|
209
|
+
const context = new Map();
|
|
210
|
+
const counter = { counter: 0 };
|
|
211
|
+
context.set('counter', counter);
|
|
212
|
+
context.set('workflowId', workflowInput.workflowId);
|
|
213
|
+
context.set('workflowTopic', workflowTopic);
|
|
214
|
+
context.set('workflowName', workflowTopic.split('-').pop());
|
|
215
|
+
context.set('workflowTrace', data.metadata.trc);
|
|
216
|
+
context.set('workflowSpan', data.metadata.spn);
|
|
217
|
+
const workflowResponse = await asyncLocalStorage.run(context, async () => {
|
|
218
|
+
return await workflowFunction.apply(this, workflowInput.arguments);
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
code: 200,
|
|
222
|
+
status: StreamStatus.SUCCESS,
|
|
223
|
+
metadata: { ...data.metadata },
|
|
224
|
+
data: { response: workflowResponse }
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
//todo: (retryable error types)
|
|
229
|
+
return {
|
|
230
|
+
code: 500,
|
|
231
|
+
status: StreamStatus.PENDING,
|
|
232
|
+
metadata: { ...data.metadata },
|
|
233
|
+
data: { error: err }
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
static async shutdown() {
|
|
239
|
+
for (const [key, value] of WorkerService.instances) {
|
|
240
|
+
const hotMesh = await value;
|
|
241
|
+
await hotMesh.stop();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
_a = WorkerService;
|
|
246
|
+
WorkerService.activityRegistry = {}; //user's activities
|
|
247
|
+
WorkerService.instances = new Map();
|
|
248
|
+
WorkerService.getHotMesh = async (worflowTopic) => {
|
|
249
|
+
if (WorkerService.instances.has(worflowTopic)) {
|
|
250
|
+
return await WorkerService.instances.get(worflowTopic);
|
|
251
|
+
}
|
|
252
|
+
const hotMesh = HotMesh.init({
|
|
253
|
+
appId: worflowTopic,
|
|
254
|
+
engine: { redis: { ...WorkerService.connection } }
|
|
255
|
+
});
|
|
256
|
+
WorkerService.instances.set(worflowTopic, hotMesh);
|
|
257
|
+
await WorkerService.activateWorkflow(await hotMesh, worflowTopic, getWorkflowYAML);
|
|
258
|
+
return hotMesh;
|
|
259
|
+
};
|
|
260
|
+
WorkerService.Context = {
|
|
261
|
+
info: () => {
|
|
262
|
+
return {
|
|
263
|
+
workflowId: '',
|
|
264
|
+
workflowTopic: '',
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
export { WorkerService };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ActivityConfig, ProxyType, WorkflowOptions } from "../../types/durable";
|
|
2
|
+
export declare class WorkflowService {
|
|
3
|
+
static executeChild<T>(options: WorkflowOptions): Promise<T>;
|
|
4
|
+
static proxyActivities<ACT>(options?: ActivityConfig): ProxyType<ACT>;
|
|
5
|
+
static wrapActivity<T>(activityName: string, options?: ActivityConfig): T;
|
|
6
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import ms from 'ms';
|
|
2
|
+
import { asyncLocalStorage } from './asyncLocalStorage';
|
|
3
|
+
import { WorkerService } from './worker';
|
|
4
|
+
import { ClientService as Client } from './client';
|
|
5
|
+
import { ConnectionService as Connection } from './connection';
|
|
6
|
+
/*
|
|
7
|
+
`proxyActivities` returns a wrapped instance of the
|
|
8
|
+
target activity, so that when the workflow calls a
|
|
9
|
+
proxied activity, it is actually calling the proxy
|
|
10
|
+
function, which in turn calls the activity function.
|
|
11
|
+
|
|
12
|
+
`proxyActivities` must be called AFTER the activities
|
|
13
|
+
have been registered in order to work properly.
|
|
14
|
+
If the activities are not already registered,
|
|
15
|
+
`proxyActivities` will throw an error. This is OK.
|
|
16
|
+
|
|
17
|
+
The `client` (client.ts) is equivalent to the
|
|
18
|
+
HotMesh `engine`. The jobs it creates will be
|
|
19
|
+
put in the taskQueue. When the `worker` (worker.ts)
|
|
20
|
+
is eventually initialized (if it happens to be inited later),
|
|
21
|
+
it will see the items in the queue and process them. If it happens
|
|
22
|
+
to already be inited, the jobs will immediately be dequeued and
|
|
23
|
+
processed. In either case, the jobs will be processed.
|
|
24
|
+
|
|
25
|
+
Here is an example of how the methods in this file are used:
|
|
26
|
+
|
|
27
|
+
./workflows.ts
|
|
28
|
+
|
|
29
|
+
import { Durable } from '@hotmeshio/hotmesh';
|
|
30
|
+
import type * as activities from './activities';
|
|
31
|
+
const { greet } = Durable.workflow.proxyActivities<typeof activities>({
|
|
32
|
+
startToCloseTimeout: '1 minute',
|
|
33
|
+
retryPolicy: {
|
|
34
|
+
initialInterval: '5 seconds', // Initial delay between retries
|
|
35
|
+
maximumAttempts: 3, // Max number of retry attempts
|
|
36
|
+
backoffCoefficient: 2.0, // Backoff factor for delay between retries: delay = initialInterval * (backoffCoefficient ^ retry_attempt)
|
|
37
|
+
maximumInterval: '30 seconds', // Max delay between retries
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export async function example(name: string): Promise<string> {
|
|
42
|
+
return await greet(name);
|
|
43
|
+
}
|
|
44
|
+
*/
|
|
45
|
+
export class WorkflowService {
|
|
46
|
+
static async executeChild(options) {
|
|
47
|
+
const store = asyncLocalStorage.getStore();
|
|
48
|
+
if (!store) {
|
|
49
|
+
throw new Error('durable-store-not-found');
|
|
50
|
+
}
|
|
51
|
+
const workflowId = store.get('workflowId');
|
|
52
|
+
const workflowTrace = store.get('workflowTrace');
|
|
53
|
+
const workflowSpan = store.get('workflowSpan');
|
|
54
|
+
const client = new Client({
|
|
55
|
+
connection: await Connection.connect(WorkerService.connection),
|
|
56
|
+
});
|
|
57
|
+
//todo: should I allow-cross/app callback (pj:'@DURABLE@hello-world@<pjid>'/pa: <paid>/pd: <pdad>)
|
|
58
|
+
const handle = await client.workflow.start({
|
|
59
|
+
...options,
|
|
60
|
+
workflowId: `${workflowId}${options.workflowId}`,
|
|
61
|
+
workflowTrace,
|
|
62
|
+
workflowSpan,
|
|
63
|
+
});
|
|
64
|
+
const result = await handle.result();
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
static proxyActivities(options) {
|
|
68
|
+
const proxy = {};
|
|
69
|
+
const keys = Object.keys(WorkerService.activityRegistry);
|
|
70
|
+
if (keys.length) {
|
|
71
|
+
keys.forEach((key) => {
|
|
72
|
+
const activityFunction = WorkerService.activityRegistry[key];
|
|
73
|
+
proxy[key] = WorkflowService.wrapActivity(key, options);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return proxy;
|
|
77
|
+
}
|
|
78
|
+
static wrapActivity(activityName, options) {
|
|
79
|
+
return async function () {
|
|
80
|
+
const store = asyncLocalStorage.getStore();
|
|
81
|
+
if (!store) {
|
|
82
|
+
throw new Error('durable-store-not-found');
|
|
83
|
+
}
|
|
84
|
+
const COUNTER = store.get('counter');
|
|
85
|
+
//increment by state (not value) to avoid race conditions
|
|
86
|
+
const execIndex = COUNTER.counter = COUNTER.counter + 1;
|
|
87
|
+
const workflowId = store.get('workflowId');
|
|
88
|
+
const workflowTopic = store.get('workflowTopic');
|
|
89
|
+
const trc = store.get('workflowTrace');
|
|
90
|
+
const spn = store.get('workflowSpan');
|
|
91
|
+
const activityTopic = `${workflowTopic}-activity`;
|
|
92
|
+
const activityJobId = `${workflowId}-${activityName}-${execIndex}`;
|
|
93
|
+
let activityState;
|
|
94
|
+
try {
|
|
95
|
+
const hmshInstance = await WorkerService.getHotMesh(activityTopic);
|
|
96
|
+
activityState = await hmshInstance.getState(activityTopic, activityJobId);
|
|
97
|
+
if (activityState.metadata.js == 1) {
|
|
98
|
+
//return immediately
|
|
99
|
+
return activityState.data?.response;
|
|
100
|
+
}
|
|
101
|
+
//one time subscription
|
|
102
|
+
return await new Promise((resolve, reject) => {
|
|
103
|
+
hmshInstance.sub(activityTopic, async (topic, message) => {
|
|
104
|
+
const response = message.data?.response;
|
|
105
|
+
hmshInstance.unsub(activityTopic);
|
|
106
|
+
// Resolve the Promise when the callback is triggered with a message
|
|
107
|
+
resolve(response);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
//expected; thrown by `getState` when the job cannot be found
|
|
113
|
+
const duration = ms(options?.startToCloseTimeout || '1 minute');
|
|
114
|
+
const payload = {
|
|
115
|
+
arguments: Array.from(arguments),
|
|
116
|
+
workflowId: activityJobId,
|
|
117
|
+
workflowTopic,
|
|
118
|
+
activityName,
|
|
119
|
+
};
|
|
120
|
+
//start the job
|
|
121
|
+
const hmshInstance = await WorkerService.getHotMesh(activityTopic);
|
|
122
|
+
const context = { metadata: { trc, spn }, data: {} };
|
|
123
|
+
const jobOutput = await hmshInstance.pubsub(activityTopic, payload, context, duration);
|
|
124
|
+
return jobOutput.data.response;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|