Ejemplo n.º 1
0
Archivo: event.py Proyecto: xplot/imeet
    def process_queue(self):
        """
            Process the event queue in batches
            Events status are going to be updated in Datastore

            TODO: Implement a priority mechanism, and a relation between events
            so all events from a single Invite are related under the same bucket
            The queue will only be stopped for that invite,
            and will continue for the other invites, and it's events

            For now, the whole queue will be stopped if one event fails.
        """
        q = taskqueue.Queue(QUEUE_NAME)

        event_tasks = q.lease_tasks(10, 50)
        delete_tasks = []

        for event_task in event_tasks:
            event_id = event_task.payload

            logging.info("Processing EventId: %s" % event_id)

            event = Event.get_by_unique_id(event_id)

            if event is None or event.skip_event():
                logging.info(
                    "Task will not retry"
                    "Either the event is nonexistent or it reached MAX retries"
                )
                delete_tasks.append(event_task)
                continue

            #Everything below will mean event.retries ++
            event.retries += 1

            if event.hold_event():
                logging.info(
                    "Event will be hold, because higher priority event, has to be processed"
                )
                event.status = EventStatus.FAILED
            else:
                try:
                    logging.info("Event URL: %s" % event.endpoint)
                    logging.info("This is going to be sent: ")
                    logging.info(event.payload)

                    self._make_request(event)

                    event.status = EventStatus.SENT
                    delete_tasks.append(event_task)
                except Exception, e:
                    logging.exception(e)
                    event.status = EventStatus.FAILED

            event.put()

            if event.status == EventStatus.FAILED:
                #We always break, then retry, events are considered blockers
                break
Ejemplo n.º 2
0
Archivo: event.py Proyecto: xplot/imeet
    def process_queue(self):
        """
            Process the event queue in batches
            Events status are going to be updated in Datastore

            TODO: Implement a priority mechanism, and a relation between events
            so all events from a single Invite are related under the same bucket
            The queue will only be stopped for that invite,
            and will continue for the other invites, and it's events

            For now, the whole queue will be stopped if one event fails.
        """
        q = taskqueue.Queue(QUEUE_NAME)

        event_tasks = q.lease_tasks(10, 50)
        delete_tasks = []

        for event_task in event_tasks:
            event_id = event_task.payload

            logging.info("Processing EventId: %s" % event_id)

            event = Event.get_by_unique_id(event_id)

            if event is None or event.skip_event():
                logging.info(
                    "Task will not retry"
                    "Either the event is nonexistent or it reached MAX retries"
                )
                delete_tasks.append(event_task)
                continue

            #Everything below will mean event.retries ++
            event.retries += 1

            if event.hold_event():
                logging.info(
                    "Event will be hold, because higher priority event, has to be processed"
                )
                event.status = EventStatus.FAILED
            else:
                try:
                    logging.info("Event URL: %s" % event.endpoint)
                    logging.info("This is going to be sent: ")
                    logging.info(event.payload)

                    self._make_request(event)

                    event.status = EventStatus.SENT
                    delete_tasks.append(event_task)
                except Exception, e:
                    logging.exception(e)
                    event.status = EventStatus.FAILED

            event.put()

            if event.status == EventStatus.FAILED:
                #We always break, then retry, events are considered blockers
                break