2023-03-10 06:07:12 +02:00
|
|
|
import atexit
|
2023-07-09 12:29:11 +02:00
|
|
|
|
2023-03-10 06:07:12 +02:00
|
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
2023-07-09 12:29:11 +02:00
|
|
|
|
2023-03-10 06:07:12 +02:00
|
|
|
scheduler = None
|
|
|
|
|
|
|
|
def setup(args):
|
|
|
|
from libretranslate.flood import forgive_banned
|
|
|
|
from libretranslate.secret import rotate_secrets
|
|
|
|
|
|
|
|
global scheduler
|
|
|
|
|
|
|
|
if scheduler is None:
|
|
|
|
scheduler = BackgroundScheduler()
|
|
|
|
|
2024-07-19 20:14:25 +02:00
|
|
|
if not args.secondary and args.req_flood_threshold > 0:
|
2023-03-10 06:07:12 +02:00
|
|
|
scheduler.add_job(func=forgive_banned, trigger="interval", minutes=10)
|
|
|
|
|
2024-07-19 20:14:25 +02:00
|
|
|
if not args.secondary and args.api_keys and args.require_api_key_secret:
|
2023-03-10 06:07:12 +02:00
|
|
|
scheduler.add_job(func=rotate_secrets, trigger="interval", minutes=30)
|
2023-07-23 13:24:15 +02:00
|
|
|
|
2023-03-10 06:07:12 +02:00
|
|
|
scheduler.start()
|
|
|
|
|
|
|
|
# Shut down the scheduler when exiting the app
|
|
|
|
atexit.register(lambda: scheduler.shutdown())
|