Skip to content

Commit

Permalink
fix: trminus
Browse files Browse the repository at this point in the history
  • Loading branch information
linyyyang committed Nov 16, 2022
1 parent d50110b commit d4af2f2
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 113 deletions.
6 changes: 3 additions & 3 deletions docs/api/koatty_serve.createterminus.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Create terminus event
<b>Signature:</b>

```typescript
export declare function CreateTerminus(server: Server | Http2SecureServer, options?: TerminusOptions): void;
export declare function CreateTerminus(server: KoattyServer, options?: TerminusOptions): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| server | Server \| Http2SecureServer | |
| options | TerminusOptions | <i>(Optional)</i> |
| server | KoattyServer | |
| options | [TerminusOptions](./koatty_serve.terminusoptions.md) | <i>(Optional)</i> |

<b>Returns:</b>

Expand Down
3 changes: 1 addition & 2 deletions docs/api/koatty_serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
| --- | --- |
| [BindProcessEvent(event, originEventName, targetEventName)](./koatty_serve.bindprocessevent.md) | Bind event to the process |
| [CreateTerminus(server, options)](./koatty_serve.createterminus.md) | Create terminus event |
| [onShutdown()](./koatty_serve.onshutdown.md) | called right before exiting |
| [onSignal()](./koatty_serve.onsignal.md) | cleanup function, returning a promise (used to be onSigterm) |
| [Serve(app, opt)](./koatty_serve.serve.md) | Create Server |

## Interfaces
Expand All @@ -30,6 +28,7 @@
| --- | --- |
| [GrpcServerOptions](./koatty_serve.grpcserveroptions.md) | GrpcServerOptions {<!-- -->ListeningOptions<!-- -->} |
| [ListeningOptions](./koatty_serve.listeningoptions.md) | listening options ListeningOptions |
| [TerminusOptions](./koatty_serve.terminusoptions.md) | |
| [WebSocketServerOptions](./koatty_serve.websocketserveroptions.md) | |

## Type Aliases
Expand Down
19 changes: 0 additions & 19 deletions docs/api/koatty_serve.onshutdown.md

This file was deleted.

19 changes: 0 additions & 19 deletions docs/api/koatty_serve.onsignal.md

This file was deleted.

20 changes: 20 additions & 0 deletions docs/api/koatty_serve.terminusoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [koatty\_serve](./koatty_serve.md) &gt; [TerminusOptions](./koatty_serve.terminusoptions.md)

## TerminusOptions interface

<b>Signature:</b>

```typescript
export interface TerminusOptions
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [onSignal?](./koatty_serve.terminusoptions.onsignal.md) | (event: string, server: KoattyServer, forceTimeout: number) =&gt; Promise&lt;any&gt; | <i>(Optional)</i> |
| [signals?](./koatty_serve.terminusoptions.signals.md) | string\[\] | <i>(Optional)</i> |
| [timeout](./koatty_serve.terminusoptions.timeout.md) | number | |

11 changes: 11 additions & 0 deletions docs/api/koatty_serve.terminusoptions.onsignal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [koatty\_serve](./koatty_serve.md) &gt; [TerminusOptions](./koatty_serve.terminusoptions.md) &gt; [onSignal](./koatty_serve.terminusoptions.onsignal.md)

## TerminusOptions.onSignal property

<b>Signature:</b>

```typescript
onSignal?: (event: string, server: KoattyServer, forceTimeout: number) => Promise<any>;
```
11 changes: 11 additions & 0 deletions docs/api/koatty_serve.terminusoptions.signals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [koatty\_serve](./koatty_serve.md) &gt; [TerminusOptions](./koatty_serve.terminusoptions.md) &gt; [signals](./koatty_serve.terminusoptions.signals.md)

## TerminusOptions.signals property

<b>Signature:</b>

```typescript
signals?: string[];
```
11 changes: 11 additions & 0 deletions docs/api/koatty_serve.terminusoptions.timeout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [koatty\_serve](./koatty_serve.md) &gt; [TerminusOptions](./koatty_serve.terminusoptions.md) &gt; [timeout](./koatty_serve.terminusoptions.timeout.md)

## TerminusOptions.timeout property

<b>Signature:</b>

