Error appear when using cron [Scheduler] QueryFailedError: read ECONNRESET
Error appear when using cron [Scheduler] QueryFailedError: read ECONNRESET
我有一个晚上要执行的操作
@Cron(CronExpression.EVERY_DAY_AT_1AM)
async setValideFileRemainder() {
var date = new Date();
let dateToday = date.toISOString().split('T')[0];
let remainders = await this.healthFileRepository.find({
where: { remainder_date: dateToday }})
for (let file of remainders) {
file.is_valide = 1;
await this.healthFileRepository.save(file);
}
}
例如,当我在端点或每 5 分钟测试此功能时,它可以工作,但在晚上它总是给我这个错误:
[Nest] 18728 - 09/15/2021, 7:53:52 AM [Scheduler] QueryFailedError: read ECONNRESET +38765424ms
PS:我正在使用 MySQL 作为数据库
我怀疑您 运行 进入 MySQL 连接超时,因为您的客户端应用程序处于空闲状态。如果在wait_timeout
配置的时间范围内没有activity,MySQL服务器将断开您的客户端。
您需要:
- 调整您的 MySQL 服务器配置并增加
wait_timeout
- 以短于
wait_timeout
的时间间隔向您的服务器(例如 SELECT 1
)发送保持活动查询
- 优雅地处理连接断开,因为它们可能由于您的应用程序或 SQL 服务器之外的更多原因而发生(例如路由断开、link 关闭、数据包丢失等)
我有一个晚上要执行的操作
@Cron(CronExpression.EVERY_DAY_AT_1AM)
async setValideFileRemainder() {
var date = new Date();
let dateToday = date.toISOString().split('T')[0];
let remainders = await this.healthFileRepository.find({
where: { remainder_date: dateToday }})
for (let file of remainders) {
file.is_valide = 1;
await this.healthFileRepository.save(file);
}
}
例如,当我在端点或每 5 分钟测试此功能时,它可以工作,但在晚上它总是给我这个错误:
[Nest] 18728 - 09/15/2021, 7:53:52 AM [Scheduler] QueryFailedError: read ECONNRESET +38765424ms
PS:我正在使用 MySQL 作为数据库
我怀疑您 运行 进入 MySQL 连接超时,因为您的客户端应用程序处于空闲状态。如果在wait_timeout
配置的时间范围内没有activity,MySQL服务器将断开您的客户端。
您需要:
- 调整您的 MySQL 服务器配置并增加
wait_timeout
- 以短于
wait_timeout
的时间间隔向您的服务器(例如 - 优雅地处理连接断开,因为它们可能由于您的应用程序或 SQL 服务器之外的更多原因而发生(例如路由断开、link 关闭、数据包丢失等)
SELECT 1
)发送保持活动查询