Skip to content

Commit

Permalink
feat: Discovery makes use of TaskManager now
Browse files Browse the repository at this point in the history
- The parts of discovery that handles queuing has been removed. This includes the 'plug' promises, database levels and the discovery ID generator.
- The logic of the queue where it handled the vertex was separated out into a new method. This logic included connecting to a vertex, getting the claims' data, iterating over the claims, verifying the claims and adding them to the gestaltGraph, and adding the new vertices to the list.
- Adding a vertex to the list now consists of creating a singleton task. each task focuses on processing a single vertex.
- I tried to cancel all tasks on `discovery.destroy()` but it would require the `taskManager` to be started at the time since we need to iterate over active tasks at the time. For now cancel the tasks when starting with fresh.
- To avoid re-trying tasks, a `visitedVertices` set is used, this hasn't been updated. A more complex mechanism is need for this that has persistence. I think this will be left with the more complex discovery changes later.
- Discovery tests have been updated. none removed or added so far. The change was just using `taskManager`.
- Removed discovery utils and types. These are not needed anymore since we don't make use of a discovery ID generator.
- Added locking on the vertex to avoid duplicating a task due to racing. Also catching and throwing the singleton reason, so we don't get any errors on tasks that were canceled for this reason.
- Discovery tasks are canceled during fresh start and destroy.
-`Discovery` stops any active tasks when stopping
- Added a check for if `TaskManager` is still processing when calling stop on `Discovery` and `NodeManager`.
  • Loading branch information
tegefaulkes committed Sep 29, 2022
1 parent d7c931b commit 6d8f606
Show file tree
Hide file tree
Showing 14 changed files with 430 additions and 331 deletions.
7 changes: 6 additions & 1 deletion src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class PolykeyAgent {
identitiesManager,
nodeManager,
sigchain,
taskManager,
logger: logger.getChild(Discovery.name),
}));
notificationsManager =
Expand Down Expand Up @@ -754,16 +755,20 @@ class PolykeyAgent {
this.logger.info(`Destroying ${this.constructor.name}`);
// DB needs to be running for dependent domains to properly clear state.
await this.db.start();
// TaskManager needs to be running for dependent domains to clear state.
await this.taskManager.start({ lazy: true });
await this.sessionManager.destroy();
await this.notificationsManager.destroy();
await this.vaultManager.destroy();
await this.discovery.destroy();
await this.nodeGraph.destroy();
await this.gestaltGraph.destroy();
await this.taskManager.destroy();
await this.acl.destroy();
await this.sigchain.destroy();
await this.identitiesManager.destroy();
await this.taskManager.stop();
await this.taskManager.destroy();
// Non-TaskManager dependencies
await this.db.stop();
// Non-DB dependencies
await this.db.destroy();
Expand Down
Loading

0 comments on commit 6d8f606

Please sign in to comment.