Skip to content

Commit

Permalink
fix: don't require a commit hash file in dev runs
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Jan 29, 2024
1 parent 22e3e8d commit d679ed4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/flush-redis-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export async function flushRedisCache () {
const filePath = path.join(path.resolve(), 'data/LAST_API_COMMIT_HASH.txt');

const lastCommitHashInRedis = await persistentRedis.get(`LAST_API_COMMIT_HASH_${hostname}`);
const currentLastCommitHash = (await readFile(filePath, 'utf8')).trim();
const currentLastCommitHash = (await readFile(filePath, 'utf8').catch(() => '')).trim();

if (lastCommitHashInRedis !== currentLastCommitHash) {
if (process.env['NODE_ENV'] === 'production' && !currentLastCommitHash) {
throw new Error(`Current commit hash missing in ${filePath}`);
}

if (!currentLastCommitHash || lastCommitHashInRedis !== currentLastCommitHash) {
logger.info('Latest commit hash changed. Clearing redis cache.');
await redis.flushDb();
await persistentRedis.set(`LAST_API_COMMIT_HASH_${hostname}`, currentLastCommitHash);
Expand Down

0 comments on commit d679ed4

Please sign in to comment.