```typescript
timeout: number;
```
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"prepublishOnly": "npm test && npm run build",
"prerelease": "npm test && npm run build",
"release": "standard-version",
"release:minor": "npm run release -- --release-as minor",
"test": "npm run eslint && jest --passWithNoTests"
},
"main": "./dist/index.js",
Expand Down Expand Up @@ -74,17 +75,16 @@
"typescript": "^4.x.x"
},
"dependencies": {
"@godaddy/terminus": "^4.11.2",
"@grpc/grpc-js": "^1.7.3",
"koatty_core": "^1.x.x",
"koatty_lib": "^1.x.x",
"koatty_logger": "^1.x.x",
"tslib": "^2.4.0",
"ws": "^8.10.0"
"ws": "^8.11.0"
},
"peerDependencies": {
"koatty_core": "^1.x.x",
"koatty_lib": "^1.x.x",
"koatty_logger": "^1.x.x"
}
}
}
9 changes: 3 additions & 6 deletions src/grpc/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-09 17:03:50
* @LastEditTime: 2022-10-29 11:28:15
* @LastEditTime: 2022-11-16 16:04:40
*/
import { onSignal } from "../terminus";
import { CreateTerminus } from "../terminus";
import { DefaultLogger as Logger } from "koatty_logger";
import { Koatty, KoattyServer } from "koatty_core";
import {
Expand Down Expand Up @@ -57,6 +57,7 @@ export class GrpcServer implements KoattyServer {
options.ext = options.ext || {};
this.options.channelOptions = Object.assign(this.options.channelOptions || {}, options.ext);
this.server = new Server(this.options.channelOptions);
CreateTerminus(this);
}

/**
Expand All @@ -74,9 +75,6 @@ export class GrpcServer implements KoattyServer {
// Buffer.from(this.options.ext.cert),
// [],
// );
process.on("beforeExit", (code: number) => {
this.Stop();
});
this.server.bindAsync(`${this.options.hostname}:${this.options.port}`, creds, () => {
this.server.start();
listenCallback();
Expand All @@ -90,7 +88,6 @@ export class GrpcServer implements KoattyServer {
*
*/
Stop(callback?: () => void) {
onSignal();
this.server.tryShutdown((err?: Error) => {
callback?.();
Logger.Error(err);
Expand Down
8 changes: 3 additions & 5 deletions src/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @Usage:
* @Author: richen
* @Date: 2021-06-28 15:06:13
* @LastEditTime: 2022-10-29 11:28:49
* @LastEditTime: 2022-11-16 16:04:58
*/
import { createServer, Server } from "http";
import { Koatty, KoattyServer } from "koatty_core";
import { CreateTerminus, onSignal } from "../terminus";
import { CreateTerminus } from "../terminus";
import { DefaultLogger as Logger } from "koatty_logger";
import { ListeningOptions } from "../index";
/**
Expand All @@ -31,6 +31,7 @@ export class HttpServer implements KoattyServer {
this.server = createServer((req, res) => {
app.callback()(req, res);
});
CreateTerminus(this);
}

/**
Expand All @@ -41,8 +42,6 @@ export class HttpServer implements KoattyServer {
*/
Start(listenCallback?: () => void) {
listenCallback = listenCallback ? listenCallback : this.listenCallback;
// Terminus
CreateTerminus(this.server);
return this.server.listen({
port: this.options.port,
host: this.options.hostname,
Expand All @@ -57,7 +56,6 @@ export class HttpServer implements KoattyServer {
*
*/
Stop(callback?: () => void) {
onSignal();
this.server.close((err?: Error) => {
callback?.();
Logger.Error(err);
Expand Down
8 changes: 3 additions & 5 deletions src/http/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @Usage:
* @Author: richen
* @Date: 2021-06-28 15:06:13
* @LastEditTime: 2022-10-29 11:29:18
* @LastEditTime: 2022-11-16 16:05:09
*/
import { createSecureServer, Http2SecureServer, SecureServerOptions } from "http2";
import { CreateTerminus, onSignal } from "../terminus";
import { CreateTerminus } from "../terminus";
import { DefaultLogger as Logger } from "koatty_logger";
import { Koatty, KoattyServer } from "koatty_core";
import { ListeningOptions } from "../index";
Expand Down Expand Up @@ -36,6 +36,7 @@ export class Http2Server implements KoattyServer {
this.server = createSecureServer(opt, (req, res) => {
app.callback()(req, res);
});
CreateTerminus(this);
}

/**
Expand All @@ -46,8 +47,6 @@ export class Http2Server implements KoattyServer {
*/
Start(listenCallback?: () => void) {
listenCallback = listenCallback ? listenCallback : this.listenCallback;
// Terminus
CreateTerminus(this.server);
return this.server.listen({
port: this.options.port,
host: this.options.hostname,
Expand All @@ -62,7 +61,6 @@ export class Http2Server implements KoattyServer {
*
*/
Stop(callback?: () => void) {
onSignal();
this.server.close((err?: Error) => {
callback?.();
Logger.Error(err);
Expand Down
8 changes: 3 additions & 5 deletions src/http/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-12 11:48:01
* @LastEditTime: 2022-10-29 11:29:36
* @LastEditTime: 2022-11-16 16:05:17
*/
import { createServer, Server, ServerOptions } from "https";
import { Koatty, KoattyServer } from "koatty_core";
import { CreateTerminus, onSignal } from "../terminus";
import { CreateTerminus } from "../terminus";
import { DefaultLogger as Logger } from "koatty_logger";
import { ListeningOptions } from "../index";

Expand Down Expand Up @@ -42,6 +42,7 @@ export class HttpsServer implements KoattyServer {
this.server = createServer(opt, (req, res) => {
app.callback()(req, res);
});
CreateTerminus(this);
}

/**
Expand All @@ -53,8 +54,6 @@ export class HttpsServer implements KoattyServer {
*/
Start(listenCallback?: () => void) {
listenCallback = listenCallback ? listenCallback : this.listenCallback;
// Terminus
CreateTerminus(this.server);
return this.server.listen({
port: this.options.port,
host: this.options.hostname,
Expand All @@ -69,7 +68,6 @@ export class HttpsServer implements KoattyServer {
*
*/
Stop(callback?: () => void) {
onSignal();
this.server.close((err?: Error) => {
callback?.();
Logger.Error(err);
Expand Down
Loading

0 comments on commit d4af2f2

Please sign in to comment.