@hotmeshio/hotmesh 0.0.8 → 0.0.9
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/LICENSE +4 -7
- package/README.md +37 -46
- package/build/{esm/package.json → package.json} +4 -11
- package/build/{cjs/services → services}/durable/native.js +2 -2
- package/build/{esm/services → services}/durable/worker.d.ts +1 -3
- package/build/{cjs/services → services}/durable/worker.js +9 -32
- package/build/{cjs/services → services}/durable/workflow.js +6 -1
- package/build/{cjs/types → types}/durable.d.ts +4 -6
- package/package.json +4 -11
- package/services/durable/native.ts +2 -2
- package/services/durable/worker.ts +9 -9
- package/services/durable/workflow.ts +7 -1
- package/types/durable.ts +4 -4
- package/build/cjs/package.json +0 -82
- package/build/cjs/services/durable/worker.d.ts +0 -38
- package/build/esm/index.d.ts +0 -4
- package/build/esm/index.js +0 -3
- package/build/esm/modules/errors.d.ts +0 -28
- package/build/esm/modules/errors.js +0 -41
- package/build/esm/modules/key.d.ts +0 -75
- package/build/esm/modules/key.js +0 -111
- package/build/esm/modules/utils.d.ts +0 -34
- package/build/esm/modules/utils.js +0 -154
- package/build/esm/services/activities/activity.d.ts +0 -67
- package/build/esm/services/activities/activity.js +0 -486
- package/build/esm/services/activities/await.d.ts +0 -16
- package/build/esm/services/activities/await.js +0 -140
- package/build/esm/services/activities/cycle.d.ts +0 -19
- package/build/esm/services/activities/cycle.js +0 -74
- package/build/esm/services/activities/emit.d.ts +0 -9
- package/build/esm/services/activities/emit.js +0 -10
- package/build/esm/services/activities/index.d.ts +0 -17
- package/build/esm/services/activities/index.js +0 -16
- package/build/esm/services/activities/iterate.d.ts +0 -9
- package/build/esm/services/activities/iterate.js +0 -10
- package/build/esm/services/activities/trigger.d.ts +0 -22
- package/build/esm/services/activities/trigger.js +0 -158
- package/build/esm/services/activities/worker.d.ts +0 -11
- package/build/esm/services/activities/worker.js +0 -70
- package/build/esm/services/collator/index.d.ts +0 -73
- package/build/esm/services/collator/index.js +0 -221
- package/build/esm/services/compiler/deployer.d.ts +0 -36
- package/build/esm/services/compiler/deployer.js +0 -423
- package/build/esm/services/compiler/index.d.ts +0 -30
- package/build/esm/services/compiler/index.js +0 -82
- package/build/esm/services/compiler/validator.d.ts +0 -32
- package/build/esm/services/compiler/validator.js +0 -131
- package/build/esm/services/connector/clients/ioredis.d.ts +0 -13
- package/build/esm/services/connector/clients/ioredis.js +0 -47
- package/build/esm/services/connector/clients/redis.d.ts +0 -13
- package/build/esm/services/connector/clients/redis.js +0 -59
- package/build/esm/services/connector/index.d.ts +0 -5
- package/build/esm/services/connector/index.js +0 -27
- package/build/esm/services/dimension/index.d.ts +0 -29
- package/build/esm/services/dimension/index.js +0 -32
- package/build/esm/services/durable/asyncLocalStorage.d.ts +0 -3
- package/build/esm/services/durable/asyncLocalStorage.js +0 -2
- package/build/esm/services/durable/client.d.ts +0 -15
- package/build/esm/services/durable/client.js +0 -114
- package/build/esm/services/durable/connection.d.ts +0 -4
- package/build/esm/services/durable/connection.js +0 -47
- package/build/esm/services/durable/factory.d.ts +0 -3
- package/build/esm/services/durable/factory.js +0 -135
- package/build/esm/services/durable/handle.d.ts +0 -8
- package/build/esm/services/durable/handle.js +0 -34
- package/build/esm/services/durable/index.d.ts +0 -57
- package/build/esm/services/durable/index.js +0 -55
- package/build/esm/services/durable/native.d.ts +0 -4
- package/build/esm/services/durable/native.js +0 -43
- package/build/esm/services/durable/worker.js +0 -267
- package/build/esm/services/durable/workflow.d.ts +0 -6
- package/build/esm/services/durable/workflow.js +0 -132
- package/build/esm/services/engine/index.d.ts +0 -82
- package/build/esm/services/engine/index.js +0 -522
- package/build/esm/services/hotmesh/index.d.ts +0 -45
- package/build/esm/services/hotmesh/index.js +0 -131
- package/build/esm/services/logger/index.d.ts +0 -17
- package/build/esm/services/logger/index.js +0 -70
- package/build/esm/services/mapper/index.d.ts +0 -24
- package/build/esm/services/mapper/index.js +0 -72
- package/build/esm/services/pipe/functions/array.d.ts +0 -24
- package/build/esm/services/pipe/functions/array.js +0 -66
- package/build/esm/services/pipe/functions/bitwise.d.ts +0 -9
- package/build/esm/services/pipe/functions/bitwise.js +0 -21
- package/build/esm/services/pipe/functions/conditional.d.ts +0 -10
- package/build/esm/services/pipe/functions/conditional.js +0 -24
- package/build/esm/services/pipe/functions/date.d.ts +0 -57
- package/build/esm/services/pipe/functions/date.js +0 -164
- package/build/esm/services/pipe/functions/index.d.ts +0 -25
- package/build/esm/services/pipe/functions/index.js +0 -24
- package/build/esm/services/pipe/functions/json.d.ts +0 -5
- package/build/esm/services/pipe/functions/json.js +0 -9
- package/build/esm/services/pipe/functions/math.d.ts +0 -38
- package/build/esm/services/pipe/functions/math.js +0 -108
- package/build/esm/services/pipe/functions/number.d.ts +0 -25
- package/build/esm/services/pipe/functions/number.js +0 -130
- package/build/esm/services/pipe/functions/object.d.ts +0 -22
- package/build/esm/services/pipe/functions/object.js +0 -60
- package/build/esm/services/pipe/functions/string.d.ts +0 -23
- package/build/esm/services/pipe/functions/string.js +0 -66
- package/build/esm/services/pipe/functions/symbol.d.ts +0 -12
- package/build/esm/services/pipe/functions/symbol.js +0 -30
- package/build/esm/services/pipe/functions/unary.d.ts +0 -7
- package/build/esm/services/pipe/functions/unary.js +0 -15
- package/build/esm/services/pipe/index.d.ts +0 -30
- package/build/esm/services/pipe/index.js +0 -122
- package/build/esm/services/quorum/index.d.ts +0 -34
- package/build/esm/services/quorum/index.js +0 -144
- package/build/esm/services/reporter/index.d.ts +0 -47
- package/build/esm/services/reporter/index.js +0 -327
- package/build/esm/services/serializer/index.d.ts +0 -41
- package/build/esm/services/serializer/index.js +0 -251
- package/build/esm/services/signaler/store.d.ts +0 -15
- package/build/esm/services/signaler/store.js +0 -50
- package/build/esm/services/signaler/stream.d.ts +0 -43
- package/build/esm/services/signaler/stream.js +0 -314
- package/build/esm/services/store/cache.d.ts +0 -66
- package/build/esm/services/store/cache.js +0 -124
- package/build/esm/services/store/clients/ioredis.d.ts +0 -27
- package/build/esm/services/store/clients/ioredis.js +0 -93
- package/build/esm/services/store/clients/redis.d.ts +0 -29
- package/build/esm/services/store/clients/redis.js +0 -140
- package/build/esm/services/store/index.d.ts +0 -88
- package/build/esm/services/store/index.js +0 -623
- package/build/esm/services/stream/clients/ioredis.d.ts +0 -23
- package/build/esm/services/stream/clients/ioredis.js +0 -112
- package/build/esm/services/stream/clients/redis.d.ts +0 -23
- package/build/esm/services/stream/clients/redis.js +0 -116
- package/build/esm/services/stream/index.d.ts +0 -21
- package/build/esm/services/stream/index.js +0 -6
- package/build/esm/services/sub/clients/ioredis.d.ts +0 -20
- package/build/esm/services/sub/clients/ioredis.js +0 -69
- package/build/esm/services/sub/clients/redis.d.ts +0 -20
- package/build/esm/services/sub/clients/redis.js +0 -60
- package/build/esm/services/sub/index.d.ts +0 -18
- package/build/esm/services/sub/index.js +0 -6
- package/build/esm/services/task/index.d.ts +0 -18
- package/build/esm/services/task/index.js +0 -70
- package/build/esm/services/telemetry/index.d.ts +0 -49
- package/build/esm/services/telemetry/index.js +0 -217
- package/build/esm/services/worker/index.d.ts +0 -30
- package/build/esm/services/worker/index.js +0 -102
- package/build/esm/types/activity.d.ts +0 -92
- package/build/esm/types/activity.js +0 -1
- package/build/esm/types/app.d.ts +0 -16
- package/build/esm/types/app.js +0 -1
- package/build/esm/types/async.d.ts +0 -5
- package/build/esm/types/async.js +0 -1
- package/build/esm/types/cache.d.ts +0 -1
- package/build/esm/types/cache.js +0 -1
- package/build/esm/types/collator.d.ts +0 -8
- package/build/esm/types/collator.js +0 -8
- package/build/esm/types/durable.d.ts +0 -59
- package/build/esm/types/durable.js +0 -1
- package/build/esm/types/hook.d.ts +0 -31
- package/build/esm/types/hook.js +0 -6
- package/build/esm/types/hotmesh.d.ts +0 -82
- package/build/esm/types/hotmesh.js +0 -1
- package/build/esm/types/index.d.ts +0 -20
- package/build/esm/types/index.js +0 -5
- package/build/esm/types/ioredisclient.d.ts +0 -5
- package/build/esm/types/ioredisclient.js +0 -2
- package/build/esm/types/job.d.ts +0 -50
- package/build/esm/types/job.js +0 -1
- package/build/esm/types/logger.d.ts +0 -6
- package/build/esm/types/logger.js +0 -1
- package/build/esm/types/map.d.ts +0 -4
- package/build/esm/types/map.js +0 -1
- package/build/esm/types/pipe.d.ts +0 -4
- package/build/esm/types/pipe.js +0 -1
- package/build/esm/types/quorum.d.ts +0 -46
- package/build/esm/types/quorum.js +0 -1
- package/build/esm/types/redis.d.ts +0 -8
- package/build/esm/types/redis.js +0 -1
- package/build/esm/types/redisclient.d.ts +0 -25
- package/build/esm/types/redisclient.js +0 -1
- package/build/esm/types/serializer.d.ts +0 -33
- package/build/esm/types/serializer.js +0 -1
- package/build/esm/types/stats.d.ts +0 -83
- package/build/esm/types/stats.js +0 -1
- package/build/esm/types/stream.d.ts +0 -67
- package/build/esm/types/stream.js +0 -22
- package/build/esm/types/telemetry.d.ts +0 -1
- package/build/esm/types/telemetry.js +0 -1
- package/build/esm/types/transition.d.ts +0 -17
- package/build/esm/types/transition.js +0 -1
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -9
- /package/build/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/build/{cjs/index.js → index.js} +0 -0
- /package/build/{cjs/modules → modules}/errors.d.ts +0 -0
- /package/build/{cjs/modules → modules}/errors.js +0 -0
- /package/build/{cjs/modules → modules}/key.d.ts +0 -0
- /package/build/{cjs/modules → modules}/key.js +0 -0
- /package/build/{cjs/modules → modules}/utils.d.ts +0 -0
- /package/build/{cjs/modules → modules}/utils.js +0 -0
- /package/build/{cjs/services → services}/activities/activity.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/activity.js +0 -0
- /package/build/{cjs/services → services}/activities/await.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/await.js +0 -0
- /package/build/{cjs/services → services}/activities/cycle.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/cycle.js +0 -0
- /package/build/{cjs/services → services}/activities/emit.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/emit.js +0 -0
- /package/build/{cjs/services → services}/activities/index.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/index.js +0 -0
- /package/build/{cjs/services → services}/activities/iterate.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/iterate.js +0 -0
- /package/build/{cjs/services → services}/activities/trigger.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/trigger.js +0 -0
- /package/build/{cjs/services → services}/activities/worker.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/worker.js +0 -0
- /package/build/{cjs/services → services}/collator/index.d.ts +0 -0
- /package/build/{cjs/services → services}/collator/index.js +0 -0
- /package/build/{cjs/services → services}/compiler/deployer.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/deployer.js +0 -0
- /package/build/{cjs/services → services}/compiler/index.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/index.js +0 -0
- /package/build/{cjs/services → services}/compiler/validator.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/validator.js +0 -0
- /package/build/{cjs/services → services}/connector/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/connector/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/connector/index.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/index.js +0 -0
- /package/build/{cjs/services → services}/dimension/index.d.ts +0 -0
- /package/build/{cjs/services → services}/dimension/index.js +0 -0
- /package/build/{cjs/services → services}/durable/asyncLocalStorage.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/asyncLocalStorage.js +0 -0
- /package/build/{cjs/services → services}/durable/client.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/client.js +0 -0
- /package/build/{cjs/services → services}/durable/connection.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/connection.js +0 -0
- /package/build/{cjs/services → services}/durable/factory.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/factory.js +0 -0
- /package/build/{cjs/services → services}/durable/handle.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/handle.js +0 -0
- /package/build/{cjs/services → services}/durable/index.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/index.js +0 -0
- /package/build/{cjs/services → services}/durable/native.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/workflow.d.ts +0 -0
- /package/build/{cjs/services → services}/engine/index.d.ts +0 -0
- /package/build/{cjs/services → services}/engine/index.js +0 -0
- /package/build/{cjs/services → services}/hotmesh/index.d.ts +0 -0
- /package/build/{cjs/services → services}/hotmesh/index.js +0 -0
- /package/build/{cjs/services → services}/logger/index.d.ts +0 -0
- /package/build/{cjs/services → services}/logger/index.js +0 -0
- /package/build/{cjs/services → services}/mapper/index.d.ts +0 -0
- /package/build/{cjs/services → services}/mapper/index.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/array.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/array.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/bitwise.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/bitwise.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/conditional.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/conditional.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/date.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/date.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/index.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/index.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/json.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/json.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/math.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/math.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/number.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/number.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/object.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/object.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/string.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/string.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/symbol.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/symbol.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/unary.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/unary.js +0 -0
- /package/build/{cjs/services → services}/pipe/index.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/index.js +0 -0
- /package/build/{cjs/services → services}/quorum/index.d.ts +0 -0
- /package/build/{cjs/services → services}/quorum/index.js +0 -0
- /package/build/{cjs/services → services}/reporter/index.d.ts +0 -0
- /package/build/{cjs/services → services}/reporter/index.js +0 -0
- /package/build/{cjs/services → services}/serializer/index.d.ts +0 -0
- /package/build/{cjs/services → services}/serializer/index.js +0 -0
- /package/build/{cjs/services → services}/signaler/store.d.ts +0 -0
- /package/build/{cjs/services → services}/signaler/store.js +0 -0
- /package/build/{cjs/services → services}/signaler/stream.d.ts +0 -0
- /package/build/{cjs/services → services}/signaler/stream.js +0 -0
- /package/build/{cjs/services → services}/store/cache.d.ts +0 -0
- /package/build/{cjs/services → services}/store/cache.js +0 -0
- /package/build/{cjs/services → services}/store/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/store/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/store/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/store/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/store/index.d.ts +0 -0
- /package/build/{cjs/services → services}/store/index.js +0 -0
- /package/build/{cjs/services → services}/stream/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/stream/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/stream/index.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/index.js +0 -0
- /package/build/{cjs/services → services}/sub/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/sub/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/sub/index.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/index.js +0 -0
- /package/build/{cjs/services → services}/task/index.d.ts +0 -0
- /package/build/{cjs/services → services}/task/index.js +0 -0
- /package/build/{cjs/services → services}/telemetry/index.d.ts +0 -0
- /package/build/{cjs/services → services}/telemetry/index.js +0 -0
- /package/build/{cjs/services → services}/worker/index.d.ts +0 -0
- /package/build/{cjs/services → services}/worker/index.js +0 -0
- /package/build/{cjs/types → types}/activity.d.ts +0 -0
- /package/build/{cjs/types → types}/activity.js +0 -0
- /package/build/{cjs/types → types}/app.d.ts +0 -0
- /package/build/{cjs/types → types}/app.js +0 -0
- /package/build/{cjs/types → types}/async.d.ts +0 -0
- /package/build/{cjs/types → types}/async.js +0 -0
- /package/build/{cjs/types → types}/cache.d.ts +0 -0
- /package/build/{cjs/types → types}/cache.js +0 -0
- /package/build/{cjs/types → types}/collator.d.ts +0 -0
- /package/build/{cjs/types → types}/collator.js +0 -0
- /package/build/{cjs/types → types}/durable.js +0 -0
- /package/build/{cjs/types → types}/hook.d.ts +0 -0
- /package/build/{cjs/types → types}/hook.js +0 -0
- /package/build/{cjs/types → types}/hotmesh.d.ts +0 -0
- /package/build/{cjs/types → types}/hotmesh.js +0 -0
- /package/build/{cjs/types → types}/index.d.ts +0 -0
- /package/build/{cjs/types → types}/index.js +0 -0
- /package/build/{cjs/types → types}/ioredisclient.d.ts +0 -0
- /package/build/{cjs/types → types}/ioredisclient.js +0 -0
- /package/build/{cjs/types → types}/job.d.ts +0 -0
- /package/build/{cjs/types → types}/job.js +0 -0
- /package/build/{cjs/types → types}/logger.d.ts +0 -0
- /package/build/{cjs/types → types}/logger.js +0 -0
- /package/build/{cjs/types → types}/map.d.ts +0 -0
- /package/build/{cjs/types → types}/map.js +0 -0
- /package/build/{cjs/types → types}/pipe.d.ts +0 -0
- /package/build/{cjs/types → types}/pipe.js +0 -0
- /package/build/{cjs/types → types}/quorum.d.ts +0 -0
- /package/build/{cjs/types → types}/quorum.js +0 -0
- /package/build/{cjs/types → types}/redis.d.ts +0 -0
- /package/build/{cjs/types → types}/redis.js +0 -0
- /package/build/{cjs/types → types}/redisclient.d.ts +0 -0
- /package/build/{cjs/types → types}/redisclient.js +0 -0
- /package/build/{cjs/types → types}/serializer.d.ts +0 -0
- /package/build/{cjs/types → types}/serializer.js +0 -0
- /package/build/{cjs/types → types}/stats.d.ts +0 -0
- /package/build/{cjs/types → types}/stats.js +0 -0
- /package/build/{cjs/types → types}/stream.d.ts +0 -0
- /package/build/{cjs/types → types}/stream.js +0 -0
- /package/build/{cjs/types → types}/telemetry.d.ts +0 -0
- /package/build/{cjs/types → types}/telemetry.js +0 -0
- /package/build/{cjs/types → types}/transition.d.ts +0 -0
- /package/build/{cjs/types → types}/transition.js +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Here is an example of how the methods in this file are used:
|
|
3
|
-
|
|
4
|
-
./client.ts
|
|
5
|
-
|
|
6
|
-
import { Durable } from '@hotmeshio/hotmesh';
|
|
7
|
-
import Redis from 'ioredis';
|
|
8
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
-
|
|
10
|
-
async function run() {
|
|
11
|
-
const connection = await Durable.Connection.connect({
|
|
12
|
-
class: Redis,
|
|
13
|
-
options: {
|
|
14
|
-
host: 'localhost',
|
|
15
|
-
port: 6379,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const client = new Durable.Client({
|
|
20
|
-
connection,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const handle = await client.workflow.start(example, {
|
|
24
|
-
taskQueue: 'hello-world',
|
|
25
|
-
args: ['HotMesh'],
|
|
26
|
-
workflowName: 'example',
|
|
27
|
-
workflowId: uuidv4(),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
console.log(`Started workflow ${handle.workflowId}`);
|
|
31
|
-
console.log(await handle.result());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
run().catch((err) => {
|
|
35
|
-
console.error(err);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
export class ConnectionService {
|
|
41
|
-
static async connect(config) {
|
|
42
|
-
return {
|
|
43
|
-
class: config.class,
|
|
44
|
-
options: { ...config.options },
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const getWorkflowYAML = (topic, version = '1') => {
|
|
2
|
-
return `app:
|
|
3
|
-
id: ${topic}
|
|
4
|
-
version: '${version}'
|
|
5
|
-
graphs:
|
|
6
|
-
- subscribes: ${topic}
|
|
7
|
-
publishes: ${topic}
|
|
8
|
-
expire: 120
|
|
9
|
-
input:
|
|
10
|
-
schema:
|
|
11
|
-
type: object
|
|
12
|
-
properties:
|
|
13
|
-
workflowId:
|
|
14
|
-
type: string
|
|
15
|
-
arguments:
|
|
16
|
-
type: array
|
|
17
|
-
output:
|
|
18
|
-
schema:
|
|
19
|
-
type: object
|
|
20
|
-
properties:
|
|
21
|
-
response:
|
|
22
|
-
type: any
|
|
23
|
-
|
|
24
|
-
activities:
|
|
25
|
-
t1:
|
|
26
|
-
type: trigger
|
|
27
|
-
stats:
|
|
28
|
-
id: '{$self.input.data.workflowId}'
|
|
29
|
-
|
|
30
|
-
a1:
|
|
31
|
-
type: activity
|
|
32
|
-
cycle: true
|
|
33
|
-
|
|
34
|
-
w1:
|
|
35
|
-
type: worker
|
|
36
|
-
topic: ${topic}
|
|
37
|
-
input:
|
|
38
|
-
schema:
|
|
39
|
-
type: object
|
|
40
|
-
properties:
|
|
41
|
-
workflowId:
|
|
42
|
-
type: string
|
|
43
|
-
arguments:
|
|
44
|
-
type: array
|
|
45
|
-
maps:
|
|
46
|
-
workflowId: '{t1.output.data.workflowId}'
|
|
47
|
-
arguments: '{t1.output.data.arguments}'
|
|
48
|
-
output:
|
|
49
|
-
schema:
|
|
50
|
-
type: object
|
|
51
|
-
properties:
|
|
52
|
-
response:
|
|
53
|
-
type: any
|
|
54
|
-
job:
|
|
55
|
-
maps:
|
|
56
|
-
response: '{$self.output.data.response}'
|
|
57
|
-
|
|
58
|
-
c1:
|
|
59
|
-
type: cycle
|
|
60
|
-
ancestor: a1
|
|
61
|
-
transitions:
|
|
62
|
-
t1:
|
|
63
|
-
- to: a1
|
|
64
|
-
a1:
|
|
65
|
-
- to: w1
|
|
66
|
-
w1:
|
|
67
|
-
- to: c1
|
|
68
|
-
conditions:
|
|
69
|
-
code: 500
|
|
70
|
-
`;
|
|
71
|
-
};
|
|
72
|
-
const getActivityYAML = (topic, version = '1') => {
|
|
73
|
-
return `app:
|
|
74
|
-
id: ${topic}
|
|
75
|
-
version: '${version}'
|
|
76
|
-
graphs:
|
|
77
|
-
- subscribes: ${topic}
|
|
78
|
-
input:
|
|
79
|
-
schema:
|
|
80
|
-
type: object
|
|
81
|
-
properties:
|
|
82
|
-
workflowId:
|
|
83
|
-
type: string
|
|
84
|
-
workflowTopic:
|
|
85
|
-
type: string
|
|
86
|
-
activityName:
|
|
87
|
-
type: array
|
|
88
|
-
arguments:
|
|
89
|
-
type: array
|
|
90
|
-
output:
|
|
91
|
-
schema:
|
|
92
|
-
type: object
|
|
93
|
-
properties:
|
|
94
|
-
response:
|
|
95
|
-
type: any
|
|
96
|
-
|
|
97
|
-
activities:
|
|
98
|
-
t1:
|
|
99
|
-
type: trigger
|
|
100
|
-
stats:
|
|
101
|
-
id: '{$self.input.data.workflowId}'
|
|
102
|
-
a1:
|
|
103
|
-
type: worker
|
|
104
|
-
topic: ${topic}
|
|
105
|
-
input:
|
|
106
|
-
schema:
|
|
107
|
-
type: object
|
|
108
|
-
properties:
|
|
109
|
-
workflowId:
|
|
110
|
-
type: string
|
|
111
|
-
workflowTopic:
|
|
112
|
-
type: string
|
|
113
|
-
activityName:
|
|
114
|
-
type: array
|
|
115
|
-
arguments:
|
|
116
|
-
type: array
|
|
117
|
-
maps:
|
|
118
|
-
workflowId: '{t1.output.data.workflowId}'
|
|
119
|
-
workflowTopic: '{t1.output.data.workflowTopic}'
|
|
120
|
-
activityName: '{t1.output.data.activityName}'
|
|
121
|
-
arguments: '{t1.output.data.arguments}'
|
|
122
|
-
output:
|
|
123
|
-
schema:
|
|
124
|
-
type: object
|
|
125
|
-
properties:
|
|
126
|
-
response:
|
|
127
|
-
type: any
|
|
128
|
-
job:
|
|
129
|
-
maps:
|
|
130
|
-
response: '{$self.output.data.response}'
|
|
131
|
-
transitions:
|
|
132
|
-
t1:
|
|
133
|
-
- to: a1`;
|
|
134
|
-
};
|
|
135
|
-
export { getActivityYAML, getWorkflowYAML };
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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 };
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
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
|
-
if (typeof activities === 'function') {
|
|
77
|
-
WorkerService.activityRegistry[activities.name] = activities;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
Object.keys(activities).forEach(key => {
|
|
81
|
-
WorkerService.activityRegistry[activities[key].name] = activities[key];
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return WorkerService.activityRegistry;
|
|
85
|
-
}
|
|
86
|
-
static async create(config) {
|
|
87
|
-
//always call `registerActivities` before `import`
|
|
88
|
-
WorkerService.connection = config.connection;
|
|
89
|
-
WorkerService.registerActivities(config.activities);
|
|
90
|
-
const workflow = await import(config.workflowsPath);
|
|
91
|
-
const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
|
|
92
|
-
const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
|
|
93
|
-
const activityTopic = `${baseTopic}-activity`;
|
|
94
|
-
const workflowTopic = `${baseTopic}`;
|
|
95
|
-
//initialize supporting workflows
|
|
96
|
-
const worker = new WorkerService();
|
|
97
|
-
worker.activityRunner = await worker.initActivityWorkflow(config, activityTopic);
|
|
98
|
-
await WorkerService.activateWorkflow(worker.activityRunner, activityTopic, getActivityYAML);
|
|
99
|
-
worker.workflowRunner = await worker.initWorkerWorkflow(config, workflowTopic, workflowFunction);
|
|
100
|
-
await WorkerService.activateWorkflow(worker.workflowRunner, workflowTopic, getWorkflowYAML);
|
|
101
|
-
return worker;
|
|
102
|
-
}
|
|
103
|
-
static resolveWorkflowTarget(workflow) {
|
|
104
|
-
let workflowFunction;
|
|
105
|
-
if (typeof workflow === 'function') {
|
|
106
|
-
workflowFunction = workflow;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const workflowFunctionNames = Object.keys(workflow);
|
|
110
|
-
workflowFunction = workflow[workflowFunctionNames[workflowFunctionNames.length - 1]];
|
|
111
|
-
return WorkerService.resolveWorkflowTarget(workflowFunction);
|
|
112
|
-
}
|
|
113
|
-
return [workflowFunction.name, workflowFunction];
|
|
114
|
-
}
|
|
115
|
-
async run() {
|
|
116
|
-
this.workflowRunner.engine.logger.info('WorkerService is running');
|
|
117
|
-
}
|
|
118
|
-
async initActivityWorkflow(config, activityTopic) {
|
|
119
|
-
const redisConfig = {
|
|
120
|
-
class: config.connection.class,
|
|
121
|
-
options: config.connection.options
|
|
122
|
-
};
|
|
123
|
-
const hmshInstance = await HotMesh.init({
|
|
124
|
-
appId: activityTopic,
|
|
125
|
-
engine: { redis: redisConfig },
|
|
126
|
-
workers: [
|
|
127
|
-
{ topic: activityTopic,
|
|
128
|
-
redis: redisConfig,
|
|
129
|
-
callback: this.wrapActivityFunctions().bind(this)
|
|
130
|
-
}
|
|
131
|
-
]
|
|
132
|
-
});
|
|
133
|
-
WorkerService.instances.set(activityTopic, hmshInstance);
|
|
134
|
-
return hmshInstance;
|
|
135
|
-
}
|
|
136
|
-
wrapActivityFunctions() {
|
|
137
|
-
return async (data) => {
|
|
138
|
-
try {
|
|
139
|
-
//always run the activity function when instructed; return the response
|
|
140
|
-
const activityInput = data.data;
|
|
141
|
-
const activityName = activityInput.activityName;
|
|
142
|
-
const activityFunction = WorkerService.activityRegistry[activityName];
|
|
143
|
-
const pojoResponse = await activityFunction.apply(this, activityInput.arguments);
|
|
144
|
-
return {
|
|
145
|
-
status: StreamStatus.SUCCESS,
|
|
146
|
-
metadata: { ...data.metadata },
|
|
147
|
-
data: { response: pojoResponse }
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
catch (err) {
|
|
151
|
-
this.activityRunner.engine.logger.error('durable-worker-activity-err', err);
|
|
152
|
-
return {
|
|
153
|
-
status: StreamStatus.ERROR,
|
|
154
|
-
code: 500,
|
|
155
|
-
message: err.message,
|
|
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
|
-
hotMesh.engine.logger.error('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
|
-
return {
|
|
229
|
-
status: StreamStatus.ERROR,
|
|
230
|
-
code: 500,
|
|
231
|
-
metadata: { ...data.metadata },
|
|
232
|
-
data: { error: err }
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
static async shutdown() {
|
|
238
|
-
for (const [key, value] of WorkerService.instances) {
|
|
239
|
-
const hotMesh = await value;
|
|
240
|
-
await hotMesh.stop();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
_a = WorkerService;
|
|
245
|
-
WorkerService.activityRegistry = {}; //user's activities
|
|
246
|
-
WorkerService.instances = new Map();
|
|
247
|
-
WorkerService.getHotMesh = async (worflowTopic) => {
|
|
248
|
-
if (WorkerService.instances.has(worflowTopic)) {
|
|
249
|
-
return await WorkerService.instances.get(worflowTopic);
|
|
250
|
-
}
|
|
251
|
-
const hotMesh = HotMesh.init({
|
|
252
|
-
appId: worflowTopic,
|
|
253
|
-
engine: { redis: { ...WorkerService.connection } }
|
|
254
|
-
});
|
|
255
|
-
WorkerService.instances.set(worflowTopic, hotMesh);
|
|
256
|
-
await WorkerService.activateWorkflow(await hotMesh, worflowTopic, getWorkflowYAML);
|
|
257
|
-
return hotMesh;
|
|
258
|
-
};
|
|
259
|
-
WorkerService.Context = {
|
|
260
|
-
info: () => {
|
|
261
|
-
return {
|
|
262
|
-
workflowId: '',
|
|
263
|
-
workflowTopic: '',
|
|
264
|
-
};
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
export { WorkerService };
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
}
|