Beispiel #1
0
def process_fxa_event(raw_body, **kwargs):
    """Parse and process a single firefox account event."""
    # Try very hard not to error out if there's junk in the queue.
    log = getLogger('accounts.sqs')
    event_type = None
    try:
        body = json.loads(raw_body)
        event = json.loads(body['Message'])
        event_type = event.get('event')
        uid = event.get('uid')
        timestamp = event.get('ts', 0)
        if not (event_type and uid and timestamp):
            raise ValueError(
                'Properties event, uuid, and ts must all be non-empty')
    except (ValueError, KeyError, TypeError) as e:
        log.exception('Invalid account message: %s' % e)
    else:
        if event_type == 'primaryEmailChanged':
            email = event.get('email')
            if not email:
                log.error('Email property must be non-empty for "%s" event' %
                          event_type)
            else:
                primary_email_change_event.delay(email, uid, timestamp)
        else:
            log.debug('Dropping unknown event type %r', event_type)
Beispiel #2
0
def process_fxa_event(raw_body, **kwargs):
    """Parse and process a single firefox account event."""
    # Try very hard not to error out if there's junk in the queue.
    log = getLogger('accounts.sqs')
    event_type = None
    try:
        body = json.loads(raw_body)
        event = json.loads(body['Message'])
        event_type = event.get('event')
        uid = event.get('uid')
        timestamp = event.get('ts', 0)
        if not (event_type and uid and timestamp):
            raise ValueError(
                'Properties event, uuid, and ts must all be non-empty')
    except (ValueError, KeyError, TypeError) as e:
        log.exception('Invalid account message: %s' % e)
    else:
        if event_type == 'primaryEmailChanged':
            email = event.get('email')
            if not email:
                log.error('Email property must be non-empty for "%s" event' %
                          event_type)
            else:
                primary_email_change_event.delay(email, uid, timestamp)
        else:
            log.debug('Dropping unknown event type %r', event_type)
Beispiel #3
0
        event_type = event.get('event')
        uid = event.get('uid')
        timestamp = datetime.fromtimestamp(event.get('ts', ''))
        if not (event_type and uid and timestamp):
            raise ValueError(
                'Properties event, uuid, and ts must all be non-empty')
    except (ValueError, KeyError, TypeError), e:
        log.exception('Invalid account message: %s' % e)
    else:
        if event_type == 'primaryEmailChanged':
            email = event.get('email')
            if not email:
                log.error('Email property must be non-empty for "%s" event' %
                          event_type)
            else:
                primary_email_change_event.delay(email, uid, timestamp)
        else:
            log.debug('Dropping unknown event type %r', event_type)


def process_sqs_queue(queue_url):
    log = getLogger('accounts.sqs')
    log.info('Processing account events from %s', queue_url)
    try:
        region = queue_url.split('.')[1]
        available_regions = (boto3._get_default_session()
                             .get_available_regions('sqs'))
        if region not in available_regions:
            log.error('SQS misconfigured, expected region, got %s from %s' % (
                region, queue_url))
        # Connect to the SQS queue.
Beispiel #4
0
        event_type = event.get('event')
        uid = event.get('uid')
        timestamp = datetime.fromtimestamp(event.get('ts', ''))
        if not (event_type and uid and timestamp):
            raise ValueError(
                'Properties event, uuid, and ts must all be non-empty')
    except (ValueError, KeyError, TypeError), e:
        log.exception('Invalid account message: %s' % e)
    else:
        if event_type == 'primaryEmailChanged':
            email = event.get('email')
            if not email:
                log.error('Email property must be non-empty for "%s" event' %
                          event_type)
            else:
                primary_email_change_event.delay(email, uid, timestamp)
        else:
            log.debug('Dropping unknown event type %r', event_type)


def process_sqs_queue(queue_url, aws_region, queue_wait_time):
    log = getLogger('accounts.sqs')
    log.info('Processing account events from %s', queue_url)
    try:
        # Connect to the SQS queue.
        sqs = boto3.client(
            'sqs',
            aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
            aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
            region_name=aws_region)
        # Poll for messages indefinitely.