Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions hinghwa-dict-backend/website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import os
import random
import time

import demjson3
import jwt
Expand Down Expand Up @@ -483,6 +484,17 @@ def openUrl(request, type, id, Y, M, D, X):

import shutil


class HinghwaBackgroundScheduler(BackgroundScheduler):
def _process_jobs(self):
while True:
try:
return super()._process_jobs()
except Exception as e:
print(f"Error processing jobs: {e}")
time.sleep(5)


try:

def random_word_of_the_day():
Expand All @@ -497,12 +509,11 @@ def clear_audio_buffer():
print("remove the audio buffer in public files")

def register(fun, id, replace_existing):
scheduler = BackgroundScheduler()
scheduler = HinghwaBackgroundScheduler(timezone=settings.TIME_ZONE)
scheduler.add_jobstore(DjangoJobStore(), "default")
register_job(
scheduler, "cron", id=id, hour=0, replace_existing=replace_existing
)(fun)
register_events(scheduler)
scheduler.start()

try:
Expand Down
Loading