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.
89 lines
3.7 KiB
89 lines
3.7 KiB
5 years ago
|
#!/usr/bin/env python
|
||
|
# -*- coding:utf-8 -*-
|
||
|
# project: 4月
|
||
|
# author: liuyu
|
||
|
# date: 2020/4/7
|
||
|
|
||
4 years ago
|
from api.models import Apps, UserInfo, AppIOSDeveloperInfo
|
||
5 years ago
|
from api.utils.storage.storage import Storage
|
||
4 years ago
|
from api.utils.app.supersignutils import IosUtils
|
||
|
from api.utils.utils import send_ios_developer_active_status
|
||
5 years ago
|
from django.core.cache import cache
|
||
4 years ago
|
from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE, SUPER_SIGN_ROOT
|
||
|
import time, os
|
||
5 years ago
|
from django_apscheduler.models import DjangoJobExecution
|
||
5 years ago
|
import logging
|
||
5 years ago
|
|
||
5 years ago
|
logger = logging.getLogger(__file__)
|
||
5 years ago
|
|
||
5 years ago
|
|
||
5 years ago
|
def sync_download_times():
|
||
|
down_tem_key = CACHE_KEY_TEMPLATE.get("download_times_key")
|
||
5 years ago
|
key = "_".join([down_tem_key, '*'])
|
||
5 years ago
|
for app_download in cache.iter_keys(key):
|
||
5 years ago
|
count_hits = cache.get(app_download)
|
||
5 years ago
|
app_id = app_download.split(down_tem_key)[1].strip('_')
|
||
5 years ago
|
Apps.objects.filter(app_id=app_id).update(count_hits=count_hits)
|
||
5 years ago
|
logger.info("sync_download_times app_id:%s count_hits:%s" % (app_id, count_hits))
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
def auto_clean_upload_tmp_file():
|
||
|
upload_tem_key = CACHE_KEY_TEMPLATE.get("upload_file_tmp_name_key")
|
||
|
key = "_".join([upload_tem_key, '*'])
|
||
|
for upload_tem_file_key in cache.iter_keys(key):
|
||
|
data = cache.get(upload_tem_file_key)
|
||
|
if data:
|
||
|
stime = data.get("stime", None)
|
||
5 years ago
|
if stime and time.time() - stime > 60 * 20:
|
||
5 years ago
|
user_obj = UserInfo.objects.filter(pk=data.get("id")).first()
|
||
|
if user_obj:
|
||
|
storage = Storage(user_obj)
|
||
|
filename = data.get("filename", None)
|
||
|
if filename:
|
||
|
storage.delete_file(filename)
|
||
5 years ago
|
logger.info("auto_clean_upload_tmp_file delete_file :%s " % (filename))
|
||
|
|
||
5 years ago
|
cache.delete(upload_tem_file_key)
|
||
5 years ago
|
logger.info("auto_clean_upload_tmp_file upload_tem_file_key :%s " % (upload_tem_file_key))
|
||
5 years ago
|
|
||
|
|
||
|
def auto_delete_job_log():
|
||
|
job_execution = DjangoJobExecution.objects.order_by("-id").values("id").first()
|
||
|
if job_execution:
|
||
|
need_count = SYNC_CACHE_TO_DATABASE.get("auto_clean_apscheduler_log", 10000)
|
||
|
max_id = job_execution.get("id")
|
||
|
count = DjangoJobExecution.objects.count()
|
||
|
if count > need_count:
|
||
|
DjangoJobExecution.objects.filter(id__lte=max_id - need_count).delete()
|
||
4 years ago
|
|
||
|
|
||
|
def auto_delete_tmp_file():
|
||
|
mobileconfig_tmp_dir = os.path.join(SUPER_SIGN_ROOT, 'tmp', 'mobileconfig')
|
||
|
for root, dirs, files in os.walk(mobileconfig_tmp_dir, topdown=False):
|
||
|
now_time = time.time()
|
||
|
for name in files:
|
||
|
file_path = os.path.join(root, name)
|
||
|
st_mtime = os.stat(file_path).st_mtime
|
||
|
if now_time - st_mtime > SYNC_CACHE_TO_DATABASE.get('clean_local_tmp_file_from_mtime', 30 * 60):
|
||
|
try:
|
||
|
os.remove(file_path)
|
||
|
except Exception as e:
|
||
|
logger.error("auto_delete_tmp_file %s Failed . Exception %s" % (file_path, e))
|
||
4 years ago
|
|
||
|
|
||
|
def auto_check_ios_developer_active():
|
||
|
all_ios_developer = AppIOSDeveloperInfo.objects.filter(is_actived=True)
|
||
|
for ios_developer in all_ios_developer:
|
||
|
userinfo = ios_developer.user_id
|
||
|
if userinfo.supersign_active:
|
||
|
status, result = IosUtils.active_developer(ios_developer, userinfo)
|
||
|
msg = "auto_check_ios_developer_active user:%s ios.developer:%s status:%s result:%s" % (
|
||
|
ios_developer.user_id, ios_developer, status, result)
|
||
|
if status:
|
||
|
logger.info(msg)
|
||
|
else:
|
||
|
ios_developer.is_actived = False
|
||
|
ios_developer.save()
|
||
|
logger.error(msg)
|
||
|
send_ios_developer_active_status(ios_developer, msg)
|