Skip to content

Commit

Permalink
cleanup wait method
Browse files Browse the repository at this point in the history
  • Loading branch information
shouples committed Oct 17, 2024
1 parent 1af04cf commit 5a703e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/docker/workflows/confluent-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ConfluentLocalWorkflow extends LocalResourceWorkflow {

// TODO: add additional logic here for connecting with Schema Registry if a flag is set

await this.waitForConnectionChangeEvent();
await this.waitForLocalResourceEventChange();
}

/**
Expand All @@ -89,6 +89,17 @@ export class ConfluentLocalWorkflow extends LocalResourceWorkflow {
// TODO(shoup): implement
}

/** Block until we see the {@link localKafkaConnected} event fire. (Controlled by the EventListener
* in `src/docker/eventListener.ts` whenever a supported container starts or dies.) */
async waitForLocalResourceEventChange(): Promise<void> {
// not set in the base class since each workflow may need to wait for specific events to fire
await new Promise((resolve) => {
localKafkaConnected.event(() => {
resolve(void 0);
});
});
}

private async startLocalKafkaContainer(
brokerNum: number,
): Promise<ContainerInspectResponse | undefined> {
Expand All @@ -105,17 +116,6 @@ export class ConfluentLocalWorkflow extends LocalResourceWorkflow {
return await getContainer(container.id);
}

/** Block until we see the {@link localKafkaConnected} event fire. (Controlled by the EventListener
* in `src/docker/eventListener.ts` whenever a supported container starts or dies.) */
async waitForConnectionChangeEvent(): Promise<void> {
// not set in the base class since each workflow may need to wait for specific events to fire
await new Promise((resolve) => {
localKafkaConnected.event(() => {
resolve(void 0);
});
});
}

async createKafkaContainer(brokerNum: number): Promise<LocalResourceContainer | undefined> {
const brokerContainerName: string = `confluent-local-broker-${brokerNum}`;

Expand Down
8 changes: 8 additions & 0 deletions src/docker/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export abstract class LocalResourceWorkflow {
progress?: Progress<{ message?: string; increment?: number }>,
): Promise<void>;

/**
* Wait for the local resource(s) to be created/removed based on event emitters.
*
* This should be called at the end of the `start` or `stop` methods to ensure the resource(s) are
* ready to be used, and any existing progress notifications can be resolved.
*/
abstract waitForLocalResourceEventChange(): Promise<void>;

/** Check if the this workflow's base image repo:tag exists locally, pulling it if not. */
protected async checkForImage(): Promise<void> {
// get the repo from the child instances' static property
Expand Down

0 comments on commit 5a703e4

Please sign in to comment.