def get_request(request): form, error = JsonParser( Argument('duration', type=list, help='参数错误') ).parse(request.body) if error is None: s_date = form.duration[0] e_date = (parse_time(form.duration[1]) + timedelta(days=1)).strftime('%Y-%m-%d') data = {x.id: {'name': x.name, 'count': 0} for x in App.objects.all()} for req in DeployRequest.objects.filter(created_at__gt=s_date, created_at__lt=e_date): data[req.deploy.app_id]['count'] += 1 data = sorted(data.values(), key=lambda x: x['count'], reverse=True)[:10] return json_response(data) return json_response(error=error)
def auto_run_by_minute(): try: now = datetime.now() for req in DeployRequest.objects.filter(status='2'): if (now - parse_time(req.do_at)).seconds > 3600: req.status = '-3' req.save() for req in DeployRequest.objects.filter(status='1', plan__lte=now): req.status = '2' req.do_at = human_datetime() req.do_by = req.created_by req.save() Thread(target=dispatch, args=(req,)).start() finally: connections.close_all()
def auto_update_status(): now = datetime.now() for req in DeployRequest.objects.filter(status='2'): if (now - parse_time(req.do_at)).seconds > 3600: req.status = '-3' req.save()