Пример #1
0
def update_jobs_status(request):
    try:
        job = request.GET['job__id']
        jobs = DeployJobs.objects.filter(job__id=job).filter(
            deploy_status='deploy')
        count = len(jobs)
        for job in jobs:
            j_id = job.j_id
            j = DeployJobs.objects.get(j_id=j_id)
            job_status = sapi.check_job(j_id)
            print(list(set(job_status.values()))[0])
            try:
                if list(set(job_status.values()))[0]:
                    import re
                    results = sapi.get_cmd_result(j_id)
                    DeployResults.objects.create(deployjob=j,
                                                 result=json.dumps(results))
                    for result in results.values():
                        error_result = bool(re.search(r'Error', result, re.I))
                        if error_result > 0:
                            j.deploy_status = 'failed'
                        else:
                            j.deploy_status = 'success'
                else:
                    j.deploy_status = 'deploy'
            except Exception as e:
                print(e)
                pass
            j.save()
        return Response({"results": 'success', "count": count})
    except Exception as e:
        return Response({"results": '?job__name=wtf', "count": 1024})
Пример #2
0
def update_states_status(request):
    try:
        jobs = StateJob.objects.filter(status='deploy')
        count = len(jobs)
        for job in jobs:
            j_id = job.j_id
            j = StateJob.objects.get(j_id=j_id)
            job_status = sapi.check_job(j_id)
            print(list(set(job_status.values()))[0])
            try:
                if list(set(job_status.values()))[0]:
                    results = sapi.get_state_result(j_id)
                    j.result = json.dumps(results)
                    result_status = []
                    for oo in results.values():
                        for xx in oo.values():
                            result_status.append(xx['result'])
                    if False in result_status:
                        j.status = 'failed'
                    else:
                        j.status = 'success'
                    j.done = True
                else:
                    j.status = 'deploy'
            except Exception as e:
                print(e)
                pass
            j.save()
        return Response({"results": 'success', "count": count})
    except Exception as e:
        return Response({"results": 'tnnd', "count": 1024})