<commit_before>from datetime import datetime
from flask import current_app
from sqlalchemy.orm import subqueryload_all
import sys
import warnings

from changes.backends.base import UnrecoverableException
from changes.backends.jenkins.builder import JenkinsBuilder
from changes.config import db, queue
from changes.constants import Status, Result
from changes.events import publish_build_update
from changes.models import Build, BuildPlan, Plan, RemoteEntity
from changes.utils.locking import lock


def sync_with_builder(build):
    build.date_modified = datetime.utcnow()
    db.session.add(build)

    entity = RemoteEntity.query.filter_by(
        provider='jenkins',
        internal_id=build.id,
        type='build',
    ).first()
    if not entity:
        queue.delay('create_build', kwargs={
            'build_id': build.id.hex,
        }, countdown=5)
    else:
        builder = JenkinsBuilder(
            app=current_app,
            base_url=current_app.config['JENKINS_URL'],
        )
        builder.sync_build(build)


def _sync_build(build_id):
    build = Build.query.get(build_id)
    if not build:
        return

    if build.status == Status.finished:
        return<commit_msg>Fix legacy sync<commit_after>from datetime import datetime
from flask import current_app
from sqlalchemy.orm import subqueryload_all
import sys
import warnings

from changes.backends.base import UnrecoverableException
from changes.backends.jenkins.builder import JenkinsBuilder
from changes.config import db, queue
from changes.constants import Status, Result
from changes.events import publish_build_update
from changes.models import Build, BuildPlan, Plan, RemoteEntity
from changes.utils.locking import lock


def sync_with_builder(build):
    build.date_modified = datetime.utcnow()
    db.session.add(build)

    # TODO(dcramer): remove migration after 12/24
    if not build.data:
        entity = RemoteEntity.query.filter_by(
            provider='jenkins',
            internal_id=build.id,
            type='build',
        ).first()
        if entity is not None:
            build.data = entity.data
            db.session.add(build)

    if not build.data:
        queue.delay('create_build', kwargs={
            'build_id': build.id.hex,
        }, countdown=5)
    else:
        builder = JenkinsBuilder(
            app=current_app,
            base_url=current_app.config['JENKINS_URL'],
        )
        builder.sync_build(build)


def _sync_build(build_id):
    build = Build.query.get(build_id)
    if not build:
        return

    if build.status == Status.finished:
        return
{'fraction_non_alphanumeric': 0.08205521472392638, 'fraction_numerical': 0.0023006134969325155, 'mean_word_length': 3.020030816640986, 'pattern_counts': {'":': 0, '<': 3, '<?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': '783600', 'n_tokens_mistral': 747, 'n_tokens_neox': 729, 'n_words': 189}