@kne/fastify-message 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -17,7 +17,9 @@ module.exports = fp(async function(fastify, options) {
17
17
  }
18
18
  }, options);
19
19
 
20
- fastify.register(require('@fastify/sse'));
20
+ if (!fastify.sse) {
21
+ fastify.register(require('@fastify/sse'));
22
+ }
21
23
 
22
24
  fastify.register(require('@kne/fastify-namespace'), {
23
25
  name: options.name,
@@ -258,12 +258,18 @@ module.exports = fp(async (fastify, options) => {
258
258
  },
259
259
  async function (request, reply) {
260
260
  const intervalSeconds = request.query.interval ?? 5;
261
- const { timezone } = request.query;
261
+ const { timezone, type, runnerType } = request.query;
262
+ const startTime = Date.now();
263
+ const maxDurationMs = 30 * 60 * 1000;
262
264
 
263
265
  async function* eventStream() {
264
266
  while (reply.sse.isConnected) {
267
+ if (Date.now() - startTime >= maxDurationMs) {
268
+ yield { event: 'timeout', data: JSON.stringify({ message: '连接已超过30分钟,自动断开' }) };
269
+ return;
270
+ }
265
271
  try {
266
- yield { data: JSON.stringify(await services.statistics.getRealtime({ timezone })) };
272
+ yield { data: JSON.stringify(await services.statistics.getRealtime({ timezone, type, runnerType })) };
267
273
  } catch (err) {
268
274
  yield { event: 'error', data: JSON.stringify({ message: err.message }) };
269
275
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-message",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "管理消息发送,支持sms消息,email消息等.",
5
5
  "main": "index.js",
6
6
  "scripts": {