peewee解决问题"OperationalError: (2006, 'MySQL server has gone away')"

用过MySQL的应该都知道,MySQL默认长链接只能保持8小时,超过后就会自动断开。

在peewee中如何维持长连接呢?

解决方法比较晦涩,需要自定义一个支持重试的mixin,然后自定义一种RetryMySQLDatabase混入mixin
from peewee import *
from peewee import __exception_wrapper__

class RetryOperationalError(object):

def execute[......]

继续阅读

SpringBoot中定时任务执行的坑

在sb中,支持多种定时执行模式(cron, fixRate, fixDelay),开启也非常简单:

1、在Application或者其他Autoconfig上
@EnableScheduling
2、在需要定时执行的函数上
@Scheduled(fixedDelayString = "${config.timeInMs}")
@Scheduled(cron = "${config.cronStr}")
不过这里有个小坑,默认这个schedule只使用一个线程。

如果你在多个[......]

继续阅读