コード例 #1
0
ファイル: message.py プロジェクト: SOSbeacon/SchoolBeacon-GAE
def broadcast_to_student(student_key, event_key, message_key, batch_id=""):
    """Send broadcast to each of the student's contacts."""
    from sosbeacon.event.student_marker import create_or_update_marker
    from sosbeacon.student import Student  # Needed to load the entity.
    from sosbeacon.utils import insert_tasks

    student = student_key.get()

    if not student:
        # TODO: ?
        logging.info("Tried to broadcast %s to missing student %s.", message_key.urlsafe(), student_key.urlsafe())
        return

    tasks = []

    # contacts = {}
    for contact in student.contacts:
        # TODO: Optimize task building with memcache markers to
        # avoid building tasks that already exist.

        task = get_contact_broadcast_task(event_key, message_key, student_key, contact, batch_id)

        if not task:
            continue

        tasks.append(task)

        # TODO: WTF is this?
        # contacts[contact['t']] = contact

    if tasks:
        insert_tasks(tasks, CONTACT_TX_QUEUE)

    create_or_update_marker(event_key, student, message_key)
コード例 #2
0
ファイル: message.py プロジェクト: SOSbeacon/SchoolBeacon-GAE
def broadcast_to_contact(event_key, message_key, student_key, contact, batch_id=""):
    """Insert tasks to send message to each contact method, and create a
    contact marker.
    """
    from sosbeacon.event.contact_marker import create_or_update_marker
    from sosbeacon.utils import insert_tasks

    SEARCH_TYPES = ["e", "t"]

    # Find methods we want to query by.
    methods = set()
    for method in contact.get("methods", ()):
        method_type = method.get("type")
        value = method.get("value")

        if method_type == "t" and not value:
            SEARCH_TYPES.append("p")

        if not value or method_type not in SEARCH_TYPES:
            continue

        methods.add(value)

    if not methods:
        return

    short_id = create_or_update_marker(event_key, student_key, message_key, contact, methods)

    method_tasks = []
    for method in methods:
        method_tasks.append(get_method_broadcast_task(event_key, message_key, short_id, method, batch_id))

    insert_tasks(method_tasks, METHOD_TX_QUEUE)
コード例 #3
0
ファイル: message.py プロジェクト: SOSbeacon/SchoolBeacon-GAE
def broadcast_to_student(student_key, event_key, message_key, batch_id=''):
    """Send broadcast to each of the student's contacts."""
    from sosbeacon.event.student_marker import create_or_update_marker
    from sosbeacon.student import Student  # Needed to load the entity.
    from sosbeacon.utils import insert_tasks

    student = student_key.get()

    if not student:
        # TODO: ?
        logging.info('Tried to broadcast %s to missing student %s.',
                     message_key.urlsafe(), student_key.urlsafe())
        return

    tasks = []

    #contacts = {}
    for contact in student.contacts:
        # TODO: Optimize task building with memcache markers to
        # avoid building tasks that already exist.

        task = get_contact_broadcast_task(event_key, message_key, student_key,
                                          contact, batch_id)

        if not task:
            continue

        tasks.append(task)

        # TODO: WTF is this?
        #contacts[contact['t']] = contact

    if tasks:
        insert_tasks(tasks, CONTACT_TX_QUEUE)

    create_or_update_marker(event_key, student, message_key)
コード例 #4
0
ファイル: message.py プロジェクト: SOSbeacon/SchoolBeacon-GAE
def broadcast_to_contact(event_key,
                         message_key,
                         student_key,
                         contact,
                         batch_id=''):
    """Insert tasks to send message to each contact method, and create a
    contact marker.
    """
    from sosbeacon.event.contact_marker import create_or_update_marker
    from sosbeacon.utils import insert_tasks

    SEARCH_TYPES = ['e', 't']

    # Find methods we want to query by.
    methods = set()
    for method in contact.get('methods', ()):
        method_type = method.get('type')
        value = method.get('value')

        if method_type == 't' and not value:
            SEARCH_TYPES.append('p')

        if not value or method_type not in SEARCH_TYPES:
            continue

        methods.add(value)

    if not methods:
        return

    short_id = create_or_update_marker(event_key, student_key, message_key,
                                       contact, methods)

    method_tasks = []
    for method in methods:
        method_tasks.append(
            get_method_broadcast_task(event_key, message_key, short_id, method,
                                      batch_id))

    insert_tasks(method_tasks, METHOD_TX_QUEUE)