Commit 8e296906 authored by nanahira's avatar nanahira

skew ahead time for uploads

parent 43fc3693
Pipeline #25375 passed with stages
in 4 minutes and 5 seconds
......@@ -271,7 +271,7 @@ export class PackagerService extends ConsoleLogger {
let tmpFilename: string;
try {
if (files.length > 2000) {
/*if (files.length > 2000) {
// minio would skew the stream if it's too slow
// use a tmp file to put the stream
......@@ -286,7 +286,7 @@ export class PackagerService extends ConsoleLogger {
});
// open the tmp file as a new stream
uploadStream = fs.createReadStream(tmpFilename);
}
}*/
const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, {
ContentType: 'application/tar+zstd',
......
import { ConsoleLogger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { _Object, DeleteObjectsCommand, ListObjectsCommand, PutObjectCommand, PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3';
import {
_Object,
DeleteObjectsCommand,
ListObjectsCommand,
PutObjectCommand,
PutObjectCommandInput,
S3Client,
S3ClientConfig,
} from '@aws-sdk/client-s3';
import { createHash } from 'crypto';
import internal from 'stream';
import { Upload } from '@aws-sdk/lib-storage';
......@@ -11,11 +19,6 @@ export interface S3StreamUploadResult {
}
export class S3Service extends ConsoleLogger {
private readonly bucket: string;
private readonly prefix: string;
public readonly cdnUrl: string;
private readonly s3: S3Client;
private getConfig(field: string) {
return this.config.get(`${this.servicePrefix}_${field}`) || this.config.get(field);
}
......@@ -24,12 +27,11 @@ export class S3Service extends ConsoleLogger {
return `${this.cdnUrl}/${path}`;
}
constructor(private servicePrefix: string, private config: ConfigService) {
super(`${servicePrefix} s3`);
this.bucket = this.getConfig('S3_BUCKET');
this.prefix = this.getConfig('S3_PREFIX');
this.cdnUrl = this.getConfig('S3_CDN_URL') || `${this.getConfig('S3_ENDPOINT')}/${this.bucket}${this.prefix ? `/${this.prefix}` : ''}`;
this.s3 = new S3Client({
private readonly bucket = this.getConfig('S3_BUCKET');
private readonly prefix = this.getConfig('S3_PREFIX');
public readonly cdnUrl =
this.getConfig('S3_CDN_URL') || `${this.getConfig('S3_ENDPOINT')}/${this.bucket}${this.prefix ? `/${this.prefix}` : ''}`;
private readonly s3Config: S3ClientConfig = {
credentials: {
accessKeyId: this.getConfig('S3_KEY'),
secretAccessKey: this.getConfig('S3_SECRET'),
......@@ -37,7 +39,19 @@ export class S3Service extends ConsoleLogger {
region: this.getConfig('S3_REGION') || 'us-west-1',
endpoint: this.getConfig('S3_ENDPOINT'),
forcePathStyle: true,
});
};
private readonly s3ConfigSkewed: S3ClientConfig = {
...this.s3Config,
// skew 14 mins ahead for long upload
systemClockOffset: 14 * 60 * 1000,
};
private readonly s3 = new S3Client(this.s3Config);
private readonly skewedS3 = new S3Client(this.s3ConfigSkewed);
constructor(private servicePrefix: string, private config: ConfigService) {
super(`${servicePrefix} s3`);
}
async listObjects(path: string) {
......@@ -115,7 +129,7 @@ export class S3Service extends ConsoleLogger {
async uploadStream(path: string, stream: internal.Readable, extras: Partial<PutObjectCommandInput> = {}) {
const key = this.getPathWithPrefix(path);
const upload = new Upload({
client: this.s3,
client: this.skewedS3,
params: {
Bucket: this.bucket,
Key: key,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment