Skip to content

Commit

Permalink
Adds sleep.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Prickett committed Feb 20, 2023
1 parent 905775b commit 4429cfd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion enricher/enricher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const REDIS_URL = process.env.REDIS_URL || 'redis:https://127.0.0.1:6379';
const FLIGHTAWARE_API_KEY = process.env.FLIGHTAWARE_API_KEY;
const FLIGHTAWARE_QUEUE = 'flightawarequeue';

// Sleep for 5 seconds... used as a lazy way to avoid
// rate limiting on the FlightAware API...
async function sleep() {
return new Promise((resolve) => {
setTimeout(resolve, 5000);
});
};

const redisClient = createClient({
url: REDIS_URL
});
Expand Down Expand Up @@ -60,14 +68,17 @@ while (true) {
}
}

// TODO sleep for a couple of seconds...
} else {
console.log(`Error talking to FlightAware API returned ${flightAwareResponse.status} code.`);
}
} catch (e) {
console.log('Error talking to FlightAware API:');
console.log(e);
}

// Sleep to prevent FlightAware rate limiter kicking in (this is a very
// lazy way of dealing with this!).
await sleep();
} else {
console.log('No new work to do.');
}
Expand Down

0 comments on commit 4429cfd

Please sign in to comment.