Skip to content

Commit

Permalink
Add Item iter
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Mar 13, 2024
1 parent e319453 commit e81d9c5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions api/routes/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,27 @@ export default async function router(schema: Schema, config: Config) {
try {
await Auth.is_auth(config, req);

// TODO there is a limit here to how many will be returned
// switch to an async iter or stream
const list = await config.models.Layer.list();

for (const layer of list.items) {
const status = (await CloudFormation.status(config, layer.id)).status;
if (!status.endsWith('_COMPLETE')) continue;

try {
const lambda = await Lambda.generate(config, layer);
if (await CloudFormation.exists(config, layer.id)) {
await CloudFormation.update(config, layer.id, lambda);
} else {
await CloudFormation.create(config, layer.id, lambda);
let page = 0;
let list;
do {
list = await config.models.Layer.list({ page, limit: 25 });

for (const layer of list.items) {
const status = (await CloudFormation.status(config, layer.id)).status;
if (!status.endsWith('_COMPLETE')) continue;

try {
const lambda = await Lambda.generate(config, layer);
if (await CloudFormation.exists(config, layer.id)) {
await CloudFormation.update(config, layer.id, lambda);
} else {
await CloudFormation.create(config, layer.id, lambda);
}
} catch (err) {
console.error(err);
}
} catch (err) {
console.error(err);
}
}
} while (list.items.length)

return res.json({
status: 200,
Expand Down

0 comments on commit e81d9c5

Please sign in to comment.