You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
1.1 KiB

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from datetime import datetime, timedelta
import traceback
from django.core.mail import mail_admins
from celery import shared_task
from .models import License, UserProfile
from .utils import check_one_profile
from project.customer import consts
@shared_task
def check_license():
profiles = UserProfile.objects.all()
now = datetime.today()
#licenses = License.objects.filter(date_to__lt=now, status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE], deleted=False)
#licenses.update(status=consts.LICENSE_EXPIRED)
licenses = License.objects.filter(order_date__lte=now - timedelta(consts.LICENSE_PAY_DAYS), status=consts.LICENSE_UNPAID, deleted=False)
licenses.update(status=consts.LICENSE_SUSPENDED)
for profile in profiles:
try:
check_one_profile(profile, License, now)
except Exception as e:
mail_admins(subject=u'customer: check_license error',
message=u'Profile id=%s.\n\n%s' % (profile.pk, traceback.format_exc(e))
)
return None