Ejemplo n.º 1
0
def get_job_info(redis_conn,
                 job_id: str,
                 with_relics=True) -> Dict[str, Union[bool, str]]:
    """
    Pull meta info for a given job from Redis.
    Scenario 1: job status is True, job relics present (ok)
    Scenario 2: job status is None, job relics present (wrong status, fix)
    Scenario 3: job status is True, no job relics (expired)
    Scenario 4: job status is None, no job relics (wrong everything)
    """

    job_status = redis_conn.hget("jobs:status", job_id)
    job_status = json.loads(job_status) if job_status else None
    relics = redis_conn.get(f"relics:{job_id}")
    sample = json.loads(relics)["sample"] if relics else ""
    relics = json.loads(relics)["relics"] if relics else []

    if not job_status and relics:
        job_status = utils.mark_job_success(job_id, True)
    job_object = create_job_info_object(job_status,
                                        relics,
                                        sample,
                                        job_id,
                                        with_relics=with_relics)

    return job_object
Ejemplo n.º 2
0
def analyze(user_id: str = None, filename: str = None) -> None:
    """
    Start NLP tasks.
    """

    job = get_current_job()
    job_id = job._id
    file_path = f"{UPLOAD_FOLDER}/{filename}"
    check_arguments(user_id, filename, file_path)
    relics, sample, error = get_text_relics(file_path)
    remove_file(file_path)
    if error:
        utils.mark_job_success(job_id, False)
    else:
        save_relics(relics, sample, job_id)
        utils.mark_job_success(job_id, True)
Ejemplo n.º 3
0
    def test_05_create_job_info_object_status_exists_but_no_relics(self):
        """
        Should return job object of correct structure.
        """

        relics = []
        sample = "some text sample"
        job_id = "some-job-id"
        job_status = utils.mark_job_success(job_id,
                                            True,
                                            redis_conn=self.redis_conn)
        job_object = history.create_job_info_object(job_status, relics, sample,
                                                    job_id)
        self.assertIsInstance(job_object, dict)
        self.assertListEqual(job_object["relics"], relics)
        self.assertEqual(job_object["jobId"], job_id)
        self.assertEqual(job_object["timestamp"], job_status["timestamp"])
        self.assertEqual(job_object["sample"], sample)
        self.assertEqual(job_object["success"], True)
        self.assertFalse(job_object["inProgress"])
        self.assertTrue(job_object["expired"])
Ejemplo n.º 4
0
    def test_03_create_job_info_object_status_and_relics_exist(self):
        """
        Should return job object of correct structure.
        """

        relics = ["1", "2", "3"]
        sample = "some text sample"
        data = {"relics": relics, "sample": sample}
        job_id = "some-job-id"
        job_status = utils.mark_job_success(job_id,
                                            True,
                                            redis_conn=self.redis_conn)
        self.redis_conn.set(f"relics:{job_id}", json.dumps(data))
        job_object = history.create_job_info_object(job_status, relics, sample,
                                                    job_id)
        self.assertIsInstance(job_object, dict)
        self.assertListEqual(job_object["relics"], relics)
        self.assertEqual(job_object["jobId"], job_id)
        self.assertEqual(job_object["timestamp"], job_status["timestamp"])
        self.assertTrue(job_object["success"])
        self.assertTrue(job_object["sample"], sample)
        self.assertFalse(job_object["inProgress"])