Skip to content

Commit

Permalink
Add throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Mar 13, 2024
1 parent e81d9c5 commit 8c3bf66
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions api/routes/layer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type, Static } from '@sinclair/typebox'
import sleep from '../lib/sleep.js';
import { GenericListOrder } from '@openaddresses/batch-generic';
import Schema from '@openaddresses/batch-schema';
import { check } from '@placemarkio/check-geojson';
Expand Down Expand Up @@ -175,18 +176,18 @@ export default async function router(schema: Schema, config: Config) {
let list;
do {
list = await config.models.Layer.list({ page, limit: 25 });
++page;

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);
}

await sleep(50) //Otherwise AWS will throw Throttling exceptions
} catch (err) {
console.error(err);
}
Expand Down

0 comments on commit 8c3bf66

Please sign in to comment.