async def _post_judge(handler, rdoc): accept = rdoc['status'] == constant.record.STATUS_ACCEPTED bus.publish_throttle('record_change', rdoc, rdoc['_id']) post_coros = list() # TODO(twd2): ignore no effect statuses like system error, ... if rdoc['type'] == constant.record.TYPE_SUBMISSION: if accept: post_coros.append(_send_ac_mail(handler, rdoc)) if rdoc['tid']: post_coros.append( contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'], rdoc['_id'], rdoc['pid'], accept, rdoc['score'])) if not rdoc.get('rejudged'): if await problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'], rdoc['_id'], rdoc['status']): if accept: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. await problem.inc(rdoc['domain_id'], rdoc['pid'], 'num_accept', 1) post_coros.append( domain.inc_user(rdoc['domain_id'], rdoc['uid'], num_accept=1)) else: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. await job.record.user_in_problem(rdoc['uid'], rdoc['domain_id'], rdoc['pid']) post_coros.append( job.difficulty.update_problem(rdoc['domain_id'], rdoc['pid'])) await asyncio.gather(*post_coros)
async def _post_judge(rdoc): await opcount.force_inc(**opcount.OPS['run_code'], ident=opcount.PREFIX_USER + str(rdoc['uid']), operations=rdoc['time_ms']) accept = rdoc['status'] == constant.record.STATUS_ACCEPTED post_coros = [bus.publish('record_change', rdoc['_id'])] # TODO(twd2): ignore no effect statuses like system error, ... if rdoc['type'] == constant.record.TYPE_SUBMISSION: if accept: # TODO(twd2): send ac mail pass if rdoc['tid']: post_coros.append(contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'], rdoc['_id'], rdoc['pid'], accept, rdoc['score'])) if not rdoc.get('rejudged'): if await problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'], rdoc['_id'], rdoc['status']): post_coros.append(problem.inc(rdoc['domain_id'], rdoc['pid'], 'num_accept', 1)) post_coros.append(domain.inc_user(rdoc['domain_id'], rdoc['uid'], num_accept=1)) if accept: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. pass else: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. await job.record.user_in_problem(rdoc['uid'], rdoc['domain_id'], rdoc['pid']) await asyncio.gather(*post_coros)
async def _post_judge(handler, rdoc): accept = rdoc['status'] == constant.record.STATUS_ACCEPTED bus.publish_throttle('record_change', rdoc, rdoc['_id']) post_coros = list() # TODO(twd2): ignore no effect statuses like system error, ... if rdoc['type'] == constant.record.TYPE_SUBMISSION: if accept: post_coros.append(_send_ac_mail(handler, rdoc)) if rdoc['tid']: post_coros.append(contest.update_status(rdoc['domain_id'], rdoc.get('ttype', document.TYPE_CONTEST), rdoc['tid'], rdoc['uid'], rdoc['_id'], rdoc['pid'], accept, rdoc['score'])) if not rdoc.get('rejudged'): if await problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'], rdoc['_id'], rdoc['status']): if accept: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. await problem.inc(rdoc['domain_id'], rdoc['pid'], 'num_accept', 1) post_coros.append(domain.inc_user(rdoc['domain_id'], rdoc['uid'], num_accept=1)) else: # TODO(twd2): enqueue rdoc['pid'] to recalculate rp. await job.record.user_in_problem(rdoc['uid'], rdoc['domain_id'], rdoc['pid']) post_coros.append(job.difficulty.update_problem(rdoc['domain_id'], rdoc['pid'])) await asyncio.gather(*post_coros)
async def on_message(self, *, key, tag, **kwargs): if key == 'next': rid = self.rids[tag] update = {} if 'status' in kwargs: update.setdefault('$set', {})['status'] = int(kwargs['status']) if 'compiler_text' in kwargs: update.setdefault('$push', {})['compiler_texts'] = str( kwargs['compiler_text']) if 'judge_text' in kwargs: update.setdefault('$push', {})['judge_texts'] = str( kwargs['judge_text']) if 'case' in kwargs: update.setdefault('$push', {})['cases'] = { 'status': int(kwargs['case']['status']), 'score': int(kwargs['case']['score']), 'time_ms': int(kwargs['case']['time_ms']), 'memory_kb': int(kwargs['case']['memory_kb']), } await record.next_judge(rid, self.user['_id'], self.id, **update) await bus.publish('record_change', rid) elif key == 'end': rid = self.rids.pop(tag) rdoc, _ = await asyncio.gather( record.end_judge(rid, self.user['_id'], self.id, int(kwargs['status']), int(kwargs['score']), int(kwargs['time_ms']), int(kwargs['memory_kb'])), self.channel.basic_client_ack(tag)) accept = True if rdoc['status'] == record.STATUS_ACCEPTED else False # TODO(twd2): update problem post_coros = [ problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'], rdoc['_id'], rdoc['status']), bus.publish('record_change', rid) ] if rdoc['tid']: post_coros.append( contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'], rdoc['_id'], rdoc['pid'], accept, rdoc['score'])) if accept: post_coros.append( training.update_status_by_pid(rdoc['domain_id'], rdoc['uid'], rdoc['pid'])) await asyncio.gather(*post_coros) elif key == 'nack': await self.channel.basic_client_nack(tag)
async def on_message(self, *, key, tag, **kwargs): if key == 'next': rid = self.rids[tag] update = {} if 'status' in kwargs: update.setdefault('$set', {})['status'] = int(kwargs['status']) if 'compiler_text' in kwargs: update.setdefault('$push', {})['compiler_texts'] = str(kwargs['compiler_text']) if 'judge_text' in kwargs: update.setdefault('$push', {})['judge_texts'] = str(kwargs['judge_text']) if 'case' in kwargs: update.setdefault('$push', {})['cases'] = { 'status': int(kwargs['case']['status']), 'score': int(kwargs['case']['score']), 'time_ms': int(kwargs['case']['time_ms']), 'memory_kb': int(kwargs['case']['memory_kb']), } await record.next_judge(rid, self.user['_id'], self.id, **update) await bus.publish('record_change', rid) elif key == 'end': rid = self.rids.pop(tag) rdoc, _ = await asyncio.gather(record.end_judge(rid, self.user['_id'], self.id, int(kwargs['status']), int(kwargs['score']), int(kwargs['time_ms']), int(kwargs['memory_kb'])), self.channel.basic_client_ack(tag)) accept = True if rdoc['status'] == record.STATUS_ACCEPTED else False # TODO(twd2): update problem post_coros = [problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'], rdoc['_id'], rdoc['status']), bus.publish('record_change', rid)] if rdoc['tid']: post_coros.append(contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'], rdoc['_id'], rdoc['pid'], accept, rdoc['score'])) if accept: post_coros.append(training.update_status_by_pid(rdoc['domain_id'], rdoc['uid'], rdoc['pid'])) await asyncio.gather(*post_coros) elif key == 'nack': await self.channel.basic_client_nack(tag)