33 lines
747 B
Python
33 lines
747 B
Python
|
|
from queue_sqlite.scheduler import QueueScheduler
|
||
|
|
from queue_sqlite.mounter import listener
|
||
|
|
import time
|
||
|
|
|
||
|
|
|
||
|
|
# 注册监听器
|
||
|
|
@listener()
|
||
|
|
def user_activity_log(data):
|
||
|
|
"""监听用户活动数据"""
|
||
|
|
print(f"用户活动: {data}")
|
||
|
|
|
||
|
|
|
||
|
|
@listener()
|
||
|
|
def system_alert(data):
|
||
|
|
"""监听系统告警"""
|
||
|
|
print(f"系统告警: {data}")
|
||
|
|
|
||
|
|
|
||
|
|
# 创建调度器
|
||
|
|
scheduler = QueueScheduler(scheduler_type="qt")
|
||
|
|
scheduler.start()
|
||
|
|
|
||
|
|
# 更新监听数据(会自动触发监听函数)
|
||
|
|
scheduler.update_listen_data("user_activity_log", "用户登录")
|
||
|
|
scheduler.update_listen_data("user_activity_log", "用户购买")
|
||
|
|
scheduler.update_listen_data("system_alert", "CPU使用率过高")
|
||
|
|
|
||
|
|
time.sleep(5)
|
||
|
|
|
||
|
|
scheduler.stop()
|
||
|
|
|
||
|
|
print(scheduler.get_listen_datas())
|