@hotmeshio/hotmesh 0.0.24 → 0.0.25
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 +21 -28
- package/build/package.json +1 -1
- package/build/services/durable/meshos.d.ts +16 -12
- package/build/services/durable/meshos.js +30 -13
- package/build/services/store/clients/redis.js +1 -2
- package/build/services/stream/clients/redis.js +1 -1
- package/build/services/sub/clients/redis.js +1 -1
- package/build/types/durable.d.ts +10 -9
- package/build/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/services/durable/meshos.ts +39 -17
- package/services/store/clients/redis.ts +1 -2
- package/services/stream/clients/redis.ts +1 -1
- package/services/sub/clients/redis.ts +1 -1
- package/types/durable.ts +12 -6
- package/types/index.ts +2 -1
package/README.md
CHANGED
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
Elevate Redis from an in-memory data cache to a game-changing [service mesh](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/faq.md#what-is-hotmesh). Turn your unpredictable functions into unbreakable workflows.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
HotMesh is a wrapper for Redis that exposes a higher level set of domain constructs like ‘activities’, ‘workflows’, 'jobs', etc. Behind the scenes, it uses *Redis Data* (Hash, ZSet, and List); *Redis Streams* (XReadGroup, XAdd, XLen); and *Redis Publish/Subscribe*.
|
|
8
|
-
|
|
9
|
-
The ultimate goal is to resurface Redis as a *Durable Service Mesh*, capable of running unbreakable workflows that span your microservices. The technical term for this type of durability is *Reentrant Process Engine*.
|
|
6
|
+
HotMesh is a wrapper for Redis that exposes a higher level set of domain constructs like ‘activities’, ‘workflows’, 'jobs', etc. Behind the scenes, it uses *Redis Data* (Hash, ZSet, List); *Redis Streams* (XReadGroup, XAdd, XLen, etc); and *Redis Publish/Subscribe*.
|
|
10
7
|
|
|
11
8
|
It's still Redis in the background, but the information flow is fundamentally different. Your functions no longer call Redis (e.g., to cache a document) and instead are called by Redis.
|
|
12
9
|
|
|
@@ -20,34 +17,32 @@ npm install @hotmeshio/hotmesh
|
|
|
20
17
|
## Design
|
|
21
18
|
The HotMesh SDK is designed to keep your code front-and-center. Write code as you normally would, then use HotMesh to make it durable.
|
|
22
19
|
|
|
23
|
-
1. Start with any ordinary class. Pay attention to unpredictable functions: those that execute slowly, cause problems at scale, or simply fail to return. *Note how the `
|
|
20
|
+
1. Start with any ordinary class. Pay attention to unpredictable functions: those that execute slowly, cause problems at scale, or simply fail to return. *Note how the `flaky` function throws an error 50% of the time. This is exactly the type of function that can be fixed using HotMesh.*
|
|
24
21
|
```javascript
|
|
25
22
|
//myworkflow.ts
|
|
26
23
|
|
|
27
24
|
export class MyWorkflow {
|
|
28
25
|
|
|
29
|
-
//main method
|
|
30
26
|
async run(name: string): Promise<string> {
|
|
31
|
-
const
|
|
27
|
+
const hi = await this.flaky(name);
|
|
32
28
|
const hello = await this.greet(name);
|
|
33
|
-
return `${
|
|
29
|
+
return `${hi} ${hello}`;
|
|
34
30
|
}
|
|
35
31
|
|
|
36
|
-
//this function
|
|
37
|
-
async
|
|
32
|
+
//this function is unpredictable and will fail 50% of the time
|
|
33
|
+
async flaky(name: string): Promise<string> {
|
|
38
34
|
if (Math.random() < 0.5) {
|
|
39
|
-
throw new Error('
|
|
35
|
+
throw new Error('Ooops!');
|
|
40
36
|
}
|
|
41
|
-
return
|
|
37
|
+
return `Hi, ${name}!`;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
//this function always succeeds
|
|
45
40
|
async greet(name: string): Promise<string> {
|
|
46
41
|
return `Hello, ${name}!`;
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
44
|
```
|
|
50
|
-
2. Import `
|
|
45
|
+
2. Import `Redis` and `MeshOS` and configure host, port, etc. List those functions that Redis should govern as durable workflows (like `run` and `flaky`). And that's it! *Your functions don't actually change; rather, their governance does.*
|
|
51
46
|
```javascript
|
|
52
47
|
//myworkflow.ts
|
|
53
48
|
|
|
@@ -63,40 +58,38 @@ The HotMesh SDK is designed to keep your code front-and-center. Write code as yo
|
|
|
63
58
|
workflowFunctions = ['run'];
|
|
64
59
|
|
|
65
60
|
//list functions to retry and cache
|
|
66
|
-
proxyFunctions = ['
|
|
61
|
+
proxyFunctions = ['flaky'];
|
|
67
62
|
|
|
68
|
-
//main method (Redis will now govern its execution)
|
|
69
63
|
async run(name: string): Promise<string> {
|
|
70
|
-
const
|
|
64
|
+
const hi = await this.flaky(name);
|
|
71
65
|
const hello = await this.greet(name);
|
|
72
|
-
return `${
|
|
66
|
+
return `${hi} ${hello}`;
|
|
73
67
|
}
|
|
74
68
|
|
|
75
|
-
//this function
|
|
76
|
-
async
|
|
69
|
+
//this function is now durable and will be retried until it succeeds!
|
|
70
|
+
async flaky(name: string): Promise<string> {
|
|
77
71
|
if (Math.random() < 0.5) {
|
|
78
|
-
throw new Error('
|
|
72
|
+
throw new Error('Ooops!');
|
|
79
73
|
}
|
|
80
|
-
return
|
|
74
|
+
return `Hi, ${name}!`;
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
//this vanilla function is unchanged
|
|
84
77
|
async greet(name: string): Promise<string> {
|
|
85
78
|
return `Hello, ${name}!`;
|
|
86
79
|
}
|
|
87
80
|
}
|
|
88
81
|
```
|
|
89
|
-
3. Invoke your class, providing a unique
|
|
82
|
+
3. Invoke your class, providing a unique id (it's now an idempotent workflow and needs a GUID). Nothing changes from the outside, *but Redis now governs the end-to-end execution.* It's guaranteed to succeed and return regardless of network or microservice failure. Redis will simply inflate like a balloon and deflate as your services come back online.
|
|
90
83
|
```javascript
|
|
91
84
|
//mycaller.ts
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const workflow = new MyWorkflow('unique123', { await: true }); //await the response
|
|
86
|
+
const workflow = new MyWorkflow({ id: 'my123', await: true });
|
|
96
87
|
const response = await workflow.run('John');
|
|
97
|
-
//Hello, John!
|
|
88
|
+
//Hello, John! Hi, John!
|
|
98
89
|
```
|
|
99
90
|
|
|
91
|
+
>NOTE: MeshOS provides a full suite of durable workflow methods for extending your functions, including: `waitForSignal`, `signal`, `hook`, `sleep` (months, years, etc), `executeChild`, `startChild`, `get`, `set`, `incr` (increment), and `mult` (multiply).
|
|
92
|
+
|
|
100
93
|
## Advanced Design
|
|
101
94
|
HotMesh's TypeScript SDK is the easiest way to make your functions durable. But if you need full control over your function lifecycles (including high-volume, high-speed use cases), you can use HotMesh's underlying YAML models to optimize your durable workflows. The following model depicts a sequence of activities orchestrated by HotMesh. Any function you associate with a `topic` in your YAML definition is guaranteed to be durable.
|
|
102
95
|
|
package/build/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { WorkflowHandleService } from './handle';
|
|
2
|
-
import { FindOptions, MeshOSActivityOptions, MeshOSOptions, WorkflowSearchOptions } from '../../types/durable';
|
|
3
|
-
import { RedisOptions, RedisClass } from '../../types/redis';
|
|
4
|
-
import { StringAnyType } from '../../types';
|
|
5
2
|
import { WorkflowService } from './workflow';
|
|
3
|
+
import { FindOptions, MeshOSActivityOptions, MeshOSConfig, MeshOSOptions, MeshOSWorkerOptions, WorkflowSearchOptions } from '../../types/durable';
|
|
4
|
+
import { RedisOptions, RedisClass } from '../../types/redis';
|
|
5
|
+
import { StringAnyType } from '../../types/serializer';
|
|
6
6
|
/**
|
|
7
7
|
* The base class for running MeshOS workflows.
|
|
8
|
-
* Extend
|
|
9
|
-
* execute as durable workflows
|
|
8
|
+
* Extend this class, add your Redis config, and add functions to
|
|
9
|
+
* execute as durable `hooks`, `workflows`, and `activities`.
|
|
10
10
|
*/
|
|
11
11
|
export declare class MeshOSService {
|
|
12
12
|
/**
|
|
@@ -78,14 +78,18 @@ export declare class MeshOSService {
|
|
|
78
78
|
*/
|
|
79
79
|
static createIndex(): Promise<void>;
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* stop the workers
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
static stopWorkers(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Initializes the worker(s). This is a static
|
|
82
87
|
* method that allows for optional task Queue targeting.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {string[]} allowList
|
|
88
|
+
* An `allowList` may be optionally provided to start
|
|
89
|
+
* specific `worker` and `hook` methods.
|
|
90
|
+
* @param {MeshOSWorkerOptions} [options]
|
|
87
91
|
*/
|
|
88
|
-
static startWorkers(
|
|
92
|
+
static startWorkers(options?: MeshOSWorkerOptions): Promise<void>;
|
|
89
93
|
/**
|
|
90
94
|
* executes the redis FT search query
|
|
91
95
|
* @example '@_quantity:[89 89]'
|
|
@@ -104,5 +108,5 @@ export declare class MeshOSService {
|
|
|
104
108
|
* Optionally include a target taskQueue to exec the
|
|
105
109
|
* workflow's call on a specific worker queue.
|
|
106
110
|
*/
|
|
107
|
-
constructor(id?: string, options?:
|
|
111
|
+
constructor(id?: string | MeshOSConfig, options?: MeshOSConfig);
|
|
108
112
|
}
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MeshOSService = void 0;
|
|
4
4
|
const nanoid_1 = require("nanoid");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
5
7
|
const client_1 = require("./client");
|
|
6
8
|
const search_1 = require("./search");
|
|
7
9
|
const worker_1 = require("./worker");
|
|
8
|
-
const _1 = require(".");
|
|
9
|
-
const asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
10
10
|
const workflow_1 = require("./workflow");
|
|
11
|
+
const stream_1 = require("../signaler/stream");
|
|
11
12
|
/**
|
|
12
13
|
* The base class for running MeshOS workflows.
|
|
13
|
-
* Extend
|
|
14
|
-
* execute as durable workflows
|
|
14
|
+
* Extend this class, add your Redis config, and add functions to
|
|
15
|
+
* execute as durable `hooks`, `workflows`, and `activities`.
|
|
15
16
|
*/
|
|
16
17
|
class MeshOSService {
|
|
17
18
|
static async getHotMeshClient(redisClass, redisOptions, namespace, taskQueue) {
|
|
@@ -42,14 +43,24 @@ class MeshOSService {
|
|
|
42
43
|
search_1.Search.configureSearchIndex(hmClient, my.search);
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
+
* stop the workers
|
|
47
|
+
* @returns {Promise<void>}
|
|
48
|
+
*/
|
|
49
|
+
static async stopWorkers() {
|
|
50
|
+
await _1.Durable.Client.shutdown();
|
|
51
|
+
await _1.Durable.Worker.shutdown();
|
|
52
|
+
await stream_1.StreamSignaler.stopConsuming();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Initializes the worker(s). This is a static
|
|
46
56
|
* method that allows for optional task Queue targeting.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param {
|
|
50
|
-
* @param {string[]} allowList
|
|
57
|
+
* An `allowList` may be optionally provided to start
|
|
58
|
+
* specific `worker` and `hook` methods.
|
|
59
|
+
* @param {MeshOSWorkerOptions} [options]
|
|
51
60
|
*/
|
|
52
|
-
static async startWorkers(
|
|
61
|
+
static async startWorkers(options) {
|
|
62
|
+
const taskQueue = options && options.taskQueue;
|
|
63
|
+
const allowList = options && options.allowList || [];
|
|
53
64
|
const my = new this();
|
|
54
65
|
//helper functions
|
|
55
66
|
const resolveFunctionNames = (arr) => arr.map(item => typeof item === 'string' ? item : item.name);
|
|
@@ -74,8 +85,6 @@ class MeshOSService {
|
|
|
74
85
|
const proxiedActivities = _1.Durable.workflow.proxyActivities({
|
|
75
86
|
activities: proxyActivities
|
|
76
87
|
});
|
|
77
|
-
//WATCH!: unsure if this will pollute the scope; don't think
|
|
78
|
-
// so as activity functions are terminal in the chain.
|
|
79
88
|
Object.assign(my, proxiedActivities);
|
|
80
89
|
}
|
|
81
90
|
const functionsToIterate = allowList.length ? resolveFunctionNames(allowList) : resolveFunctionNames([...my.workflowFunctions, ...my.hookFunctions]);
|
|
@@ -224,7 +233,15 @@ class MeshOSService {
|
|
|
224
233
|
password: '',
|
|
225
234
|
db: 0,
|
|
226
235
|
};
|
|
227
|
-
|
|
236
|
+
if (typeof (id) === 'string') {
|
|
237
|
+
this.id = id;
|
|
238
|
+
}
|
|
239
|
+
else if (id?.id) {
|
|
240
|
+
this.id = id.id;
|
|
241
|
+
options = id;
|
|
242
|
+
id = undefined;
|
|
243
|
+
}
|
|
244
|
+
;
|
|
228
245
|
if (options?.taskQueue) {
|
|
229
246
|
this.taskQueue = options.taskQueue;
|
|
230
247
|
}
|
|
@@ -33,8 +33,7 @@ class RedisStoreService extends index_1.StoreService {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
getMulti() {
|
|
36
|
-
|
|
37
|
-
return multi;
|
|
36
|
+
return this.redisClient.multi();
|
|
38
37
|
}
|
|
39
38
|
async exec(...args) {
|
|
40
39
|
return await this.redisClient.sendCommand(args);
|
package/build/types/durable.d.ts
CHANGED
|
@@ -59,15 +59,9 @@ type MeshOSClassConfig = {
|
|
|
59
59
|
redisClass: RedisClass;
|
|
60
60
|
};
|
|
61
61
|
type MeshOSConfig = {
|
|
62
|
+
id?: string;
|
|
63
|
+
await?: boolean;
|
|
62
64
|
taskQueue?: string;
|
|
63
|
-
index?: {
|
|
64
|
-
index: string;
|
|
65
|
-
prefix: string[];
|
|
66
|
-
schema: Record<string, {
|
|
67
|
-
type: 'TEXT' | 'NUMERIC' | 'TAG';
|
|
68
|
-
sortable: boolean;
|
|
69
|
-
}>;
|
|
70
|
-
};
|
|
71
65
|
};
|
|
72
66
|
type ConnectionConfig = {
|
|
73
67
|
class: RedisClass;
|
|
@@ -102,6 +96,13 @@ type MeshOSActivityOptions = {
|
|
|
102
96
|
name: string;
|
|
103
97
|
options: ActivityConfig;
|
|
104
98
|
};
|
|
99
|
+
type MeshOSWorkerOptions = {
|
|
100
|
+
taskQueue?: string;
|
|
101
|
+
allowList?: Array<MeshOSOptions | string>;
|
|
102
|
+
logLevel?: string;
|
|
103
|
+
maxSystemRetries?: number;
|
|
104
|
+
backoffCoefficient?: number;
|
|
105
|
+
};
|
|
105
106
|
type WorkerOptions = {
|
|
106
107
|
logLevel?: string;
|
|
107
108
|
maxSystemRetries?: number;
|
|
@@ -125,4 +126,4 @@ type ActivityConfig = {
|
|
|
125
126
|
maximumInterval: string;
|
|
126
127
|
};
|
|
127
128
|
};
|
|
128
|
-
export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, ProxyType, Registry, SignalOptions, FindOptions, HookOptions, MeshOSActivityOptions, MeshOSClassConfig, MeshOSConfig, MeshOSOptions, WorkerConfig, WorkflowConfig, WorkerOptions, WorkflowSearchOptions, WorkflowDataType, WorkflowOptions, };
|
|
129
|
+
export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, ProxyType, Registry, SignalOptions, FindOptions, HookOptions, MeshOSActivityOptions, MeshOSWorkerOptions, MeshOSClassConfig, MeshOSConfig, MeshOSOptions, WorkerConfig, WorkflowConfig, WorkerOptions, WorkflowSearchOptions, WorkflowDataType, WorkflowOptions, };
|
package/build/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { App, AppVID, AppTransitions, AppSubscriptions } from './app';
|
|
|
3
3
|
export { AsyncSignal } from './async';
|
|
4
4
|
export { CacheMode } from './cache';
|
|
5
5
|
export { CollationFaultType, CollationStage } from './collator';
|
|
6
|
-
export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, ProxyType, Registry, SignalOptions, FindOptions, HookOptions, MeshOSActivityOptions, MeshOSClassConfig, MeshOSConfig, MeshOSOptions, WorkflowConfig, WorkerConfig, WorkerOptions, WorkflowSearchOptions, WorkflowDataType, WorkflowOptions, } from './durable';
|
|
6
|
+
export { ActivityConfig, ActivityWorkflowDataType, ClientConfig, ContextType, ConnectionConfig, Connection, ProxyType, Registry, SignalOptions, FindOptions, HookOptions, MeshOSActivityOptions, MeshOSWorkerOptions, MeshOSClassConfig, MeshOSConfig, MeshOSOptions, WorkflowConfig, WorkerConfig, WorkerOptions, WorkflowSearchOptions, WorkflowDataType, WorkflowOptions, } from './durable';
|
|
7
7
|
export { HookCondition, HookConditions, HookGate, HookInterface, HookRule, HookRules, HookSignal } from './hook';
|
|
8
8
|
export { RedisClientType as IORedisClientType, RedisMultiType as IORedisMultiType } from './ioredisclient';
|
|
9
9
|
export { ILogger } from './logger';
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { nanoid } from 'nanoid';
|
|
2
2
|
|
|
3
|
+
import { Durable } from '.';
|
|
4
|
+
import { asyncLocalStorage } from './asyncLocalStorage';
|
|
3
5
|
import { ClientService as Client } from './client';
|
|
4
6
|
import { WorkflowHandleService } from './handle';
|
|
5
7
|
import { Search } from './search';
|
|
6
8
|
import { WorkerService as Worker } from './worker';
|
|
7
|
-
import { FindOptions, MeshOSActivityOptions, MeshOSOptions, WorkflowSearchOptions } from '../../types/durable';
|
|
8
|
-
import { RedisOptions, RedisClass } from '../../types/redis';
|
|
9
|
-
import { StringAnyType } from '../../types';
|
|
10
|
-
import { Durable } from '.';
|
|
11
|
-
import { asyncLocalStorage } from './asyncLocalStorage';
|
|
12
9
|
import { WorkflowService } from './workflow';
|
|
10
|
+
import { StreamSignaler } from '../signaler/stream';
|
|
11
|
+
import {
|
|
12
|
+
FindOptions,
|
|
13
|
+
MeshOSActivityOptions,
|
|
14
|
+
MeshOSConfig,
|
|
15
|
+
MeshOSOptions,
|
|
16
|
+
MeshOSWorkerOptions,
|
|
17
|
+
WorkflowSearchOptions } from '../../types/durable';
|
|
18
|
+
import { RedisOptions, RedisClass } from '../../types/redis';
|
|
19
|
+
import { StringAnyType } from '../../types/serializer';
|
|
13
20
|
|
|
14
21
|
/**
|
|
15
22
|
* The base class for running MeshOS workflows.
|
|
16
|
-
* Extend
|
|
17
|
-
* execute as durable workflows
|
|
23
|
+
* Extend this class, add your Redis config, and add functions to
|
|
24
|
+
* execute as durable `hooks`, `workflows`, and `activities`.
|
|
18
25
|
*/
|
|
19
26
|
|
|
20
27
|
export class MeshOSService {
|
|
@@ -122,14 +129,25 @@ export class MeshOSService {
|
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
/**
|
|
125
|
-
*
|
|
132
|
+
* stop the workers
|
|
133
|
+
* @returns {Promise<void>}
|
|
134
|
+
*/
|
|
135
|
+
static async stopWorkers(): Promise<void> {
|
|
136
|
+
await Durable.Client.shutdown();
|
|
137
|
+
await Durable.Worker.shutdown();
|
|
138
|
+
await StreamSignaler.stopConsuming();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Initializes the worker(s). This is a static
|
|
126
143
|
* method that allows for optional task Queue targeting.
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @param {
|
|
130
|
-
* @param {string[]} allowList
|
|
144
|
+
* An `allowList` may be optionally provided to start
|
|
145
|
+
* specific `worker` and `hook` methods.
|
|
146
|
+
* @param {MeshOSWorkerOptions} [options]
|
|
131
147
|
*/
|
|
132
|
-
static async startWorkers(
|
|
148
|
+
static async startWorkers(options?: MeshOSWorkerOptions) {
|
|
149
|
+
const taskQueue = options && options.taskQueue;
|
|
150
|
+
const allowList = options && options.allowList || [];
|
|
133
151
|
const my = new this();
|
|
134
152
|
|
|
135
153
|
//helper functions
|
|
@@ -156,8 +174,6 @@ export class MeshOSService {
|
|
|
156
174
|
const proxiedActivities = Durable.workflow.proxyActivities({
|
|
157
175
|
activities: proxyActivities
|
|
158
176
|
});
|
|
159
|
-
//WATCH!: unsure if this will pollute the scope; don't think
|
|
160
|
-
// so as activity functions are terminal in the chain.
|
|
161
177
|
Object.assign(my, proxiedActivities);
|
|
162
178
|
}
|
|
163
179
|
|
|
@@ -281,8 +297,14 @@ export class MeshOSService {
|
|
|
281
297
|
* Optionally include a target taskQueue to exec the
|
|
282
298
|
* workflow's call on a specific worker queue.
|
|
283
299
|
*/
|
|
284
|
-
constructor(id?: string, options?:
|
|
285
|
-
|
|
300
|
+
constructor(id?: string | MeshOSConfig, options?: MeshOSConfig) {
|
|
301
|
+
if (typeof(id) === 'string') {
|
|
302
|
+
this.id = id;
|
|
303
|
+
} else if (id?.id) {
|
|
304
|
+
this.id = id.id;
|
|
305
|
+
options = id;
|
|
306
|
+
id = undefined;
|
|
307
|
+
};
|
|
286
308
|
if (options?.taskQueue) {
|
|
287
309
|
this.taskQueue = options.taskQueue;
|
|
288
310
|
} else if (!id && !options?.taskQueue) {
|
|
@@ -46,8 +46,7 @@ class RedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
getMulti(): RedisMultiType {
|
|
49
|
-
|
|
50
|
-
return multi as unknown as RedisMultiType;
|
|
49
|
+
return this.redisClient.multi() as unknown as RedisMultiType;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
async exec(...args: any[]): Promise<string|string[]|string[][]> {
|
|
@@ -21,7 +21,7 @@ class RedisStreamService extends StreamService<RedisClientType, RedisMultiType>
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
getMulti(): RedisMultiType {
|
|
24
|
-
return this.redisClient.
|
|
24
|
+
return this.redisClient.multi() as unknown as RedisMultiType;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
mintKey(type: KeyType, params: KeyStoreParams): string {
|
package/types/durable.ts
CHANGED
|
@@ -65,12 +65,9 @@ type MeshOSClassConfig = {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
type MeshOSConfig = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
prefix: string[];
|
|
72
|
-
schema: Record<string, {type: 'TEXT' | 'NUMERIC' | 'TAG', sortable: boolean}>;
|
|
73
|
-
};
|
|
68
|
+
id?: string; //guid for the workflow when instancing
|
|
69
|
+
await?: boolean; //default is false; must explicitly send true to await the final result
|
|
70
|
+
taskQueue?: string; //optional target queue isolate for the function
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
type ConnectionConfig = {
|
|
@@ -113,6 +110,14 @@ type MeshOSActivityOptions = {
|
|
|
113
110
|
options: ActivityConfig;
|
|
114
111
|
}
|
|
115
112
|
|
|
113
|
+
type MeshOSWorkerOptions = {
|
|
114
|
+
taskQueue?: string; //change the default task queue
|
|
115
|
+
allowList?: Array<MeshOSOptions | string>; //limit which `hook` and `workflow` workers start
|
|
116
|
+
logLevel?: string; //debug, info, warn, error
|
|
117
|
+
maxSystemRetries?: number; //1-3 (10ms, 100ms, 1_000ms)
|
|
118
|
+
backoffCoefficient?: number; //2-10ish
|
|
119
|
+
}
|
|
120
|
+
|
|
116
121
|
type WorkerOptions = {
|
|
117
122
|
logLevel?: string; //debug, info, warn, error
|
|
118
123
|
maxSystemRetries?: number; //1-3 (10ms, 100ms, 1_000ms)
|
|
@@ -153,6 +158,7 @@ export {
|
|
|
153
158
|
FindOptions,
|
|
154
159
|
HookOptions,
|
|
155
160
|
MeshOSActivityOptions,
|
|
161
|
+
MeshOSWorkerOptions,
|
|
156
162
|
MeshOSClassConfig,
|
|
157
163
|
MeshOSConfig,
|
|
158
164
|
MeshOSOptions,
|
package/types/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export {
|
|
|
40
40
|
FindOptions,
|
|
41
41
|
HookOptions,
|
|
42
42
|
MeshOSActivityOptions,
|
|
43
|
+
MeshOSWorkerOptions,
|
|
43
44
|
MeshOSClassConfig,
|
|
44
45
|
MeshOSConfig,
|
|
45
46
|
MeshOSOptions,
|
|
@@ -49,7 +50,7 @@ export {
|
|
|
49
50
|
WorkflowSearchOptions,
|
|
50
51
|
WorkflowDataType,
|
|
51
52
|
WorkflowOptions,
|
|
52
|
-
}from './durable'
|
|
53
|
+
} from './durable'
|
|
53
54
|
export {
|
|
54
55
|
HookCondition,
|
|
55
56
|
HookConditions,
|