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

Commit

Permalink
feat: have the s3 lock cleanup gracefully
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
jacobheun committed Jan 25, 2019
1 parent b8eab5a commit 7f6b2c8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion examples/full-s3-repo/s3-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class S3Lock {
* @returns {LockCloser}
*/
getCloser (lockPath) {
return {
const closer = {
/**
* Removes the lock. This can be overriden to customize how the lock is removed. This
* is important for removing any created locks.
Expand All @@ -74,6 +74,23 @@ class S3Lock {
})
}
}

const cleanup = () => {
console.log('\nAttempting to cleanup gracefully...')

closer.close(() => {
console.log('Cleanup complete, exiting.')
process.exit()
})
}

// listen for graceful termination
process.on('SIGTERM', cleanup)
process.on('SIGINT', cleanup)
process.on('SIGHUP', cleanup)
process.on('uncaughtException', cleanup)

return closer
}

/**
Expand Down

0 comments on commit 7f6b2c8

Please sign in to comment.