2016-11-13 14:34:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2018-02-27 11:39:27 +00:00
|
|
|
import datetime
|
|
|
|
|
2017-11-14 01:44:16 +00:00
|
|
|
from celery import shared_task
|
2018-02-27 11:39:27 +00:00
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from common.celery import register_as_period_task, after_app_ready_start, \
|
|
|
|
after_app_shutdown_clean
|
2018-03-06 09:05:36 +00:00
|
|
|
from .models import Status, Session
|
2017-12-04 08:41:00 +00:00
|
|
|
|
2017-12-07 05:28:11 +00:00
|
|
|
|
2017-12-04 08:41:00 +00:00
|
|
|
CACHE_REFRESH_INTERVAL = 10
|
2017-12-04 12:15:47 +00:00
|
|
|
RUNNING = False
|
2016-11-13 14:34:38 +00:00
|
|
|
|
2017-11-14 01:44:16 +00:00
|
|
|
|
|
|
|
@shared_task
|
2018-02-27 11:39:27 +00:00
|
|
|
@register_as_period_task(interval=3600)
|
|
|
|
@after_app_ready_start
|
|
|
|
@after_app_shutdown_clean
|
|
|
|
def delete_terminal_status_period():
|
2018-03-06 09:05:36 +00:00
|
|
|
yesterday = timezone.now() - datetime.timedelta(days=3)
|
2018-02-27 11:39:27 +00:00
|
|
|
Status.objects.filter(date_created__lt=yesterday).delete()
|
2017-12-04 08:41:00 +00:00
|
|
|
|
|
|
|
|
2018-03-06 09:05:36 +00:00
|
|
|
@shared_task
|
|
|
|
@register_as_period_task(interval=3600)
|
|
|
|
@after_app_ready_start
|
|
|
|
@after_app_shutdown_clean
|
|
|
|
def clean_orphan_session():
|
|
|
|
active_sessions = Session.objects.filter(is_finished=False)
|
|
|
|
for session in active_sessions:
|
|
|
|
if not session.terminal.is_active:
|
|
|
|
session.is_finished = True
|
|
|
|
session.save()
|