Skip to content

Commit

Permalink
refactor(worker): improve type imports and lifecycle generics
Browse files Browse the repository at this point in the history
Add type imports and enhance WorkerLifecycle generic type parameter
- Change import statements to use 'import type'
- Add generic type parameter to WorkerLifecycle in Worker class
- Add queue creation and logging in WorkerLifecycle start method
  • Loading branch information
jumski committed Jan 21, 2025
1 parent 297f2b6 commit a700ef1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkgs/edge-worker/src/Worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import postgres from 'postgres';
import { Json, WorkerBootstrap } from './types.ts';
import type { Json, WorkerBootstrap } from './types.ts';
import { Queue } from './Queue.ts';
import { Queries } from './Queries.ts';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from './ExecutionController.ts';
import { Logger } from './Logger.ts';
import { WorkerLifecycle, type LifecycleConfig } from './WorkerLifecycle.ts';
import { PollerConfig } from './ReadWithPollPoller.ts';
import type { PollerConfig } from './ReadWithPollPoller.ts';
import { BatchProcessor } from './BatchProcessor.ts';

export type WorkerConfig = {
Expand All @@ -22,7 +22,7 @@ export class Worker<MessagePayload extends Json> {
private config: Required<WorkerConfig>;
private executionController: ExecutionController<MessagePayload>;
private messageHandler: (message: MessagePayload) => Promise<void>;
private lifecycle: WorkerLifecycle;
private lifecycle: WorkerLifecycle<MessagePayload>;
private logger: Logger;
private abortController = new AbortController();

Expand Down
3 changes: 3 additions & 0 deletions pkgs/edge-worker/src/WorkerLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class WorkerLifecycle<MessagePayload extends Json> {
async acknowledgeStart(workerBootstrap: WorkerBootstrap): Promise<void> {
this.workerState.transitionTo(States.Starting);

this.logger.log(`Ensuring queue '${this.queue.queueName}' exists...`);
this.queue.safeCreate();

this.workerRow = await this.queries.onWorkerStarted({
queueName: this.queueName,
...workerBootstrap,
Expand Down

0 comments on commit a700ef1

Please sign in to comment.