def request_stats():
    """ Check if the current user's statistics have been calculated and if not,
        put them in the stats queue for stats_calculator.
    """
    status = _redis.redis.get(construct_stats_queue_key(current_user.musicbrainz_id)) == 'queued'
    if status == 'queued':
        flash.info('You have already been added to the stats calculation queue! Please check back later.')
    elif db_stats.valid_stats_exist(current_user.id):
        flash.info('Your stats were calculated in the most recent stats calculation interval,'
            ' please wait until the next interval! We calculate new statistics every Monday at 00:00 UTC.')
    else:
        # publish to rabbitmq queue that the stats-calculator consumes
        data = {
            'type': 'user',
            'id': current_user.id,
            'musicbrainz_id': current_user.musicbrainz_id,
        }
        publish_data_to_queue(
            data=data,
            exchange=current_app.config['BIGQUERY_EXCHANGE'],
            queue=current_app.config['BIGQUERY_QUEUE'],
            error_msg='Could not put user %s into statistics calculation queue, please try again later',
        )
        _redis.redis.set(construct_stats_queue_key(current_user.musicbrainz_id), 'queued')
        flash.info('You have been added to the stats calculation queue! Please check back later.')
    return redirect(url_for('profile.info'))
Example #2
0
def request_stats():
    """ Check if the current user's statistics have been calculated and if not,
        put them in the stats queue for stats_calculator.
    """
    status = _redis.redis.get(
        construct_stats_queue_key(current_user.musicbrainz_id)) == 'queued'
    if status == 'queued':
        flash.info(
            'You have already been added to the stats calculation queue! Please check back later.'
        )
    elif db_stats.valid_stats_exist(current_user.id):
        flash.info(
            'Your stats were calculated in the most recent stats calculation interval,'
            ' please wait until the next interval! We calculate new statistics every Monday at 00:00 UTC.'
        )
    else:
        # publish to rabbitmq queue that the stats-calculator consumes
        data = {
            'type': 'user',
            'id': current_user.id,
            'musicbrainz_id': current_user.musicbrainz_id,
        }
        publish_data_to_queue(
            data=data,
            exchange=current_app.config['BIGQUERY_EXCHANGE'],
            queue=current_app.config['BIGQUERY_QUEUE'],
            error_msg=
            'Could not put user %s into statistics calculation queue, please try again later',
        )
        _redis.redis.set(
            construct_stats_queue_key(current_user.musicbrainz_id), 'queued')
        flash.info(
            'You have been added to the stats calculation queue! Please check back later.'
        )
    return redirect(url_for('profile.info'))
Example #3
0
def delete_user(musicbrainz_id):
    """ Delete a user from ListenBrainz completely.
    First, drops the user's influx measurement and then deletes her from the
    database.

    Args:
        musicbrainz_id (str): the MusicBrainz ID of the user

    Raises:
        NotFound if user isn't present in the database
    """

    user = _get_user(musicbrainz_id)
    _influx.delete(user.musicbrainz_id)
    publish_data_to_queue(
        data={
            'type': 'delete.user',
            'musicbrainz_id': musicbrainz_id,
        },
        exchange=current_app.config['BIGQUERY_EXCHANGE'],
        queue=current_app.config['BIGQUERY_QUEUE'],
        error_msg=
        'Could not put user %s into queue for deletion, please try again later'
        % musicbrainz_id,
    )
    db_user.delete(user.id)
def delete_user(user):
    influx.delete(user['musicbrainz_id'])
    publish_data_to_queue(
        data={
            'type': 'delete.user',
            'musicbrainz_id': user['musicbrainz_id'],
        },
        exchange=app.config['BIGQUERY_EXCHANGE'],
        queue=app.config['BIGQUERY_QUEUE'],
        error_msg='Could not upt user %s into queue for bq deletion.' % user['musicbrainz_id'],
    )
    db_user.delete(user['id'])
Example #5
0
def delete_user(user):
    influx.delete(user['musicbrainz_id'])
    publish_data_to_queue(
        data={
            'type': 'delete.user',
            'musicbrainz_id': user['musicbrainz_id'],
        },
        exchange=app.config['BIGQUERY_EXCHANGE'],
        queue=app.config['BIGQUERY_QUEUE'],
        error_msg='Could not upt user %s into queue for bq deletion.' %
        user['musicbrainz_id'],
    )
    db_user.delete(user['id'])
Example #6
0
def delete_user(musicbrainz_id):
    """ Delete a user from ListenBrainz completely.
    First, drops the user's influx measurement and then deletes her from the
    database.

    Args:
        musicbrainz_id (str): the MusicBrainz ID of the user

    Raises:
        NotFound if user isn't present in the database
    """

    user = _get_user(musicbrainz_id)
    _influx.delete(user.musicbrainz_id)
    publish_data_to_queue(
        data={
            'type': 'delete.user',
            'musicbrainz_id': musicbrainz_id,
        },
        exchange=current_app.config['BIGQUERY_EXCHANGE'],
        queue=current_app.config['BIGQUERY_QUEUE'],
        error_msg='Could not put user %s into queue for deletion, please try again later' % musicbrainz_id,
    )
    db_user.delete(user.id)