feat: add SSE event stream for print jobs, implement batch printing in frontend, and update API documentation.
Build and Push Multi-Platform Images / build-and-push (push) Successful in 36s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 36s
This commit is contained in:
@@ -4,16 +4,20 @@ import {
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
MessageEvent,
|
||||
NotFoundException,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Query,
|
||||
Res,
|
||||
Sse,
|
||||
StreamableFile,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { JwtOrApiKeyGuard } from '../auth/jwt-or-apikey.guard';
|
||||
import { RequirePermissions } from '../auth/permissions.decorator';
|
||||
import { Permission } from '../auth/permissions.enum';
|
||||
@@ -48,6 +52,14 @@ export class LabelPrintAgentController {
|
||||
return { jobId: String(job.Id) };
|
||||
}
|
||||
|
||||
// Agent: SSE-Stream für neue Druckaufträge
|
||||
@Sse('events')
|
||||
sseEvents(): Observable<MessageEvent> {
|
||||
return this.service.newJob$.pipe(
|
||||
map(() => ({ data: { type: 'label-job-available' } } as MessageEvent)),
|
||||
);
|
||||
}
|
||||
|
||||
// Agent: nächsten Job abholen (Polling)
|
||||
@Get('jobs/next')
|
||||
async getNextJob(@Query('agentId') agentId: string, @Res({ passthrough: true }) res: Response) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable, Logger, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, LessThan, IsNull, Or } from 'typeorm';
|
||||
import { Repository, LessThan, IsNull } from 'typeorm';
|
||||
import { Subject, Observable } from 'rxjs';
|
||||
import { LabelPrintJob } from '../database/entities/label-print-job.entity';
|
||||
import { BarcodeTemplate } from '../database/entities/barcode-template.entity';
|
||||
import { LabelRendererService } from './label-renderer.service';
|
||||
@@ -28,6 +29,11 @@ function lockExpiry(): Date {
|
||||
@Injectable()
|
||||
export class LabelPrintAgentService {
|
||||
private readonly logger = new Logger(LabelPrintAgentService.name);
|
||||
private readonly jobCreated$ = new Subject<void>();
|
||||
|
||||
get newJob$(): Observable<void> {
|
||||
return this.jobCreated$.asObservable();
|
||||
}
|
||||
|
||||
constructor(
|
||||
@InjectRepository(LabelPrintJob)
|
||||
@@ -85,7 +91,9 @@ export class LabelPrintAgentService {
|
||||
LockedByAgent: null,
|
||||
});
|
||||
|
||||
return this.jobRepo.save(job);
|
||||
const saved = await this.jobRepo.save(job);
|
||||
this.jobCreated$.next();
|
||||
return saved;
|
||||
}
|
||||
|
||||
async claimNextJob(agentId: string): Promise<LabelPrintJob | null> {
|
||||
|
||||
Reference in New Issue
Block a user