Exemple #1
0
    def test_update_job(self):
        repo = Repo(dal.session)
        job1 = repo.get_incartjob(id='1')
        job1.doctor_id = 1
        ok: bool = repo.update_incartjob(job1)

        self.assertTrue(ok)
        job2 = repo.get_incartjob(id='1')
        self.assertEqual(job2.doctor_id, 1)
Exemple #2
0
    def run_job(self) -> None:
        repo = Repo(self.dal.session)
        job: IncartJob = repo.get_incartjob(self.job_id)
        jobdoctor: JobDoctor = None

        # искать исполнителя задания
        if job.doctor_id is None:
            jobdoctor = self.find_doctor(job)
        # исполнитель не найден(не нашли кандидата)
        if jobdoctor is None:
            self.set_restart_datetime(job)
            return
        # исполнитель не найден (кандидат отказалася)
        if job.doctor_id is None:
            self.stop_job(jobdoctor)
            return
        # отправить задание на исполнение
        self.send_job(jobdoctor)
        if jobdoctor.job_finish_id is None:
            self.stop_job(jobdoctor)
            return
        # задание не было выполнено в срок
        if jobdoctor.job_finished is None:
            self.stop_job(jobdoctor)
            return
        # доктор подтвердил выполнение задания
        job.closed = datetime.now().astimezone(timezone.utc)
        self.update_job(job)
        if job.file_decrypt:
            self.send_success(jobdoctor)  # послать подтверждение выполнения
        else:
            self.send_error(jobdoctor)  # послать сообщение
        self.send_result(job)
Exemple #3
0
    def test_find_jobdoctor(self):
        repo = Repo(dal.session)
        job = repo.get_incartjob(id='1')
        last_jobdoctor = job.jobdoctors[-1]

        self.assertEqual(len(job.jobdoctors), 2)
        self.assertIsNotNone(last_jobdoctor)
Exemple #4
0
 def test_job_relations(self):
     repo = Repo(dal.session)
     job1 = repo.get_incartjob(id='1')
     self.assertIsNotNone(job1)
     self.assertIsNotNone(job1.jobdoctors)
     self.assertTrue(isinstance(job1.jobdoctors, List))
     self.assertTrue(len(job1.jobdoctors), 2)
Exemple #5
0
    def test_get_job_candidate_first(self):
        repo = Repo(dal.session)
        job = repo.get_incartjob('2')
        candidate: Doctor = repo.get_job_candidate(job)

        self.assertIsNotNone(candidate)
        self.assertTrue(isinstance(candidate, Doctor))
        self.assertEqual(candidate.id, 1)
Exemple #6
0
    def test_get_job_none_candidate(self):
        repo = Repo(dal.session)
        doc3: Doctor = repo.get_doctor(id=96881373)  # Eugeny Bobylev
        doc3.is_active = False  # временно не доступен (temporarily unavailable)
        job: IncartJob = repo.get_incartjob(
            id="1")  # у этого задания есть 2 обращения к док 1 и 2
        doctor: Doctor = repo.get_job_candidate(job)

        self.assertIsNone(doctor)
Exemple #7
0
 def test_get_job(self):
     repo = Repo(dal.session)
     job = repo.get_incartjob(id='1')
     self.assertIsNotNone(job)
     self.assertEqual('job_1', job.snippet)
Exemple #8
0
def db_get_incartjob():
    job_id = '1733014f3b7bea76'
    with dal.session_scope() as session:
        repo = Repo(session)
        _task = repo.get_incartjob(job_id)
        print(_task)