Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
How hard can this be...
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusAhlfors committed Aug 23, 2023
1 parent bd7e37f commit 619aad3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions initialProject/status/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ const getSupervisorStatus = async (name, process) => {
};

const getWWWStatus = async () => {
const belowYellowThreshold = (new Date().getTime() - timeStart) / 1000 < 30;
try {
const nextjsResponse = (await shellExec('curl http://localhost')).stdout;
if (nextjsResponse && nextjsResponse.includes('__NEXT_DATA__')) return { status: Status.GREEN, message: '' };
if (belowYellowThreshold) return { status: Status.YELLOW, message: 'Waiting for Next.js...' };
return { status: Status.RED, message: 'Next.js is not responding' };
} catch {
if (belowYellowThreshold) return { status: Status.YELLOW, message: 'Waiting for Next.js...' };
return { status: Status.RED, message: 'Failed to query Next.js status' };
}
};
Expand Down Expand Up @@ -90,19 +87,27 @@ const getPostgresStatus = async () => {
};

const getStatus = async () => {
// First see if supervisor has started www
const wwwProcessStatus = await getSupervisorStatus('Next.js', 'www');

let wwwStatus = {
identifier: 'www',
name: 'Next.js',
description: 'Next.js website',
...wwwProcessStatus,
};

// Then check if site is running
if (wwwProcessStatus.status === Status.GREEN) {
wwwStatus = { ...wwwStatus, ...(await getWWWStatus()) };
}

// Exception... Don't show red until some time has passed
const belowYellowThreshold = (new Date().getTime() - timeStart) / 1000 < 30;
if (wwwStatus.status === Status.RED && belowYellowThreshold) {
wwwStatus.status = Status.YELLOW;
wwwStatus.message = 'Waiting for Next.js...';
}

const status = {
diploiStatusVersion: 1,
items: [wwwStatus],
Expand Down

0 comments on commit 619aad3

Please sign in to comment.