示例#1
0
    def _unfinished():
        time_delta = datetime.timedelta(hours=12)
        late_to_finish_jobs = []
        late_to_start_jobs = []

        error_free_start_status, start_status = Status.find_status(Keys.STATUS_START)
        error_free_accepted_status, accepted_status = Status.find_status(Keys.STATUS_ACCEPTED_BY_BUSINESS_OWNER)
        if not error_free_start_status:
            return accepted_status

        list_started_jobs = Job.find(status_id=start_status.id)[1]
        list_accepted_jobs = Job.find(100000, status_id=accepted_status.id)[1]

        if list_started_jobs is not []:

            for unfinished_job in list_started_jobs:
                now_time = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
                                                      "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M:%S")
                if unfinished_job.start_time is not None:
                    real_start_time = unfinished_job.start_time.strftime("%Y-%m-%d %H:%M:%S")
                    start_time_schedule = unfinished_job.start_schedule.strftime("%Y-%m-%d %H:%M:%S")
                    finish_time_schedule = unfinished_job.finish_schedule.strftime("%Y-%m-%d %H:%M:%S")

                    time_length_to_finish_job = datetime.datetime.strptime(finish_time_schedule,
                                                                           '%Y-%m-%d %H:%M:%S') - datetime.datetime.strptime(
                        start_time_schedule, '%Y-%m-%d %H:%M:%S')

                    expected_time_to_finish = datetime.datetime.strptime(real_start_time,
                                                                         '%Y-%m-%d %H:%M:%S') + time_length_to_finish_job

                    if now_time > expected_time_to_finish.strftime("%Y-%m-%d %H:%M:%S"):
                        late_to_finish_jobs.append(unfinished_job.id)
                else:
                    start_time_schedule = unfinished_job.start_schedule.strftime("%Y-%m-%d %H:%M:%S")
                    if start_time_schedule + str(time_delta) > now_time:
                        late_to_finish_jobs.append(unfinished_job.id)

        if list_accepted_jobs is not []:
            for accepted_job in list_accepted_jobs:

                job_limited_time = datetime.datetime.strptime(str(accepted_job.start_schedule + time_delta),
                                                              "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
                now_time = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
                                                      "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M:%S")

                if now_time > job_limited_time:
                    late_to_start_jobs.append(accepted_job.id)

        wanted_list = late_to_start_jobs + late_to_finish_jobs

        error_free, unfinished_jobs = AutoServiceJob.unfinished(wanted_list)
        if not error_free:
            return unfinished_jobs
        return True, SuccessListOfUnfinishedJob(status=200, message=MessagesKeys.SUCCESS_LIST,
                                                params=unfinished_jobs)
示例#2
0
 def _is_job_existence(self):
     error_free, result = Job.find(id=self.job_id)
     if not error_free:
         return False, result
     if len(result) == 0:
         return False, JobNotFound(status=404,
                                   message=MessagesKeys.ID_IS_NOT_IN_DB,
                                   params=None)
     self.job_id = result[0].id
     return True, result[0]
示例#3
0
    def execute(self):
        error_free, result = Job.find(car_owner_id=self.car_owner_id)
        if not error_free:
            dct = result.dictionary_creator()
            return self.serialize(dct, self.converter)
        if result:
            error_free, payable_job = self._payable_job()
            if not error_free:
                dct = payable_job.dictionary_creator()
                return self.serialize(dct, converter=self.converter)

            #    if payable_job ro check konam?

            dct = payable_job.dictionary_creator()
            return self.serialize(dct, converter=self.converter)

        else:
            is_busy = JobNotFound(status=404,
                                  message=MessagesKeys.NOT_FOUND_JOB,
                                  params=None)
            dct = is_busy.dictionary_creator()
            return self.serialize(dct, self.converter)