mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 11:29:38 +08:00
dump at server start
This commit is contained in:
@@ -37,7 +37,7 @@ from database import (AnnouncementResource, BlacklistResource, CaptchaResource,
|
||||
NameResource, NotificationResource, OtherResource, Redis,
|
||||
ResourceLatestResource, ResourceResource, TopResource,
|
||||
UserEmailResource, UserResource)
|
||||
from utils import check_spam, send_mail, ts_date, Cloudflare
|
||||
from utils import Cloudflare, check_spam, send_mail, ts_date
|
||||
|
||||
lib_path = pathlib.Path(__file__).parent.parent.joinpath("yyetsbot").resolve().as_posix()
|
||||
sys.path.append(lib_path)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
__author__ = "Benny <benny.think@gmail.com>"
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -230,5 +231,10 @@ def entry_dump():
|
||||
logging.info("Total time used: %.2fs" % (time.time() - t0))
|
||||
|
||||
|
||||
def no_error_entry_dump():
|
||||
with contextlib.suppress(Exception):
|
||||
entry_dump()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
entry_dump()
|
||||
|
||||
@@ -11,6 +11,7 @@ import logging
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import threading
|
||||
|
||||
import pytz
|
||||
import tornado.autoreload
|
||||
@@ -19,7 +20,7 @@ from apscheduler.triggers.cron import CronTrigger
|
||||
from tornado import httpserver, ioloop, options, web
|
||||
from tornado.log import enable_pretty_logging
|
||||
|
||||
from dump_db import entry_dump
|
||||
import dump_db
|
||||
from handler import (AnnouncementHandler, BlacklistHandler, CaptchaHandler,
|
||||
CategoryHandler, CommentChildHandler, CommentHandler,
|
||||
CommentNewestHandler, CommentReactionHandler,
|
||||
@@ -104,11 +105,13 @@ if __name__ == "__main__":
|
||||
scheduler = BackgroundScheduler(timezone=timez)
|
||||
scheduler.add_job(OtherMongoResource().reset_top, trigger=CronTrigger.from_crontab("0 0 1 * *"))
|
||||
scheduler.add_job(sync_douban, trigger=CronTrigger.from_crontab("1 1 1 * *"))
|
||||
scheduler.add_job(entry_dump, trigger=CronTrigger.from_crontab("2 2 1 * *"))
|
||||
scheduler.add_job(dump_db.entry_dump, trigger=CronTrigger.from_crontab("2 2 1 * *"))
|
||||
scheduler.add_job(ResourceLatestMongoResource().refresh_latest_resource, 'interval', hours=1)
|
||||
scheduler.add_job(OtherMongoResource().import_ban_user, 'interval', seconds=300)
|
||||
scheduler.add_job(cf.clear_fw, trigger=CronTrigger.from_crontab("0 0 */5 * *"))
|
||||
scheduler.start()
|
||||
logging.info("Triggering dump database now...")
|
||||
threading.Thread(target=dump_db.no_error_entry_dump).start()
|
||||
|
||||
options.define("p", default=8888, help="running port", type=int)
|
||||
options.define("h", default='127.0.0.1', help="listen address", type=str)
|
||||
|
||||
Reference in New Issue
Block a user