Skip to content

Commit

Permalink
Feat: Pass in signal to cleanup function
Browse files Browse the repository at this point in the history
  • Loading branch information
hienngm committed Jul 26, 2024
1 parent c00a523 commit 3d63f72
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/deploy-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy npm package

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['14.x', '16.x', '18.x', '20.x']

steps:
- name: Git clone the repository
uses: actions/checkout@v3

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Build the code
run: npm run build

- name: Run tests
run: npm run test

deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Make test coverage
run: npm run cov

- name: Coveralls
uses: coverallsapp/github-action@v2

- name: Deploy to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
2 changes: 0 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: E2E tests
on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
verify_pull_request:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ interface IGracefulShutdownConfigOptions {
* Cleanup function for releasing application resources
* during server shutdown.
*/
cleanup?: (app: INestApplication) => any;
cleanup?: (app: INestApplication, signal?: string) => any;
/**
* The duration in milliseconds before forcefully
* terminating a connection.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/graceful-shutdown.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IGracefulShutdownConfigOptions {
* Cleanup function for releasing application resources
* during server shutdown.
*/
cleanup?: (app: INestApplication) => any;
cleanup?: (app: INestApplication, signal?: string) => any;
/**
* The duration in milliseconds before forcefully
* terminating a connection.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/graceful-shutdown.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class GracefulShutdownService
throw SetupFunctionNotInvoked;
}

await this.options.cleanup?.(this.app);
await this.options.cleanup?.(this.app, signal);
if (signal && this.options.keepNodeProcessAlive) {
this.skipShutdownSignal(signal);
}
Expand Down

0 comments on commit 3d63f72

Please sign in to comment.