Skip to content

Commit 6c9c214

Browse files
committed
fix(storage-resize-image): build
1 parent 3c8d129 commit 6c9c214

File tree

1 file changed

+77
-77
lines changed
  • storage-resize-images/functions/src

1 file changed

+77
-77
lines changed

storage-resize-images/functions/src/index.ts

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -156,80 +156,80 @@ export const generateResizedImage = functions.storage
156156
/**
157157
*
158158
*/
159-
export const backfillResizedImages = functions.tasks
160-
.taskQueue()
161-
.onDispatch(async (data) => {
162-
const runtime = getExtensions().runtime();
163-
if (!config.doBackfill) {
164-
await runtime.setProcessingState(
165-
"PROCESSING_COMPLETE",
166-
"Existing images were not resized because 'Backfill existing images' was configured to false." +
167-
" If you want to resize existing images, reconfigure this instance."
168-
);
169-
return;
170-
}
171-
if (data?.nextPageQuery == undefined) {
172-
logs.startBackfill();
173-
}
174-
175-
const bucket = admin.storage().bucket(process.env.IMG_BUCKET);
176-
const query = data.nextPageQuery || {
177-
autoPaginate: false,
178-
maxResults: config.backfillBatchSize,
179-
};
180-
const [files, nextPageQuery] = await bucket.getFiles(query);
181-
const filesToResize = files.filter((f: File) => {
182-
logs.continueBackfill(f.metadata.name);
183-
return shouldResize(convertToObjectMetadata(f.metadata));
184-
});
185-
186-
const filePromises = filesToResize.map((f) => {
187-
return generateResizedImageHandler(
188-
convertToObjectMetadata(f.metadata),
189-
/*verbose=*/ false
190-
);
191-
});
192-
const results = await Promise.allSettled(filePromises);
193-
194-
const pageErrorsCount = results.filter(
195-
(r) => r.status === "rejected"
196-
).length;
197-
const pageSuccessCount = results.filter(
198-
(r) => r.status === "fulfilled"
199-
).length;
200-
const oldErrorsCount = Number(data.errorsCount) || 0;
201-
const oldSuccessCount = Number(data.successCount) || 0;
202-
const errorsCount = pageErrorsCount + oldErrorsCount;
203-
const successCount = pageSuccessCount + oldSuccessCount;
204-
205-
if (nextPageQuery) {
206-
const queue = getFunctions().taskQueue(
207-
`locations/${config.location}/functions/backfillResizedImages`,
208-
process.env.EXT_INSTANCE_ID
209-
);
210-
await queue.enqueue({
211-
nextPageQuery,
212-
errorsCount,
213-
successCount,
214-
});
215-
} else {
216-
logs.backfillComplete(successCount, errorsCount);
217-
if (errorsCount == 0) {
218-
await runtime.setProcessingState(
219-
"PROCESSING_COMPLETE",
220-
`Successfully resized ${successCount} images.`
221-
);
222-
} else if (errorsCount > 0 && successCount > 0) {
223-
await runtime.setProcessingState(
224-
"PROCESSING_WARNING",
225-
`Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
226-
);
227-
}
228-
if (errorsCount > 0 && successCount == 0) {
229-
await runtime.setProcessingState(
230-
"PROCESSING_FAILED",
231-
`Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
232-
);
233-
}
234-
}
235-
});
159+
// export const backfillResizedImages = functions.tasks
160+
// .taskQueue()
161+
// .onDispatch(async (data) => {
162+
// const runtime = getExtensions().runtime();
163+
// if (!config.doBackfill) {
164+
// await runtime.setProcessingState(
165+
// "PROCESSING_COMPLETE",
166+
// "Existing images were not resized because 'Backfill existing images' was configured to false." +
167+
// " If you want to resize existing images, reconfigure this instance."
168+
// );
169+
// return;
170+
// }
171+
// if (data?.nextPageQuery == undefined) {
172+
// logs.startBackfill();
173+
// }
174+
175+
// const bucket = admin.storage().bucket(process.env.IMG_BUCKET);
176+
// const query = data.nextPageQuery || {
177+
// autoPaginate: false,
178+
// maxResults: config.backfillBatchSize,
179+
// };
180+
// const [files, nextPageQuery] = await bucket.getFiles(query);
181+
// const filesToResize = files.filter((f: File) => {
182+
// logs.continueBackfill(f.metadata.name);
183+
// return shouldResize(convertToObjectMetadata(f.metadata));
184+
// });
185+
186+
// const filePromises = filesToResize.map((f) => {
187+
// return generateResizedImageHandler(
188+
// convertToObjectMetadata(f.metadata),
189+
// /*verbose=*/ false
190+
// );
191+
// });
192+
// const results = await Promise.allSettled(filePromises);
193+
194+
// const pageErrorsCount = results.filter(
195+
// (r) => r.status === "rejected"
196+
// ).length;
197+
// const pageSuccessCount = results.filter(
198+
// (r) => r.status === "fulfilled"
199+
// ).length;
200+
// const oldErrorsCount = Number(data.errorsCount) || 0;
201+
// const oldSuccessCount = Number(data.successCount) || 0;
202+
// const errorsCount = pageErrorsCount + oldErrorsCount;
203+
// const successCount = pageSuccessCount + oldSuccessCount;
204+
205+
// if (nextPageQuery) {
206+
// const queue = getFunctions().taskQueue(
207+
// `locations/${config.location}/functions/backfillResizedImages`,
208+
// process.env.EXT_INSTANCE_ID
209+
// );
210+
// await queue.enqueue({
211+
// nextPageQuery,
212+
// errorsCount,
213+
// successCount,
214+
// });
215+
// } else {
216+
// logs.backfillComplete(successCount, errorsCount);
217+
// if (errorsCount == 0) {
218+
// await runtime.setProcessingState(
219+
// "PROCESSING_COMPLETE",
220+
// `Successfully resized ${successCount} images.`
221+
// );
222+
// } else if (errorsCount > 0 && successCount > 0) {
223+
// await runtime.setProcessingState(
224+
// "PROCESSING_WARNING",
225+
// `Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
226+
// );
227+
// }
228+
// if (errorsCount > 0 && successCount == 0) {
229+
// await runtime.setProcessingState(
230+
// "PROCESSING_FAILED",
231+
// `Successfully resized ${successCount} images, failed to resize ${errorsCount} images. See function logs for error details.`
232+
// );
233+
// }
234+
// }
235+
// });

0 commit comments

Comments
 (0)