Beispiel #1
0
def generate_job_retries(all_jobs, retried_jobs):
    """
    Expected output from a `retry_job` request
    """
    job_retries = generate_bad_jobs()
    for job_id in all_jobs:
        if job_id in retried_jobs:
            job_retries[job_id] = {
                "job_id": job_id,
                "job": _generate_job_output(job_id),
                "retry_id": retried_jobs[job_id],
                "retry": _generate_job_output(retried_jobs[job_id]),
            }
        elif "batch_job" in all_jobs[job_id] and all_jobs[job_id]["batch_job"]:
            job_retries[job_id] = {
                "job_id": job_id,
                "job": _generate_job_output(job_id),
                "error": generate_error(job_id, "batch_parent_retry"),
            }
        else:
            job_retries[job_id] = {
                "job_id": job_id,
                "job": _generate_job_output(job_id),
                "error": generate_error(job_id, "retry_status"),
            }
    return job_retries
Beispiel #2
0
    def retry_jobs(self, params):
        job_ids = params["job_ids"]
        results = list()
        for job_id in job_ids:
            output = {"job_id": job_id}
            if job_id in RETRIED_JOBS:
                output["retry_id"] = RETRIED_JOBS[job_id]
            elif job_id == BATCH_PARENT:
                output["error"] = generate_error(job_id, "batch_parent_retry")
            else:
                output["error"] = generate_error(job_id, "retry_status")

            results.append(output)
        return results
Beispiel #3
0
def generate_job_logs(all_jobs):
    """
    Expected output from a `job_logs` request. Note that only completed jobs have logs in this case.
    """
    job_logs = generate_bad_jobs()
    for job_id in all_jobs:
        test_job = get_test_job(job_id)
        batch_job = test_job.get("batch_job", JOB_ATTR_DEFAULTS["batch_job"])
        batch_id = job_id if batch_job else get_test_job(job_id).get(
            "batch_id", None)
        if all_jobs[job_id]["status"] == COMPLETED_STATUS:
            job_logs[job_id] = {
                "job_id": job_id,
                "batch_id": batch_id,
                "first": 0,
                "latest": False,
                "max_lines": 50,
                "lines": log_gen(5),
            }
        else:
            job_logs[job_id] = {
                "batch_id": batch_id,
                "error": generate_error(job_id, "no_logs"),
                "job_id": job_id,
            }
    return job_logs
Beispiel #4
0
def generate_bad_jobs():
    bad_jobs = {
        job_id: {
            "job_id": job_id,
            "error": generate_error(job_id, "not_found")
        }
        for job_id in BAD_JOBS
    }
    return bad_jobs
Beispiel #5
0
 def mock_check_job(params):
     """Called from job.state()"""
     job_id = params["job_id"]
     if job_id == BATCH_PARENT:
         return {"child_jobs": new_child_ids}
     elif job_id in TEST_JOBS:
         return get_test_job(job_id)
     elif job_id == JOB_NOT_FOUND:
         return {
             "job_id": job_id,
             "status": generate_error(job_id, "not_found")
         }
     else:
         raise Exception()