コード例 #1
0
ファイル: sqs.py プロジェクト: MailBeaker/gmail-webhook
    def post_to_queue(self, message):
        """
        Actually post a message to the queue.

        :param message: the dict being posted the the SQS queue.
        """
        log.info('Call to post_to_queue()', extra={'payload': message})

        if not 'emailAddress' in message or not 'historyId' in message:
            raise ValueError("Message payload did not validate.")

        now = datetime.datetime.now()
        check_account_v1.delay(message['emailAddress'],
                               message['historyId'],
                               queue_time=now)
コード例 #2
0
ファイル: sqs.py プロジェクト: MailBeaker/gmail-webhook
    def post_to_queue(self, message):
        """
        Actually post a message to the queue.

        :param message: the dict being posted the the SQS queue.
        """
        log.info('Call to post_to_queue()', extra = {
            'payload': message
        })

        if not 'emailAddress' in message or not 'historyId' in message:
            raise ValueError("Message payload did not validate.")

        now = datetime.datetime.now()
        check_account_v1.delay(message['emailAddress'], message['historyId'], queue_time=now)
コード例 #3
0
def add_check_account_task(num, date, percent):
    now = None
    if not percent:
        percent = 100

    message = "Adding %d tasks to the queue." % num
    if date:
        now = datetime.datetime.now()
        message = "%s Current time is being included on each request." % message

    message = "%s %d%% of checks will result in a (simulated) new Gmail message." % (message, percent)
    print(message)

    # Read in the JSON response simulations.
    path = os.path.dirname(os.path.realpath(__file__))
    history_hit = open(os.path.join(path, "history_hit.json")).read()
    history_miss = open(os.path.join(path, "history_miss.json")).read()
    message = open(os.path.join(path, "message.json")).read()
    single_message_metadata = open(os.path.join(path, "single_message_metadata.json")).read()
    insert = open(os.path.join(path, "insert.json")).read()
    profile = open(os.path.join(path, "profile.json")).read()

    for x in range(1, (num + 1)):
        rand = cryptogen.randrange(1,100)
        if rand <= percent:
            http = HttpMockSequence([
                ({'status': '200'}, history_hit),
                ({'status': '200', 'content-type': 'multipart/mixed; boundary="batch_VZm0VD2PDxI_AAZXUZ1osU4"'}, message),
                ({'status': '200'}, single_message_metadata),
                ({'status': '200'}, insert),
                ({'status': '200'}, ''),  # Delete message
                ({'status': '200'}, profile)])
        else:
            http = HttpMockSequence([
                ({'status': '200'}, history_miss)])

        check_account_v1.delay(USER, USER_ID, HISTORY_ID, queue_time=now, http=http)