2023-08-01 08:40:38 +00:00
|
|
|
from django.db.models.signals import pre_save, post_save
|
2023-08-01 08:14:40 +00:00
|
|
|
from django.dispatch import receiver
|
|
|
|
|
|
|
|
from terminal.models import Session
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_save, sender=Session)
|
|
|
|
def on_session_pre_save(sender, instance, **kwargs):
|
|
|
|
if instance.need_update_cmd_amount:
|
|
|
|
instance.cmd_amount = instance.compute_command_amount()
|
2023-08-01 08:40:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Session)
|
|
|
|
def on_session_finished(sender, instance: Session, created, **kwargs):
|
|
|
|
if not instance.is_finished:
|
|
|
|
return
|
|
|
|
# 清理一次可能因 task 未执行的缓存数据
|
|
|
|
Session.unlock_session(instance.id)
|
2023-09-13 08:52:11 +00:00
|
|
|
|