Skip to content

Commit 081bf00

Browse files
authored
Merge pull request #226 from import-ai/fix/pipes
fix(app): fix filter and pipe config
2 parents 5fb4c9f + 4635647 commit 081bf00

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/app/app-config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ConsoleLogger, INestApplication, LogLevel } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import * as express from 'express';
44
import * as cookieParser from 'cookie-parser';
5-
import { I18nValidationExceptionFilter, I18nValidationPipe } from 'nestjs-i18n';
65

76
export function configureApp(app: INestApplication): INestApplication {
87
app.use(express.json({ limit: '10mb' }));
@@ -16,12 +15,5 @@ export function configureApp(app: INestApplication): INestApplication {
1615
const logger = new ConsoleLogger({ json: true, logLevels });
1716
app.useLogger(logger);
1817

19-
app.useGlobalPipes(new I18nValidationPipe());
20-
app.useGlobalFilters(
21-
new I18nValidationExceptionFilter({
22-
detailedErrors: false,
23-
}),
24-
);
25-
2618
return app;
2719
}

src/app/app.module.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
MiddlewareConsumer,
44
Module,
55
NestModule,
6-
ValidationPipe,
76
} from '@nestjs/common';
87
import { SerializerInterceptor } from 'omniboxd/interceptor/serializer.interceptor';
9-
import { APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
8+
import { APP_FILTER, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
109
import { TypeOrmModule } from '@nestjs/typeorm';
1110
import { TagModule } from 'omniboxd/tag/tag.module';
1211
import { CacheModule } from '@nestjs/cache-manager';
@@ -22,6 +21,8 @@ import {
2221
AcceptLanguageResolver,
2322
HeaderResolver,
2423
I18nModule,
24+
I18nValidationExceptionFilter,
25+
I18nValidationPipe,
2526
QueryResolver,
2627
} from 'nestjs-i18n';
2728
import * as path from 'path';
@@ -82,7 +83,7 @@ export class AppModule implements NestModule {
8283
providers: [
8384
{
8485
provide: APP_PIPE,
85-
useValue: new ValidationPipe({
86+
useValue: new I18nValidationPipe({
8687
transform: true,
8788
// whitelist: true,
8889
// forbidNonWhitelisted: true,
@@ -100,6 +101,12 @@ export class AppModule implements NestModule {
100101
provide: APP_INTERCEPTOR,
101102
useClass: UserInterceptor,
102103
},
104+
{
105+
provide: APP_FILTER,
106+
useValue: new I18nValidationExceptionFilter({
107+
detailedErrors: false,
108+
}),
109+
},
103110
],
104111
imports: [
105112
ConfigModule.forRoot({

src/wizard/wizard.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,17 @@ export class WizardService {
393393
const andCondition: string = andConditions.map((x) => `AND ${x}`).join(' ');
394394
const rawQuery = `
395395
WITH
396+
cutoff_time AS (
397+
SELECT NOW() - INTERVAL '10 minutes' AS time
398+
),
396399
running_tasks_sub_query AS (
397400
SELECT
398401
namespace_id,
399402
COUNT(id) AS running_count
400403
FROM tasks
404+
CROSS JOIN cutoff_time
401405
WHERE started_at IS NOT NULL
406+
AND started_at > cutoff_time.time
402407
AND ended_at IS NULL
403408
AND canceled_at IS NULL
404409
AND deleted_at IS NULL
@@ -407,11 +412,13 @@ export class WizardService {
407412
id_subquery AS (
408413
SELECT tasks.id
409414
FROM tasks
415+
CROSS JOIN cutoff_time
410416
LEFT OUTER JOIN running_tasks_sub_query
411417
ON tasks.namespace_id = running_tasks_sub_query.namespace_id
412418
LEFT OUTER JOIN namespaces
413419
ON tasks.namespace_id = namespaces.id
414-
WHERE tasks.started_at IS NULL
420+
WHERE (tasks.started_at IS NULL OR tasks.started_at <= cutoff_time.time)
421+
AND tasks.ended_at IS NULL
415422
AND tasks.canceled_at IS NULL
416423
AND tasks.deleted_at IS NULL
417424
AND COALESCE(running_tasks_sub_query.running_count, 0) < COALESCE(namespaces.max_running_tasks, 0)
@@ -423,8 +430,7 @@ export class WizardService {
423430
)
424431
SELECT *
425432
FROM tasks
426-
WHERE id IN (SELECT id FROM id_subquery)
427-
FOR UPDATE SKIP LOCKED;
433+
WHERE id IN (SELECT id FROM id_subquery);
428434
`;
429435

430436
const queryResult =

0 commit comments

Comments
 (0)