开启/关闭作业监控
This commit is contained in:
parent
fd1d2ccfc7
commit
e94d2dcaca
|
|
@ -90,29 +90,37 @@ def opl_start(ticket: Ticket):
|
||||||
check_not_in_place(opl)
|
check_not_in_place(opl)
|
||||||
|
|
||||||
# 给摄像头加载循环拍照算法
|
# 给摄像头加载循环拍照算法
|
||||||
|
start_mtask(opl)
|
||||||
|
|
||||||
|
|
||||||
|
def start_mtask(opl: Opl):
|
||||||
|
op = opl.operation
|
||||||
# 找到作业点的摄像头, 如果指定摄像头就用指定的摄像头
|
# 找到作业点的摄像头, 如果指定摄像头就用指定的摄像头
|
||||||
if op.vchannels:
|
if op.vchannels:
|
||||||
vc_codes = list(op.vchannels.all().values_list('code', flat=True))
|
vc_codes = list(op.vchannels.all().values_list('code', flat=True))
|
||||||
else:
|
|
||||||
vc_codes = list(TDevice.objects.filter(type=TDevice.DEVICE_VCHANNEL,
|
|
||||||
area=op.area).values_list('code', flat=True))
|
|
||||||
opl_id = opl.id
|
opl_id = opl.id
|
||||||
task = opl_task.delay(vc_codes, opl_id)
|
task = opl_task.delay(vc_codes, opl_id)
|
||||||
opl.mtask = TaskResult.objects.get(task_id=task.task_id)
|
opl.mtask = TaskResult.objects.get(task_id=task.task_id)
|
||||||
opl.save()
|
opl.save()
|
||||||
|
|
||||||
|
|
||||||
|
def close_mtask(task_id: str):
|
||||||
|
"""关闭celery任务
|
||||||
|
"""
|
||||||
|
from celery.app.control import Control
|
||||||
|
from server.celery import app
|
||||||
|
celery_control = Control(app=app)
|
||||||
|
celery_control.revoke(task_id, terminate=True)
|
||||||
|
|
||||||
|
|
||||||
def opl_end(ticket: Ticket):
|
def opl_end(ticket: Ticket):
|
||||||
"""
|
"""
|
||||||
作业许可证关闭时执行
|
作业许可证关闭时执行
|
||||||
"""
|
"""
|
||||||
opl = ticket.opl
|
opl = ticket.opl
|
||||||
if opl.mtask:
|
if opl.mtask:
|
||||||
from celery.app.control import Control
|
|
||||||
from server.celery import app
|
|
||||||
celery_control = Control(app=app)
|
|
||||||
# 关闭作业视频监控任务
|
# 关闭作业视频监控任务
|
||||||
celery_control.revoke(opl.mtask.id, terminate=True)
|
close_mtask(opl.mtask.task_id)
|
||||||
operation = opl.operation
|
operation = opl.operation
|
||||||
opls = Opl.objects.filter(operation=operation)
|
opls = Opl.objects.filter(operation=operation)
|
||||||
opls.filter(ticket=None).delete() # 删除无用许可证
|
opls.filter(ticket=None).delete() # 删除无用许可证
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@ from apps.opm.serializers import (GasCheckCreateUpdateSerializer, GasCheckSerial
|
||||||
OplCateCreateUpdateSerializer, OplCateDetailSerializer, OplCateSerializer,
|
OplCateCreateUpdateSerializer, OplCateDetailSerializer, OplCateSerializer,
|
||||||
OplCreateUpdateSerializer, OplDetailSerializer, OplListSerializer,
|
OplCreateUpdateSerializer, OplDetailSerializer, OplListSerializer,
|
||||||
OplWorkerCreateSerializer, OplWorkerSerializer, OplWorkerUpdateSerializer)
|
OplWorkerCreateSerializer, OplWorkerSerializer, OplWorkerUpdateSerializer)
|
||||||
|
from apps.opm.services import close_mtask, start_mtask
|
||||||
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
from rest_framework.mixins import CreateModelMixin, ListModelMixin, DestroyModelMixin
|
from rest_framework.mixins import CreateModelMixin, ListModelMixin, DestroyModelMixin
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.serializers import Serializer
|
||||||
from apps.wf.models import Ticket
|
from apps.wf.models import Ticket
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
@ -97,6 +99,29 @@ class OplWorkerViewSet(CustomModelViewSet):
|
||||||
raise ParseError('许可证已处理不可编辑')
|
raise ParseError('许可证已处理不可编辑')
|
||||||
return super().update(request, *args, **kwargs)
|
return super().update(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=True, perms_map={'post': '*'},
|
||||||
|
serializer_class=Serializer, logging_methods=[])
|
||||||
|
def start_mtask(self, request, pk=None):
|
||||||
|
"""
|
||||||
|
开启作业监控
|
||||||
|
"""
|
||||||
|
obj = self.get_object()
|
||||||
|
if obj.mtask:
|
||||||
|
# 先关闭
|
||||||
|
close_mtask(obj.mtask.task_id)
|
||||||
|
start_mtask(obj)
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=True, perms_map={'post': '*'},
|
||||||
|
serializer_class=Serializer, logging_methods=[])
|
||||||
|
def close_mtask(self, request, pk=None):
|
||||||
|
"""
|
||||||
|
停止作业监控
|
||||||
|
"""
|
||||||
|
obj = self.get_object()
|
||||||
|
if obj.mtask:
|
||||||
|
close_mtask(obj.mtask.task_id)
|
||||||
|
return Response()
|
||||||
|
|
||||||
class GasCheckViewSet(CreateModelMixin, ListModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
class GasCheckViewSet(CreateModelMixin, ListModelMixin, DestroyModelMixin, CustomGenericViewSet):
|
||||||
perms_map = {'get': '*', 'post': 'opl.update', 'delete': 'opl.update'}
|
perms_map = {'get': '*', 'post': 'opl.update', 'delete': 'opl.update'}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue