def save_job_info(job_id, role, party_id, save_info, create=False): jobs = JobInfo.select().where(JobInfo.job_id == job_id, JobInfo.role == role, JobInfo.party_id == party_id) is_insert = True if jobs: job_info = jobs[0] is_insert = False elif create: job_info = JobInfo() else: return None job_info.job_id = job_id job_info.role = role job_info.party_id = party_id job_info.create_date = datetime.datetime.now() for k, v in save_info.items(): if k in ['job_id', 'role', 'party_id']: continue setattr(job_info, k, v) if is_insert: job_info.save(force_insert=True) else: job_info.save() return job_info
def save_job_info(job_id, role, party_id, save_info, create=False): jobs = JobInfo.select().where(JobInfo.job_id == job_id, JobInfo.role == role, JobInfo.party_id == party_id) is_insert = True if jobs: job_info = jobs[0] is_insert = False elif create: job_info = JobInfo() else: return None job_info.job_id = job_id job_info.role = role job_info.party_id = party_id job_info.create_date = datetime.datetime.now() if 'status' in save_info: if job_info.status in ['success', 'failed', 'partial', 'deleted']: # Termination status cannot be updated save_info.pop('status') for k, v in save_info.items(): if k in ['job_id', 'role', 'party_id']: continue setattr(job_info, k, v) if is_insert: job_info.save(force_insert=True) else: job_info.save() return job_info
def query_job_by_id(job_id): jobs = JobInfo.select().where(JobInfo.job_id == job_id) return jobs
def query_job_by_id(job_id): jobs = JobInfo.select().where(JobInfo.job_id == job_id) return [job.to_json() for job in jobs]