<commit_before>from __future__ import absolute_import, division, unicode_literals

from sqlalchemy.sql import func

from changes.api.base import APIView
from changes.constants import Status
from changes.config import db, redis
from changes.models import Job, JobPlan, JobStep


class JobStepAllocateAPIView(APIView):
    def find_next_jobstep(self):
        # find projects with pending allocations
        project_list = [p for p, in db.session.query(
            JobStep.project_id,
        ).filter(
            JobStep.status == Status.pending_allocation,
        ).group_by(
            JobStep.project_id
        )]

        # TODO(dcramer): this should be configurably and handle more cases
        # than just 'active job' as that can be 1 step or 100 steps
        # find the total number of job steps in progress per project
        # hard limit of 10 active jobs per project<commit_msg>Handle case with no pending allocations<commit_after>from __future__ import absolute_import, division, unicode_literals

from sqlalchemy.sql import func

from changes.api.base import APIView
from changes.constants import Status
from changes.config import db, redis
from changes.models import Job, JobPlan, JobStep


class JobStepAllocateAPIView(APIView):
    def find_next_jobstep(self):
        # find projects with pending allocations
        project_list = [p for p, in db.session.query(
            Job.project_id,
        ).filter(
            Job.status == Status.pending_allocation,
        ).group_by(
            Job.project_id
        )]
        if not project_list:
            return None

        # TODO(dcramer): this should be configurably and handle more cases
        # than just 'active job' as that can be 1 step or 100 steps
        # find the total number of job steps in progress per project
        # hard limit of 10 active jobs per project
{'fraction_non_alphanumeric': 0.05642127888232133, 'fraction_numerical': 0.006448146157979581, 'mean_word_length': 2.807770961145194, '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': '4309000', 'n_tokens_mistral': 506, 'n_tokens_neox': 483, 'n_words': 191}