コード例 #1
0
    def test_insert(self):
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version

        task = Task(state=WorkState.DONE,
                    priority=404,
                    frame=1,
                    last_error="foobar",
                    job=job)
        db.session.add(task)
        db.session.commit()
        task_id = task.id
        db.session.remove()
        searched = Task.query.filter_by(id=task_id).first()
        self.assertIsNotNone(searched)
        self.assertEqual(searched.state, WorkState.DONE)
        self.assertEqual(searched.priority, 404)
        self.assertEqual(searched.attempts, 0)
        self.assertEqual(searched.frame, 1)
コード例 #2
0
ファイル: job.py プロジェクト: xlhtc007/pyfarm-master
    def alter_frame_range(self, start, end, by):
        # We have to import this down here instead of at the top to break a
        # circular dependency between the modules
        from pyfarm.scheduler.tasks import delete_task

        if end < start:
            raise ValueError("`end` must be greater than or equal to `start`")

        self.by = by

        required_frames = []
        current_frame = start
        while current_frame <= end:
            required_frames.append(current_frame)
            current_frame += by

        existing_tasks = Task.query.filter_by(job=self).all()
        frames_to_create = required_frames
        num_created = 0
        for task in existing_tasks:
            if task.frame not in required_frames:
                delete_task.delay(task.id)
            else:
                frames_to_create.remove(task.frame)

        for frame in frames_to_create:
            if self.num_tiles:
                for tile in range_(self.num_tiles - 1):
                    num_created += 1
                    task = Task()
                    task.job = self
                    task.frame = frame
                    task.tile = tile
                    task.priority = self.priority
                    db.session.add(task)
            else:
                num_created += 1
                task = Task()
                task.job = self
                task.frame = frame
                task.priority = self.priority
                db.session.add(task)

        if frames_to_create:
            if self.state != WorkState.RUNNING:
                self.state = None

        if config.get("enable_statistics"):
            task_event_count = TaskEventCount(num_new=num_created, job_queue_id=self.job_queue_id)
            task_event_count.time_start = datetime.utcnow()
            task_event_count.time_end = datetime.utcnow()
            db.session.add(task_event_count)
コード例 #3
0
    def create_queue_with_job(self, name, jobtype_version):
        queue = JobQueue(name=name)
        job = Job(title="Test Job %s" % name,
                  jobtype_version=jobtype_version,
                  queue=queue)

        for i in range(0, 100):
            task = Task(job=job, frame=i)
            db.session.add(task)
        db.session.add(job)
        db.session.flush()

        return queue
コード例 #4
0
    def test_clear_last_error(self):
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version

        task = Task(frame=1, job=job, last_error="foobar")
        db.session.add(task)
        db.session.commit()
        db.session.add(task)
        task.state = WorkState.DONE
        self.assertIsNone(task.last_error)
コード例 #5
0
    def test_clear_last_error(self):
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version

        task = Task(frame=1, job=job, last_error="foobar")
        db.session.add(task)
        db.session.commit()
        db.session.add(task)
        task.state = WorkState.DONE
        self.assertIsNone(task.last_error)
コード例 #6
0
    def alter_frame_range(self, start, end, by):
        # We have to import this down here instead of at the top to break a
        # circular dependency between the modules
        from pyfarm.scheduler.tasks import delete_task

        if end < start:
            raise ValueError("`end` must be greater than or equal to `start`")

        self.by = by

        required_frames = []
        current_frame = start
        while current_frame <= end:
            required_frames.append(current_frame)
            current_frame += by

        existing_tasks = Task.query.filter_by(job=self).all()
        frames_to_create = required_frames
        num_created = 0
        for task in existing_tasks:
            if task.frame not in required_frames:
                delete_task.delay(task.id)
            else:
                frames_to_create.remove(task.frame)

        for frame in frames_to_create:
            if self.num_tiles:
                for tile in range_(self.num_tiles - 1):
                    num_created += 1
                    task = Task()
                    task.job = self
                    task.frame = frame
                    task.tile = tile
                    task.priority = self.priority
                    db.session.add(task)
            else:
                num_created += 1
                task = Task()
                task.job = self
                task.frame = frame
                task.priority = self.priority
                db.session.add(task)

        if frames_to_create:
            if self.state != WorkState.RUNNING:
                self.state = None

        if config.get("enable_statistics"):
            task_event_count = TaskEventCount(num_new=num_created,
                                              job_queue_id=self.job_queue_id)
            task_event_count.time_start = datetime.utcnow()
            task_event_count.time_end = datetime.utcnow()
            db.session.add(task_event_count)