You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- it's way more easy to implement, `Orap` handles most of the common part, e.g. signal handle, task defining, task caching, task fetch and processing, multitasks processing, etc., while it may sacrifice flexibility in some way.
42
+
43
+
Back in the scene, there are 2 internal layers in `Orap`:
44
+
45
+
- Basic Layer:
46
+
- mainly referring to the `Signal`, `StoreManager`, and `Task`, where the concepts are self-explained in engineering context.
47
+
- it can be used directly by users.
48
+
-*Rap-lized* Layer:
49
+
- mainly referring to the `Flow`, `Verse`, and `Beat`, where the concepts are introduced by `Orap` only.
50
+
- it helps to build the declarative functionality, which is way easier for users and save some developers.
51
+
- it mostly for internal developing purpose, and ~~should be~~ easy to scale and extend, though user also has access to them if they want.
52
+
53
+
54
+
> About Multi-chain: Currently Each `Orap` listens to only 1 blockchain network by design, similar to http servers. Create multiple `Orap` instances to implement multi-chain listener.
55
+
>
56
+
> Suggest to include network in task `prefix()`, to avoid key collision in cache store
57
+
58
+
26
59
## Usage
60
+
61
+
### Declarative Style (Rap-lized)
62
+
63
+
It comes with rich features like customized task cache, multitasks handling etc.
64
+
65
+
Note the following already includes using Redis as the store to cache tasks, allowing continuation after service restart, it's robust even when the service restarts.
- set the prefix of tasks in the store cache for management
173
+
-`donePrefix`: prefix of 'todo' tasks records
174
+
-`donePrefix`: prefix of 'done' tasks records
175
+
- default: "Task:" & "Done-Task:"
176
+
177
+
**.ttl({ taskTtl, doneTtl }: { taskTtl: number; doneTtl: number })**
178
+
- set the ttl of tasks in the store cache for management
179
+
-`donePrefix`: ttl of 'todo' tasks records
180
+
-`donePrefix`: ttl of 'done' tasks records
181
+
- default: no limit
182
+
183
+
**.key(toKey: ToKeyFn)**
184
+
- defines the primary key of a task based on the event values (i.e. log topics)
185
+
- default: random hex string
186
+
187
+
**.success(onSuccess: HandleResultFn)**
188
+
- defines how to process the task if the handler success
189
+
- default: remove the 'todo' task from & set the 'done' task record to the cache store
190
+
191
+
**.fail(onFail: HandleResultFn)**
192
+
- defines how to process the task if the handler success
193
+
- default: remove the 'todo' task from (ignore task)
194
+
195
+
**.context(ctx: Context)**
196
+
- optional: set the context that can be accessed to task functions
197
+
198
+
**.another()**
199
+
- back to the parent `Event Flow`, so that it can add another `.task`
200
+
- e.g. `orap.event(...).task().another().task()`
201
+
202
+
### OO Style (Basic)
203
+
204
+
Note the following doesn't include task cache, it only calls `handle` every time it receives an event. So this service is only for demo, don't use it for production, otherwise it may miss events when service down.
205
+
206
+
```ts
207
+
import { ethers } from'ethers'
208
+
import { Orap } from'@orap-io/orap'
30
209
31
210
const orap =newOrap()
32
-
// const sm = new StoreManager(redisStore(...)) // use redis
- provide crosschecker by `reku`, available config please checkout `AutoCrossCheckParam` in `reku`
79
-
- currently one and only one crosschecker is set to each event signal
80
-
- store: provide 2 options: use memory or redis, checkout `orap/store`
286
+
- natively integrate `crosschecker` features from [@ora-io/reku](https://github.com/ora-io/ora-stack/blob/main/packages/reku/), available config please check out `AutoCrossCheckParam` in `reku`
287
+
- each event signal only accept at most one crosschecker.
288
+
- `callback`: the user provided handle function to handle the new signals.
289
+
290
+
### Task
291
+
292
+
**TaskBase**
293
+
- provide universal `toString`, `fromString`, `stringify`
294
+
295
+
**TaskStorable**
296
+
- provide store compatible features, i.e. load, save, remove, done
297
+
- overwrite when extends:
298
+
- `toKey()` (required): define the primary key that identifies each task, **doesn't** include `taskPrefix`
299
+
- `taskPrefix` (recommend): set the prefix of all tasks, also is used when `load` task
300
+
- `taskPrefixDone` (recommend): set the prefix of finished tasks, only used in `done`; no need to set if you don't use "task.done(sm)"
301
+
302
+
### StorageManager
303
+
- a wrap class designed for caching tasks in Orap
304
+
- `store`: the store entity, currently provides 2 options: use memory or redis, checkout `orap/store`
305
+
- `queryDelay`: when doing retry-able operations, e.g. get all keys with the given prefix, this defines the interval between retries.
0 commit comments