<commit_before>from __future__ import absolute_import

from datetime import datetime

from celery import Celery
from celery.utils.log import get_task_logger
from flask import current_app as app

from ..app import create_app


logger = get_task_logger('fquest')


if not app:
    app = create_app()
    ctx = app.test_request_context()
    ctx.push()

celery = Celery('fquest')
celery.config_from_object(dict(
    BROKER_URL=app.config.get('BROKER_URL'),
    CELERYBEAT_SCHEDULE={
        'fquest-beat': {
            'task': 'base.fquest.celery.beat',
            'schedule': app.config.get('BEAT_SCHEDULE'),
        },
    }
))


@celery.task(ignore_result=True)
def beat():
    " Fetch character progress. "

    from .models import Character, db, Event
    from ..ext import cache

    last_synced = cache.get('fquest.last_synced')
    logger.info('BEAT')

    if last_synced:
        characters = Character.query.filter(Character.facebook_synced <= last_synced).limit(10).all()

    else:
        characters = [Character.query.order_by(Character.facebook_synced.desc()).first()]

    cache.set('fquest.last_synced', datetime.now(), timeout=300)

    for character in characters:
        Event.fire(character)

    db.session.commit()
<commit_msg>Fix stupid error<commit_after>from __future__ import absolute_import
from sqlalchemy.exc import IntegrityError, DataError

from datetime import datetime, timedelta

from celery import Celery
from celery.utils.log import get_task_logger
from flask import current_app as app

from ..app import create_app


logger = get_task_logger('fquest')


if not app:
    app = create_app()
    ctx = app.test_request_context()
    ctx.push()

celery = Celery('fquest')
celery.config_from_object(dict(
    BROKER_URL=app.config.get('BROKER_URL'),
    CELERYBEAT_SCHEDULE={
        'fquest-beat': {
            'task': 'base.fquest.celery.beat',
            'schedule': app.config.get('BEAT_SCHEDULE'),
        },
    }
))


@celery.task(ignore_result=True)
def beat():
    " Fetch character progress. "

    from .models import Character, db, Event
    from ..ext import cache

    last_synced = cache.get('fquest.last_synced')
    logger.info('BEAT')

    if last_synced:
        characters = Character.query.filter(Character.facebook_synced <= last_synced - timedelta(minutes=10)).limit(10).all()

    else:
        characters = [Character.query.order_by(Character.facebook_synced.desc()).first()]

    cache.set('fquest.last_synced', datetime.now(), timeout=300)

    for character in characters:
        Event.fire(character)
        try:
            db.session.commit()
        except (IntegrityError, DataError):
            db.session.rollback()

{'fraction_non_alphanumeric': 0.11602826329490516, 'fraction_numerical': 0.004462625511342506, 'mean_word_length': 3.3739837398373984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5285428', 'n_tokens_mistral': 879, 'n_tokens_neox': 850, 'n_words': 178}