mirror of https://github.com/jumpserver/jumpserver
perf: 添加 celery 健康检测
parent
a377317d6e
commit
2e91aa8ce5
|
@ -2,12 +2,14 @@
|
|||
|
||||
import os
|
||||
|
||||
from kombu import Exchange, Queue
|
||||
from celery import Celery
|
||||
from kombu import Exchange, Queue
|
||||
|
||||
# set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings')
|
||||
from jumpserver import settings
|
||||
from .heatbeat import *
|
||||
|
||||
# from django.conf import settings
|
||||
|
||||
app = Celery('jumpserver')
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
from pathlib import Path
|
||||
|
||||
from celery.signals import heartbeat_sent, worker_ready, worker_shutdown
|
||||
|
||||
|
||||
@heartbeat_sent.connect
|
||||
def heartbeat(sender, **kwargs):
|
||||
worker_name = sender.eventer.hostname.split('@')[0]
|
||||
heartbeat_path = Path('/tmp/worker_heartbeat_{}'.format(worker_name))
|
||||
heartbeat_path.touch()
|
||||
|
||||
|
||||
@worker_ready.connect
|
||||
def worker_ready(sender, **kwargs):
|
||||
worker_name = sender.hostname.split('@')[0]
|
||||
ready_path = Path('/tmp/worker_ready_{}'.format(worker_name))
|
||||
ready_path.touch()
|
||||
|
||||
|
||||
@worker_shutdown.connect
|
||||
def worker_shutdown(sender, **kwargs):
|
||||
worker_name = sender.hostname.split('@')[0]
|
||||
for signal in ['ready', 'heartbeat']:
|
||||
path = Path('/tmp/worker_{}_{}'.format(signal, worker_name))
|
||||
path.unlink(missing_ok=True)
|
Loading…
Reference in New Issue