Skip to content

Commit

Permalink
wip: refreshBuckets
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Sep 6, 2022
1 parent c08328c commit c3bc60e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 258 deletions.
73 changes: 22 additions & 51 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ import * as errors from './errors';
import * as utils from './utils';
import * as keysUtils from './keys/utils';
import * as nodesUtils from './nodes/utils';
import Scheduler from './tasks/Scheduler';
// FIXME: update name to queue, currently conflicts
import TaskQueue from './tasks/Queue';
import Tasks from './tasks/Tasks';

type NetworkConfig = {
forwardHost?: Host;
Expand Down Expand Up @@ -90,8 +88,7 @@ class PolykeyAgent {
acl,
gestaltGraph,
proxy,
taskQueue,
taskScheduler,
tasks,
nodeGraph,
queue,
nodeConnectionManager,
Expand Down Expand Up @@ -139,8 +136,7 @@ class PolykeyAgent {
acl?: ACL;
gestaltGraph?: GestaltGraph;
proxy?: Proxy;
taskQueue?: TaskQueue;
taskScheduler?: Scheduler;
tasks?: Tasks;
nodeGraph?: NodeGraph;
queue?: Queue;
nodeConnectionManager?: NodeConnectionManager;
Expand Down Expand Up @@ -292,24 +288,13 @@ class PolykeyAgent {
keyManager,
logger: logger.getChild(NodeGraph.name),
}));
taskQueue =
taskQueue ??
(await TaskQueue.createQueue({
tasks =
tasks ??
(await Tasks.createTasks({
activeLimit: 5,
db,
keyManager,
concurrencyLimit: 3,
delay: true,
fresh,
handlers: {},
logger,
}));
taskScheduler =
taskScheduler ??
(await Scheduler.createScheduler({
db,
queue: taskQueue,
delay: true,
fresh,
lazy: true,
logger,
}));
queue =
Expand All @@ -336,8 +321,7 @@ class PolykeyAgent {
keyManager,
nodeGraph,
nodeConnectionManager,
scheduler: taskScheduler,
taskQueue,
tasks,
logger: logger.getChild(NodeManager.name),
});
await nodeManager.start();
Expand Down Expand Up @@ -401,8 +385,7 @@ class PolykeyAgent {
await notificationsManager?.stop();
await vaultManager?.stop();
await discovery?.stop();
await taskScheduler?.stop();
await taskQueue?.stop();
await tasks?.stop();
await proxy?.stop();
await gestaltGraph?.stop();
await acl?.stop();
Expand All @@ -426,8 +409,7 @@ class PolykeyAgent {
gestaltGraph,
proxy,
nodeGraph,
taskQueue,
taskScheduler,
tasks,
queue,
nodeConnectionManager,
nodeManager,
Expand Down Expand Up @@ -461,8 +443,7 @@ class PolykeyAgent {
public readonly gestaltGraph: GestaltGraph;
public readonly proxy: Proxy;
public readonly nodeGraph: NodeGraph;
public readonly taskQueue: TaskQueue;
public readonly taskScheduler: Scheduler;
public readonly tasks: Tasks;
public readonly queue: Queue;
public readonly nodeConnectionManager: NodeConnectionManager;
public readonly nodeManager: NodeManager;
Expand All @@ -488,8 +469,7 @@ class PolykeyAgent {
gestaltGraph,
proxy,
nodeGraph,
taskQueue,
taskScheduler,
tasks,
queue,
nodeConnectionManager,
nodeManager,
Expand All @@ -514,8 +494,7 @@ class PolykeyAgent {
gestaltGraph: GestaltGraph;
proxy: Proxy;
nodeGraph: NodeGraph;
taskQueue: TaskQueue;
taskScheduler: Scheduler;
tasks: Tasks;
queue: Queue;
nodeConnectionManager: NodeConnectionManager;
nodeManager: NodeManager;
Expand All @@ -542,8 +521,7 @@ class PolykeyAgent {
this.proxy = proxy;
this.discovery = discovery;
this.nodeGraph = nodeGraph;
this.taskQueue = taskQueue;
this.taskScheduler = taskScheduler;
this.tasks = tasks;
this.queue = queue;
this.nodeConnectionManager = nodeConnectionManager;
this.nodeManager = nodeManager;
Expand Down Expand Up @@ -707,8 +685,7 @@ class PolykeyAgent {
proxyPort: networkConfig_.proxyPort,
tlsConfig,
});
await this.taskQueue.start({ fresh });
await this.taskScheduler.start({ fresh });
await this.tasks.start({ fresh, lazy: true });
await this.queue.start();
await this.nodeManager.start();
await this.nodeConnectionManager.start({ nodeManager: this.nodeManager });
Expand All @@ -718,8 +695,7 @@ class PolykeyAgent {
await this.vaultManager.start({ fresh });
await this.notificationsManager.start({ fresh });
await this.sessionManager.start({ fresh });
await this.taskQueue.startTasks();
await this.taskScheduler.startDispatching();
await this.tasks.startProcessing();
await this.status.finishStart({
pid: process.pid,
nodeId: this.keyManager.getNodeId(),
Expand All @@ -737,15 +713,13 @@ class PolykeyAgent {
this.logger.warn(`Failed Starting ${this.constructor.name}`);
this.events.removeAllListeners();
await this.status?.beginStop({ pid: process.pid });
await this.taskScheduler.stopDispatching();
await this.taskQueue.stopTasks();
await this.tasks?.stopProcessing();
await this.sessionManager?.stop();
await this.notificationsManager?.stop();
await this.vaultManager?.stop();
await this.discovery?.stop();
await this.queue?.stop();
await this.taskScheduler?.stop();
await this.taskQueue?.stop();
await this.tasks?.stop();
await this.nodeGraph?.stop();
await this.nodeConnectionManager?.stop();
await this.nodeManager?.stop();
Expand All @@ -771,8 +745,7 @@ class PolykeyAgent {
this.logger.info(`Stopping ${this.constructor.name}`);
this.events.removeAllListeners();
await this.status.beginStop({ pid: process.pid });
await this.taskScheduler.stopDispatching();
await this.taskQueue.stopTasks();
await this.tasks.stopProcessing();
await this.sessionManager.stop();
await this.notificationsManager.stop();
await this.vaultManager.stop();
Expand All @@ -781,8 +754,7 @@ class PolykeyAgent {
await this.nodeGraph.stop();
await this.nodeManager.stop();
await this.queue.stop();
await this.taskScheduler?.stop();
await this.taskQueue?.stop();
await this.tasks.stop();
await this.proxy.stop();
await this.grpcServerAgent.stop();
await this.grpcServerClient.stop();
Expand All @@ -807,8 +779,7 @@ class PolykeyAgent {
await this.discovery.destroy();
await this.nodeGraph.destroy();
await this.gestaltGraph.destroy();
await this.taskScheduler.destroy();
await this.taskQueue.destroy();
await this.tasks.destroy();
await this.acl.destroy();
await this.sigchain.destroy();
await this.identitiesManager.destroy();
Expand Down
Loading

0 comments on commit c3bc60e

Please sign in to comment.