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)
def find_suitable_status_for_finish_a_job(): error_free, status = Status.find_status(Keys.STATUS_DONE) if not error_free: return False, error_free if status is None: return False, return True, status
def _is_job_payable(self): error_free, ids = Status.load_not_payable_statues_ids() if not error_free: return False, ids if self.job.status_id in ids: return False, JobNotPayable( status=404, message=MessagesKeys.JOB_IS_NOT_PAYABLE, params=None) else: return True,
def init_status(): data = [ Keys.STATUS_DONE, Keys.STATUS_PENDING, Keys.STATUS_CANCELLED_BY_CAR_OWNER, Keys.STATUS_CANCELLED_BY_BUSINESS_OWNER, Keys.STATUS_ACCEPTED_BY_BUSINESS_OWNER, Keys.STATUS_DENIED_BY_BUSINESS_OWNER, Keys.STATUS_TIMEOUT, Keys.STATUS_START ] for datum in data: status = Status(name=datum) db.session.add(status) db.session.commit()
def register_problem(db, job, problems): result = True, try: job.car_problems.extend(problems) pending_status = Status.load_status(Keys.STATUS_PENDING) if not pending_status[0]: raise Exception() job.status_id = pending_status[1].id db.session.add(job) db.session.commit() result = True, SuccessRegisterProblem( status=200, message=MessagesKeys.SUCCESS_REGISTER_PROBLEM, params={Keys.ID: job.id}) except: db.session.rollback() result = db_error_message(logger) return result
def load_status(status_name): return Status.find_status(status_name)