def postUpdateHook(cls, matches, updated_attr_list, is_new_list):
        '''
        To run after the match has been updated.
        Send push notifications to subscribed users
        Only if the match is part of an active event
        '''
        unplayed_match_events = []
        for (match, updated_attrs, is_new) in zip(matches, updated_attr_list, is_new_list):
            event = match.event.get()
            # Only continue if the event is currently happening
            if event.within_a_day:
                if match.has_been_played:
                    if is_new or 'alliances_json' in updated_attrs:
                        # There is a score update for this match, push a notification
                        logging.info("Sending push notifications for {}".format(match.key_name))
                        try:
                            NotificationHelper.send_match_score_update(match)
                        except Exception, exception:
                            logging.error("Error sending match updates: {}".format(exception))
                            logging.error(traceback.format_exc())
                else:
                    if is_new or (set(['alliances_json', 'time', 'time_string']).intersection(set(updated_attrs)) != set()):
                        # The match has not been played and we're changing a property that affects the event's schedule
                        # So send a schedule update notification for the parent event
                        if event not in unplayed_match_events:
                            unplayed_match_events.append(event)

            # Try to send video notifications
            if '_video_added' in updated_attrs:
                try:
                    NotificationHelper.send_match_video(match)
                except Exception, exception:
                    logging.error("Error sending match video updates: {}".format(exception))
                    logging.error(traceback.format_exc())
Beispiel #2
0
    def postUpdateHook(cls, matches, updated_attr_list, is_new_list):
        '''
        To run after the match has been updated.
        Send push notifications to subscribed users
        Only if the match is part of an active event
        '''
        unplayed_match_events = []
        for (match, updated_attrs, is_new) in zip(matches, updated_attr_list,
                                                  is_new_list):
            event = match.event.get()
            # Only continue if the event is currently happening
            if event.within_a_day:
                if match.has_been_played:
                    if is_new or 'alliances_json' in updated_attrs:
                        # There is a score update for this match, push a notification
                        logging.info(
                            "Sending push notifications for {}".format(
                                match.key_name))
                        try:
                            NotificationHelper.send_match_score_update(match)
                        except Exception, exception:
                            logging.error(
                                "Error sending match updates: {}".format(
                                    exception))
                            logging.error(traceback.format_exc())
                else:
                    if is_new or (set([
                            'alliances_json', 'time', 'time_string'
                    ]).intersection(set(updated_attrs)) != set()):
                        # The match has not been played and we're changing a property that affects the event's schedule
                        # So send a schedule update notification for the parent event
                        if event not in unplayed_match_events:
                            unplayed_match_events.append(event)

            # Try to send video notifications
            if '_video_added' in updated_attrs:
                try:
                    NotificationHelper.send_match_video(match)
                except Exception, exception:
                    logging.error(
                        "Error sending match video updates: {}".format(
                            exception))
                    logging.error(traceback.format_exc())
Beispiel #3
0
class MatchManipulator(ManipulatorBase):
    """
    Handle Match database writes.
    """
    @classmethod
    def getCacheKeysAndControllers(cls, affected_refs):
        return CacheClearer.get_match_cache_keys_and_controllers(affected_refs)

    @classmethod
    def postDeleteHook(cls, matches):
        '''
        To run after the match has been deleted.
        '''
        for match in matches:
            try:
                FirebasePusher.delete_match(match)
            except Exception:
                logging.warning("Firebase delete_match failed!")

    @classmethod
    def postUpdateHook(cls, matches, updated_attr_list, is_new_list):
        '''
        To run after the match has been updated.
        Send push notifications to subscribed users
        Only if the match is part of an active event
        '''
        unplayed_match_events = []
        for (match, updated_attrs, is_new) in zip(matches, updated_attr_list,
                                                  is_new_list):
            event = match.event.get()
            # Only continue if the event is currently happening
            if event.now:
                if match.has_been_played:
                    if is_new or 'alliances_json' in updated_attrs:
                        # There is a score update for this match, push a notification
                        logging.info(
                            "Sending push notifications for {}".format(
                                match.key_name))
                        try:
                            NotificationHelper.send_match_score_update(match)
                        except Exception, exception:
                            logging.error(
                                "Error sending match updates: {}".format(
                                    exception))
                            logging.error(traceback.format_exc())
                        try:
                            TBANSHelper.match_score(match)
                        except Exception, exception:
                            logging.error(
                                "Error sending match {} updates: {}".format(
                                    match.key_name, exception))
                            logging.error(traceback.format_exc())
                else:
                    if is_new or (set([
                            'alliances_json', 'time', 'time_string'
                    ]).intersection(set(updated_attrs)) != set()):
                        # The match has not been played and we're changing a property that affects the event's schedule
                        # So send a schedule update notification for the parent event
                        if event not in unplayed_match_events:
                            unplayed_match_events.append(event)

            # Try to send video notifications
            if '_video_added' in updated_attrs:
                try:
                    NotificationHelper.send_match_video(match)
                except Exception, exception:
                    logging.error(
                        "Error sending match video updates: {}".format(
                            exception))
                    logging.error(traceback.format_exc())
                try:
                    TBANSHelper.match_video(match)
                except Exception, exception:
                    logging.error(
                        "Error sending match video updates: {}".format(
                            exception))
                    logging.error(traceback.format_exc())