Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ S3_SECRET_KEY="some_secret_key"
S3_PORT=9000 # optional
S3_REGION="us-east-1"
S3_BUCKET="bucket_name" # by default "playwright-reports-server"
S3_BATCH_SIZE=10 # by default 10
S3_BATCH_SIZE=10 # by default 10
S3_MULTIPART_CHUNK_SIZE_MB=25 # by default 25MB, controls chunk size for multipart uploads to reduce RAM usage
25 changes: 25 additions & 0 deletions app/api/cache/refresh/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { revalidatePath } from 'next/cache';

import { withError } from '@/app/lib/withError';
import { forceInitDatabase } from '@/app/lib/service/db';
import { env } from '@/app/config/env';
import { configCache } from '@/app/lib/service/cache/config';

export const dynamic = 'force-dynamic'; // defaults to auto

export async function POST(_: Request) {
if (!env.USE_SERVER_CACHE) {
return Response.json({ error: 'USE_SERVER_CACHE is disabled' }, { status: 403 });
}

configCache.initialized = false;
const { error } = await withError(Promise.all([configCache.init(), forceInitDatabase()]));

revalidatePath('/');

if (error) {
return Response.json({ error: error?.message }, { status: 500 });
}

return Response.json({ success: true });
}
3 changes: 2 additions & 1 deletion app/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export const env = cleanEnv(process.env, {
UI_AUTH_EXPIRE_HOURS: str({ desc: 'How much hours are allowed to keep auth session valid', default: '2' }),
AUTH_SECRET: str({ desc: 'Secret for JWT', default: undefined }),
DATA_STORAGE: str({ desc: 'Where to store data', default: 'fs' }),
USE_SERVER_CACHE: bool({ desc: 'Use server side indexed cache for backend queries', default: false }),
USE_SERVER_CACHE: bool({ desc: 'Use sqlite for metadata storing, cache config', default: false }),
S3_ENDPOINT: str({ desc: 'S3 endpoint', default: undefined }),
S3_ACCESS_KEY: str({ desc: 'S3 access key', default: undefined }),
S3_SECRET_KEY: str({ desc: 'S3 secret key', default: undefined }),
S3_PORT: num({ desc: 'S3 port', default: undefined }),
S3_REGION: str({ desc: 'S3 region', default: undefined }),
S3_BUCKET: str({ desc: 'S3 bucket', default: 'playwright-reports-server' }),
S3_BATCH_SIZE: num({ desc: 'S3 batch size', default: 10 }),
S3_MULTIPART_CHUNK_SIZE_MB: num({ desc: 'S3 multipart upload chunk size in MB', default: 25 }),
RESULT_EXPIRE_DAYS: num({ desc: 'How much days to keep results', default: undefined }),
RESULT_EXPIRE_CRON_SCHEDULE: str({ desc: 'Cron schedule for results cleanup', default: '33 3 * * *' }),
REPORT_EXPIRE_DAYS: num({ desc: 'How much days to keep reports', default: undefined }),
Expand Down
10 changes: 5 additions & 5 deletions app/lib/service/cache/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { env } from '@/app/config/env';
import { SiteWhiteLabelConfig } from '@/app/types';
import { defaultConfig } from '@/app/lib/config';

const initiatedConfigDb = Symbol.for('playwright.reports.db.config');
const instance = globalThis as typeof globalThis & { [initiatedConfigDb]?: ConfigCache };

export class ConfigCache {
private static instance: ConfigCache;
public initialized = false;
public config: SiteWhiteLabelConfig | undefined;

private constructor() {}

public static getInstance() {
if (!ConfigCache.instance) {
ConfigCache.instance = new ConfigCache();
}
instance[initiatedConfigDb] ??= new ConfigCache();

return ConfigCache.instance;
return instance[initiatedConfigDb];
}

public async init(): Promise<void> {
Expand Down
3 changes: 0 additions & 3 deletions app/lib/service/cache/index.ts

This file was deleted.

77 changes: 0 additions & 77 deletions app/lib/service/cache/reports.ts

This file was deleted.

80 changes: 0 additions & 80 deletions app/lib/service/cache/results.ts

This file was deleted.

10 changes: 5 additions & 5 deletions app/lib/service/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { service } from '@/app/lib/service';
import { env } from '@/app/config/env';
import { withError } from '@/app/lib/withError';

const runningCron = Symbol.for('playwright.reports.cron.service');
const instance = globalThis as typeof globalThis & { [runningCron]?: CronService };

export class CronService {
private static instance: CronService;
public initialized = false;

private clearResultsJob: Cron | undefined;
private clearReportsJob: Cron | undefined;

public static getInstance() {
if (!CronService.instance) {
CronService.instance = new CronService();
}
instance[runningCron] ??= new CronService();

return CronService.instance;
return instance[runningCron];
}

private constructor() {
Expand Down
Loading