Ejemplo n.º 1
0
def scan_match_start_time():
    """
    定时扫描 Match 表, 提前两小时发送比赛开始通知
    :return:
    """
    now = datetime.now()
    max_dt = now + timedelta(hours=2)
    min_dt = now - timedelta(minutes=10)
    matches = Match.select().where(Match.pushed.is_null(),
                                   Match.start_time >= min_dt,
                                   Match.start_time <= max_dt)
    for match in matches:
        match_start.delay(match_id=match.id)
        Match.update(pushed=now).where(Match.id == match.id).execute()
Ejemplo n.º 2
0
    def cancel(cls, match: Match, user: User):
        """
        主办方取消赛事
        :param match:
        :param user:
        :return:
        """
        from yiyun.tasks.match import batch_refund_worker
        if not match.can_cancel():
            raise MatchStateError("当前赛事状态无法取消: {0}".format(match.state))

        with cls.database.transaction():
            Match.update(state=Match.MatchState.cancelled.value)\
                .where(Match.id == match.id).execute()

            members = MatchMember.select()\
                .where(MatchMember.match_id == match.id,
                       MatchMember.state >= MatchMember.MatchMemberState.wait_pay.value,
                       MatchMember.state <= MatchMember.MatchMemberState.normal.value)
            for member in members:
                batch_refund_worker.delay(member_id=member.id)
Ejemplo n.º 3
0
    def post(self, match_id):

        action = self.get_argument("action")
        match = Match.get_or_404(id=match_id)

        if action == "pass":
            Match.update(
                state=Match.MatchState.opening, updated=datetime.now()).where(
                    Match.id == match.id, Match.state <<
                    [Match.MatchState.wait_review, Match.MatchState.in_review
                     ]).execute()

        elif action == "reject":
            Match.update(
                state=Match.MatchState.rejected,
                reject_time=datetime.now(),
                reject_reason=self.get_argument("reject_reason", "")).where(
                    Match.id == match.id, Match.state <<
                    [Match.MatchState.wait_review, Match.MatchState.in_review
                     ]).execute()

        self.write_success()