使用超级代理缓存插件时,节点进程未终止

时间:2019-04-16 15:57:19

标签: typescript caching superagent

我当前在Typescript项目中使用此插件,该项目在AWS Lambda或本地Lambda docker容器(SAM工具)中运行。当我激活缓存插件时,lambda函数不再终止。

我还通过Mocha测试框架尝试了superagent调用。在这种情况下,尽管所有测试输出都已写入控制台,但该过程也不会终止。

此外,似乎有些工作正常。这些项目将写入redis实例,但lambda函数不会终止。

这些是已安装的版本

├── typescript@3.3.4000
├── superagent@4.1.0
├── superagent-cache-plugin@2.0.1
├── cache-service-redis@2.0.0

我需要为它们声明模块,因为没有可用的类型。我没有打字专家。因此,也许错误位于此处。

# cache-service-redis.ts
declare module 'cache-service-redis';
# superagent-cache-plugin.ts
declare module 'superagent-cache-plugin';

这是设置

import RedisCache = require('cache-service-redis');
import superagentCache = require('superagent-cache-plugin');
...
const redisConfig = {
    defaultExpiration: 300,
    redisData: {
        hostname: process.env.CacheEndpoint,
        port: 6379,
    },
    type: 'app',
};
const redisCache = new RedisCache(redisConfig);
const cache = superagentCache(redisCache);
const request = superagent.get('...').use(cache)
const response = await request

先谢谢了。我真的很想解决这个问题并使用该软件包。如有需要,我会很乐意提供更多信息。)

1 个答案:

答案 0 :(得分:0)

在阅读this gist之后,我通过在维护者的帮助下设置context.callbackWaitsForEmptyEventLoop = false;解决了这个问题,这显示了问题的最小示例。

关于此的任何正在进行的讨论都可以找到within the issue at github