Skip to content

Commit

Permalink
Use first 5MB of media files for probe
Browse files Browse the repository at this point in the history
  • Loading branch information
knpwrs committed Nov 27, 2024
1 parent 1dd845e commit 9909140
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions services/gateway/src/temporal/activities/probe/probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export default async function probe(
await mkdirp(workingDir);

const downloadPath = join(workingDir, 'download');
await streamObjectToFile('INGEST', s3UploadKey, downloadPath, () =>
Context.current().heartbeat('download'),
);
const uploadSizeBytes = (await headObject('INGEST', s3UploadKey))
?.ContentLength;
invariant(uploadSizeBytes, 'Invalid uploadSizeBytes');
await streamObjectToFile('INGEST', s3UploadKey, downloadPath, {
heartbeat: () => Context.current().heartbeat('download'),
Range: `bytes=0-${Math.min(5 * 1024 ** 2 - 1, uploadSizeBytes - 1)}`,
});
await mkdirp(workingDir);

activityLogger.info(`Probing ${downloadPath}`);
Expand Down
13 changes: 11 additions & 2 deletions services/gateway/src/util/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DeleteObjectCommand,
DeleteObjectsCommand,
GetObjectCommand,
GetObjectCommandInput,
ListObjectsV2Command,
PutObjectCommand,
S3,
Expand Down Expand Up @@ -242,10 +243,18 @@ export async function streamObjectToFile(
from: Client,
key: string,
path: string,
heartbeat?: (arg: string) => unknown,
extra?:
| (Omit<GetObjectCommandInput, 'Bucket' | 'Key'> & {
heartbeat?: (arg: string) => unknown;
})
| ((arg: string) => unknown),
) {
const { client, bucket } = getClientAndBucket(from);
const cmd = new GetObjectCommand({ Bucket: bucket, Key: key });
const { getArgs, heartbeat } =
typeof extra === 'function'
? { getArgs: {}, heartbeat: extra }
: { getArgs: extra, heartbeat: undefined };
const cmd = new GetObjectCommand({ Bucket: bucket, Key: key, ...getArgs });
const res = await client.send(cmd);

invariant(res.Body, 'No body in response!');
Expand Down

0 comments on commit 9909140

Please sign in to comment.