add job 执行异常的 邮件报警逻辑
All checks were successful
Gitea Actions Demo / host-commands (push) Successful in 0s
All checks were successful
Gitea Actions Demo / host-commands (push) Successful in 0s
This commit is contained in:
13
peter.py
13
peter.py
@ -2,15 +2,24 @@
|
||||
from functools import partial
|
||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
from apscheduler.events import EVENT_JOB_ERROR
|
||||
from config import config
|
||||
from config import config, settings
|
||||
from task import manager_task
|
||||
from utils import logger
|
||||
from utils import logger, MailSender
|
||||
|
||||
|
||||
def job_error_listener(event):
|
||||
if event.exception:
|
||||
logger.error(f"Job {event.job_id} crashed: {str(event.exception)}")
|
||||
# 可添加邮件/钉钉告警逻辑
|
||||
try:
|
||||
mail_sender = MailSender()
|
||||
mail_sender.execute(
|
||||
to_addrs=settings.ERROR_NOTIFICATION_EMAIL,
|
||||
subject=f"Job {event.job_id} crashed",
|
||||
body=f"Job {event.job_id} crashed with error: {str(event.exception)}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send error notification email: {e}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user