<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

###############################################################################
#  Copyright Kitware Inc.
#
#  Licensed under the Apache License, Version 2.0 ( the "License" );
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
###############################################################################

import datetime

from girder import events
from girder.constants import AccessType
from girder.models.model_base import AccessControlledModel
from .constants import JobStatus


class Job(AccessControlledModel):
    def initialize(self):
        self.name = 'job'
        self.ensureIndices([([('userId', 1), ('created', 1)], {})])

    def validate(self, job):
        return job

    def createJob(self, title, type, payload, user=None, when=None, interval=0,
                  public=False):
        """
        Create a new job record. This method triggers a jobs.create event that
        job schedulers should listen to in order to schedule the job.

        :param title: The title of the job.
        :type title: str
        :param type: The type of the job.
        :type type: str
        :param payload: The object that will be passed to the job executor.
        :param user: The user creating the job.
        :type user: dict or None
        :param when: Minimum start time for the job (UTC).
        :type when: datetime
        :param interval: If this job should be recurring, set this to a value
        in seconds representing how often it should occur. Set to <= 0 for
        jobs that should only be run once.
        :type interval: int
        :param public: Public read access flag.
        :type public: bool
        """
        if when is None:
            when = datetime.datetime.utcnow()

        job = {
            'title': title,
            'type': type,
            'payload': payload,
            'created': datetime.datetime.utcnow(),
            'when': when,
            'interval': interval,
            'status': JobStatus.INACTIVE
        }

        self.setPublic(job, public=public)

        if user:
            job['userId'] = user['_id']
            self.setUserAccess(job, user=user, level=AccessType.ADMIN)

        job = self.save(job)
        events.trigger('jobs.create', info=job)

        return job<commit_msg>Add progress and log fields to the job model<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

###############################################################################
#  Copyright Kitware Inc.
#
#  Licensed under the Apache License, Version 2.0 ( the "License" );
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
###############################################################################

import datetime

from girder import events
from girder.constants import AccessType
from girder.models.model_base import AccessControlledModel
from .constants import JobStatus


class Job(AccessControlledModel):
    def initialize(self):
        self.name = 'job'
        self.ensureIndices([([('userId', 1), ('created', 1)], {})])

    def validate(self, job):
        return job

    def createJob(self, title, type, payload, user=None, when=None, interval=0,
                  public=False):
        """
        Create a new job record. This method triggers a jobs.create event that
        job schedulers should listen to in order to schedule the job.

        :param title: The title of the job.
        :type title: str
        :param type: The type of the job.
        :type type: str
        :param payload: The object that will be passed to the job executor.
        :param user: The user creating the job.
        :type user: dict or None
        :param when: Minimum start time for the job (UTC).
        :type when: datetime
        :param interval: If this job should be recurring, set this to a value
        in seconds representing how often it should occur. Set to <= 0 for
        jobs that should only be run once.
        :type interval: int
        :param public: Public read access flag.
        :type public: bool
        """
        if when is None:
            when = datetime.datetime.utcnow()

        job = {
            'title': title,
            'type': type,
            'payload': payload,
            'created': datetime.datetime.utcnow(),
            'when': when,
            'interval': interval,
            'status': JobStatus.INACTIVE,
            'progress': None,
            'log': None
        }

        self.setPublic(job, public=public)

        if user:
            job['userId'] = user['_id']
            self.setUserAccess(job, user=user, level=AccessType.ADMIN)

        job = self.save(job)
        events.trigger('jobs.create', info=job)

        return job
{'fraction_non_alphanumeric': 0.14082503556187767, 'fraction_numerical': 0.003200568990042674, 'mean_word_length': 2.52222917971196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3288762', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1426, 'n_words': 583}