anchan828 / nest-cloud-run-queue

Create a Queue/Worker for NestJS application in Cloud Run.
MIT License
36 stars 1 forks source link

feat: get workers/processors #1827

Closed anchan828 closed 4 months ago

anchan828 commented 4 months ago

Execute worker/processor manually

You can execute worker/processor manually.

@Controller("/worker")
class WorkerController {
  constructor(private readonly service: QueueWorkerService) {}

  @Post()
  public async execute(@Body() body: QueueWorkerReceivedMessage): Promise<void> {
    const workers = await this.service.getWorkers(body.message);

    for (const worker of workers) {
      const processors = worker.getProcessors();

      for (const processor of processors) {
        const result = await processor.execute();

        if (result.success) {
          console.log("Success");
        } else {
          console.log("Failed:" + result.error.message);
        }
      }
    }
  }
}

Breaking changes