MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / job

Function job

packages/maintenance/src/s3-cache-control.ts:35–82  ·  view source on GitHub ↗
(ContinuationToken: any)

Source from the content-addressed store, hash-verified

33run();
34
35async function job(ContinuationToken: any) {
36 const response = await s3Client.send(
37 new ListObjectsV2Command({
38 Bucket,
39 Prefix,
40 ...(ContinuationToken && { ContinuationToken }),
41 })
42 );
43 ContinuationToken = response.NextContinuationToken;
44 ContinuationToken &&
45 (await fs.writeFile(`${filePrefix}/token`, String(ContinuationToken)));
46
47 await fs.appendFile(
48 `${filePrefix}/content`,
49 response.Contents!?.map((c) => c.Key).join(os.EOL) + os.EOL
50 );
51
52 const jobs = await Promise.allSettled(
53 response.Contents?.filter((c) => {
54 if (c.Key !== encodeURI(c.Key!)) {
55 appendFileSync(`${filePrefix}/bad-input`, c.Key + os.EOL);
56 return false;
57 } else {
58 return true;
59 }
60 }).map((file) =>
61 s3Client.send(
62 new CopyObjectCommand({
63 Bucket,
64 CopySource: Bucket + '/' + file.Key,
65 Key: file.Key,
66 MetadataDirective: 'REPLACE',
67 CacheControl: 'max-age=15557000, stale-if-error=31536000',
68 })
69 )
70 ) || []
71 );
72 count += jobs.length;
73 console.log(count);
74 const rejected = jobs.filter((j) => j.status === 'rejected');
75 if (rejected.length) {
76 await fs.appendFile(
77 `${filePrefix}/failures`,
78 JSON.stringify(rejected, null, 2) + os.EOL
79 );
80 }
81 return ContinuationToken;
82}

Callers 1

runFunction · 0.85

Calls 3

mapMethod · 0.80
logMethod · 0.65
sendMethod · 0.45

Tested by

no test coverage detected