示例#1
0
    def job_complete_core(self, session):
        """
        Checks if job is complete 

        TODO Notifications upon completion

        Status changes of job

        """
        # for now we assume the stat here to be accurate.

        if self.stat_count_tasks - self.stat_count_complete != 0:
            return

            # WIP
        if self.type == "Exam":
            # not implemented
            pass

        session.add(self)  # TODO dont add to session like this
        self.status = "complete"
        Event.new_deferred(
            session=session,
            kind='task_template_completed',
            project_id=self.project_id,
            member_id=get_member(session).id if get_member(session) else None,
            job_id=self.id,
            wait_for_commit=True)
示例#2
0
    def new(session,
            job,
            file_id,
            guide_id,
            label_dict,
            file_original_id,
            kind='human',
            task_type='draw',
            incoming_directory=None,
            flush_session=True):
        task = Task()
        session.add(task)

        task.is_live = job.is_live

        # # #
        task.job_id = job.id
        task.file_id = file_id
        task.guide_id = guide_id
        task.label_dict = label_dict
        task.file_original_id = file_original_id
        task.completion_directory_id = job.completion_directory_id
        # For now both created and updated times should be the same.
        task.time_created = datetime.datetime.utcnow()
        task.time_updated = datetime.datetime.utcnow()
        if incoming_directory:
            task.incoming_directory_id = incoming_directory.id

        if task_type == 'draw':
            # Set draw tasks to be available instead of
            # default of created
            task.status = 'available'

        # Cache from job
        task.project_id = job.project_id
        task.job_type = job.type
        task.label_mode = job.label_mode
        if flush_session:
            session.flush()
        # Have defaults
        task.kind = kind
        task.task_type = task_type
        
        if job.stat_count_tasks is None:
            job.stat_count_tasks = 1
        else:
            job.stat_count_tasks += 1

        Event.new_deferred(
            session=session,
            kind='task_created',
            project_id=task.project_id,
            task_id=task.id,
            wait_for_commit=True
        )
        session.add(job)
        return task