javascript - Sequelize 查询随机挂起
问题描述
我正在调用一个使用 Sequelize 更新 Postgres 模型中的一些数据的方法。调用来自异步生成器函数,如下所示:
文件夹结构:
- 文件夹1
- initialCallFile(生成器函数)
- anotherFileThatCalls(非生成器函数)
- 文件夹2
- 更新机器人方法文件
初次通话:
async function* function() {
await storage.updateBot({id: player.id, handsPlayed: 1, isActive: true});
}
updateBot 方法:
function updateBot(data) {
return new Promise(async resolve => {
try {
const bot = await Bot.findOne({
where: {
id: data.id,
},
});
if (bot) {
if (data.handsPlayed)
bot.handsPlayed += data.handsPlayed;
if (data.handsWon)
bot.handsWon += data.handsWon;
if (data.totalWinnings)
bot.totalWinnings = data.totalWinnings;
if (data.isActive !== null && data.isActive !== undefined)
bot.isActive = data.isActive;
} else {
logger.log('debug', 'No Bot found with id: %s', data.id);
resolve(true);
}
await bot.save();
resolve(true);
} catch (err) {
logger.log('error', 'Error updating Bot with id: %s', data.id);
resolve(true);
}
});
}
updateBot 方法在初始 Bot.fineOne 查询中挂起。没有抛出错误,即使在 5-10 分钟后,也没有超时。
我也在从其他地方调用 updateBot,它们不在生成器函数内,它们按预期工作而不会挂起。但是,我不认为这是导致问题的生成器函数,因为它是一个完全独立的函数,当我用简单的超时替换查询时,它不会挂起。
我也尝试过直接在我的生成器函数中调用更新以及使用 yield 而不是 await ,但仍然存在挂起。由于没有错误或超时,我不确定如何最好地调试问题。该代码在其他地方调用时按预期工作,所以我很困惑。
任何建议将不胜感激。
解决方案
推荐阅读
- tomcat - Windows Server 2012 上的 Tomcat IIS 集成
- android - Doze 命令中的 ADB Android 白名单是否与在 GUI 中禁用电池优化相同?
- pdf - 更改 SSRS 报告中奇数页和偶数页的页边距
- sql - 为什么我的 sql 查询出现 0/0 错误?
- javascript - 如何在 JS 循环中增加 PHP 变量
- apache-spark - Spark:Spark广播需要rpc吗?
- dart - 如何在 VSCode 中配置 IntelliSense,以便在创建类或构造函数时为 Dart 类名提供建议?
- postgresql - 如何将 JSONB 对象中的现有时间戳更改为 Postgresql 中的另一种时间戳格式
- java - 使用自定义方法和 JpaRepository 实现接口
- java - 由于您尚未通过服务器“ge.spring.io”进行身份验证,因此未发布构建扫描