Ejemplo n.º 1
0
    def do_start(cls, request):
        task_id = request.POST.get("task_id")
        try:
            int(task_id)
        except ValueError:
            return HttpResponse(json_error('任务id格式有误'))
        try:
            task = Task.objects.get(id=task_id)
            if task.status == TASK.RUNNING:
                return HttpResponse(json_error('该任务正在运行,请先停止'))
        except Exception:
            return HttpResponse(json_error('该任务已不存在,请刷新重试'))
        else:
            cmd = {'action':'start','task_ids':task_id}
            res = send_request(cls.MODULE_NAME, cmd)
            if res['success']:
                task.status = TASK.RUNNING
                task.progress = ''
                task.spider_flag = TASK.WAIT
                task.start_time = datetime.now()
                task.end_time = None
                task.save()
                msg = json_success('start')
            else:
                msg = json_error('命令执行失败')

            return HttpResponse(msg)
Ejemplo n.º 2
0
    def do_start(cls, request):
        task_id = request.POST.get("task_id")
        try:
            int(task_id)
        except ValueError:
            return HttpResponse(json_error('任务id格式有误'))
        try:
            task = Task.objects.get(id=task_id)
            if task.status == TASK.RUNNING:
                return HttpResponse(json_error('该任务正在运行,请先停止'))
        except Exception:
            return HttpResponse(json_error('该任务已不存在,请刷新重试'))
        else:
            cmd = {'action': 'start', 'task_ids': task_id}
            res = send_request(cls.MODULE_NAME, cmd)
            if res['success']:
                task.status = TASK.RUNNING
                task.progress = ''
                task.spider_flag = TASK.WAIT
                task.start_time = datetime.now()
                task.end_time = None
                task.save()
                msg = json_success('start')
            else:
                msg = json_error('命令执行失败')

            return HttpResponse(msg)
Ejemplo n.º 3
0
 def do_delete(cls, request, delete_task=True):
     task_ids = request.POST.get("task_id").split(',')
     if Task.objects.filter(id__in=task_ids).filter(status=TASK.RUNNING).count()>0:
         msg = json_error('任务正在运行,请重新选择!')
     else:
         if delete_task:
             Task.objects.filter(id__in=task_ids).delete()
         Result.objects.filter(task_id__in=task_ids).delete()
         Url.objects.filter(task_id__in=task_ids).delete()
         msg = json_success('success')
     return HttpResponse(msg)
Ejemplo n.º 4
0
 def do_delete(cls, request, delete_task=True):
     task_ids = request.POST.get("task_id").split(',')
     if Task.objects.filter(id__in=task_ids).filter(
             status=TASK.RUNNING).count() > 0:
         msg = json_error('任务正在运行,请重新选择!')
     else:
         if delete_task:
             Task.objects.filter(id__in=task_ids).delete()
         Result.objects.filter(task_id__in=task_ids).delete()
         Url.objects.filter(task_id__in=task_ids).delete()
         msg = json_success('success')
     return HttpResponse(msg)
Ejemplo n.º 5
0
    def do_stop(cls, request):
        task_id = request.POST.get("task_id")
        try:
            int(task_id)
        except ValueError:
            return HttpResponse(json_error('任务id格式有误'))
        try:
            task = Task.objects.get(id=task_id)
            if task.status != TASK.RUNNING:
                return HttpResponse(json_error('该任务已经停止'))
        except Exception:
            return HttpResponse(json_error('该任务已不存在,请刷新重试'))
        else:
            cmd = {'action':'stop','task_ids':task_id}
            res = send_request(cls.MODULE_NAME, cmd)
            if res['success']:
                task.status = TASK.STOP
                task.save()
                msg = json_success('stop')
            else:
                msg = json_error('命令执行失败')

            return HttpResponse(msg)
Ejemplo n.º 6
0
    def do_stop(cls, request):
        task_id = request.POST.get("task_id")
        try:
            int(task_id)
        except ValueError:
            return HttpResponse(json_error('任务id格式有误'))
        try:
            task = Task.objects.get(id=task_id)
            if task.status != TASK.RUNNING:
                return HttpResponse(json_error('该任务已经停止'))
        except Exception:
            return HttpResponse(json_error('该任务已不存在,请刷新重试'))
        else:
            cmd = {'action': 'stop', 'task_ids': task_id}
            res = send_request(cls.MODULE_NAME, cmd)
            if res['success']:
                task.status = TASK.STOP
                task.save()
                msg = json_success('stop')
            else:
                msg = json_error('命令执行失败')

            return HttpResponse(msg)
Ejemplo n.º 7
0
 def do_error(cls,request):
     return HttpResponse(json_error('非法操作'))
Ejemplo n.º 8
0
 def do_error(cls, request):
     return HttpResponse(json_error('非法操作'))