Skip to content

Commit

Permalink
HARMONY-1538: More debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
indiejames committed Oct 13, 2023
1 parent 0f309d8 commit 5950d2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions services/service-runner/app/workers/pull-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ async function _pullAndDoWork(repeat = true): Promise<void> {
try {
// remove any previous work items to prevent the pod from running out of disk space
const regex = /^(?!WORKING|TERMINATING)(.+)$/;
logger.info('Starting to empty directory');
console.log('Starting to empty directory');
await emptyDirectory(env.workingDir, regex);
logger.info('Directory emptied');
console.log('Directory emptied');
// write out the WORKING file to prevent pod termination while working
logger.info('WRITING WORKING FILE');
console.log('WRITING WORKING FILE');
await fs.writeFile(workingFilePath, '1');
logger.info('WORKING FILE WRITTEN');
console.log('WORKING FILE WRITTEN');
} catch (e) {
// We'll continue on even if we have issues cleaning up - it just means the pod may end
// up being evicted at some point due to running out of ephemeral storage space
Expand All @@ -173,16 +173,16 @@ async function _pullAndDoWork(repeat = true): Promise<void> {
// check to see if we are terminating
const terminationFilePath = path.join(env.workingDir, 'TERMINATING');
try {
logger.info('CHECKING FOR TERMINATING FILE');
console.log('CHECKING FOR TERMINATING FILE');
await fs.access(terminationFilePath);
logger.info('DONE CHECKING FOR TERMINATING FILE');
console.log('DONE CHECKING FOR TERMINATING FILE');
// TERMINATING file exists so PreStop handler is requesting termination
logger.warn('Received TERMINATION request, no longer processing work');
try {
// Clean up the TERMINATING file to ensure we do not stay in an infinite loop terminating
logger.info('UNLINKNG TERMINATING FILE');
console.log('UNLINKNG TERMINATING FILE');
await fs.unlink(terminationFilePath);
logger.info('TERMINATING FILE UNLINKED');
console.log('TERMINATING FILE UNLINKED');
} catch (e) {
logger.error('Error removing TERMINATING file, will still attempt to quit');
logger.error(e);
Expand All @@ -193,7 +193,7 @@ async function _pullAndDoWork(repeat = true): Promise<void> {
// expected if file does not exist
}

logger.info('ABOUT TO POLL FOR WORK');
console.log('ABOUT TO POLL FOR WORK');

pullCounter += 1;
logger.debug('Polling for work');
Expand Down Expand Up @@ -235,15 +235,15 @@ async function _pullAndDoWork(repeat = true): Promise<void> {
logger.error(e);
} finally {
// remove the WORKING file
logger.info('UNLINKING WORKING FILE');
console.log('UNLINKING WORKING FILE');
try {
await fs.unlink(workingFilePath);
} catch {
// log this, but don't let it stop things
logger.error('Failed to delete /tmp/WORKING');
}
if (repeat) {
logger.info('REPEATING POLLING FOR WORK');
console.log('REPEATING POLLING FOR WORK');
setTimeout(_pullAndDoWork, pollingInterval);
}
}
Expand Down
8 changes: 4 additions & 4 deletions services/service-runner/test/pull-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ describe('Pull Worker', async function () {
});

it('deletes the WORKING lock file', async function () {
console.log(`STARTING _pullAndDoWork`);
console.log('STARTING _pullAndDoWork');
await _pullAndDoWork(false);
console.log(`COMPLETED _pullAndDoWork`);
console.log(`existsSync CHECK STARTED`);
console.log('COMPLETED _pullAndDoWork');
console.log('existsSync CHECK STARTED');
expect(existsSync(`${env.workingDir}/WORKING`)).to.be.false;
console.log(`existsSync CHECK COMPLTED`);
console.log('existsSync CHECK COMPLTED');
});

it('does not throw', async function () {
Expand Down

0 comments on commit 5950d2d

Please sign in to comment.