<commit_before>from datetime import datetime, timedelta
from sqlalchemy import or_

from changes.config import queue
from changes.models import Repository, RepositoryBackend


def check_repos():
    """
    Looks for any repositories which haven't checked in within several minutes
    and creates `sync_repo` tasks for them.
    """
    now = datetime.utcnow()
    cutoff = now - timedelta(minutes=3)

    repo_list = Repository.query.filter(
        Repository.backend != RepositoryBackend.unknown,
        or_(
            Repository.last_update_attempt < cutoff,
            Repository.last_update_attempt == None,  # NOQA
        )
    )
    for repo in repo_list:
        queue.delay('sync_repo', kwargs={
            'repo_id': repo.id.hex,
        })<commit_msg>Immediately mark last update attempt when checK-repos fires<commit_after>from datetime import datetime, timedelta
from sqlalchemy import or_

from changes.config import db
from changes.config import queue
from changes.models import Repository, RepositoryBackend


def check_repos():
    """
    Looks for any repositories which haven't checked in within several minutes
    and creates `sync_repo` tasks for them.
    """
    now = datetime.utcnow()
    cutoff = now - timedelta(minutes=3)

    repo_list = list(Repository.query.filter(
        Repository.backend != RepositoryBackend.unknown,
        or_(
            Repository.last_update_attempt < cutoff,
            Repository.last_update_attempt == None,  # NOQA
        )
    ))
    if not repo_list:
        return

    db.session.query(Repository).filter(
        Repository.id.in_([r.id for r in repo_list]),
    ).update({
        Repository.last_update_attempt: now,
    }, synchronize_session=False)

    for repo in repo_list:
        queue.delay('sync_repo', kwargs={
            'repo_id': repo.id.hex,
        })
{'fraction_non_alphanumeric': 0.08648648648648649, 'fraction_numerical': 0.001081081081081081, 'mean_word_length': 2.816494845360825, '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': '1433173', 'n_tokens_mistral': 545, 'n_tokens_neox': 509, 'n_words': 145}