def _expect_create_task_calls(self, task_manager, job_doc):
        from flamenco.job_compilers import commands

        task_manager.api_create_task.assert_has_calls([
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-1-13',
                status='under-construction',
                task_type='sleep',
            ),
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-14-26',
                status='under-construction',
                task_type='sleep',
            ),
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-27-30,40-44',
                status='under-construction',
                task_type='sleep',
            ),
        ])
    def test_to_dict(self):
        from flamenco.job_compilers import commands

        cmd = commands.Echo(message='Preparing to sleep')
        self.assertEqual({
            'name': 'echo',
            'settings': {
                'message': 'Preparing to sleep',
            }
        }, cmd.to_dict())
Exemple #3
0
    def test_api_find_jobfinal_tasks(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.job_compilers import commands

        manager, _, _ = self.create_manager_service_account()

        with self.app.test_request_context():
            force_cli_user()
            job_doc = self.jmngr.api_create_job(
                'test job',
                'Wörk wørk w°rk.',
                'sleep',
                {
                    'frames': '12-18, 20-22',
                    'chunk_size': 7,
                    'time_in_seconds': 3,
                },
                self.proj_id,
                ctd.EXAMPLE_PROJECT_OWNER_ID,
                manager['_id'],
            )
            job_id = job_doc['_id']

            # Find the tasks created so far, use them as parents.
            tasks = self.flamenco.db('tasks').find({'job': job_id},
                                                   projection={'_id': 1})
            task_ids = [t['_id'] for t in tasks]

            # dependent task that is used as a single parent.
            taskid1 = self.tmngr.api_create_task(
                job_doc,
                [commands.Echo(message='ẑžƶźz')],
                'zzz 1',
                parents=task_ids,
                task_type='sleep',
            )

            # task dependent on multiple tasks that is not used as a parent.
            taskid2 = self.tmngr.api_create_task(
                job_doc,
                [commands.Echo(message='ẑžƶźz')],
                'zzz 2',
                parents=task_ids,
                task_type='sleep',
            )

            # task dependent on a single task that is not used as a parent.
            taskid3 = self.tmngr.api_create_task(
                job_doc,
                [commands.Echo(message='ẑžƶźz')],
                'zzz 3',
                parents=[taskid1],
                task_type='sleep',
            )

            # independent task
            taskid4 = self.tmngr.api_create_task(
                job_doc,
                [commands.Echo(message='ẑžƶźz')],
                'zzz 4',
                task_type='sleep',
            )

            job_enders = self.tmngr.api_find_job_enders(job_id)
            self.assertEqual({taskid2, taskid3, taskid4}, set(job_enders))
Exemple #4
0
    def test_job_compilation(self, mock_datetime):
        from flamenco.job_compilers import sleep, commands

        job_doc = {
            '_id': ObjectId(24 * 'f'),
            'settings': {
                'frames': '1-30, 40-44',
                'chunk_size': 13,
                'time_in_seconds': 3,
            }
        }
        task_manager = mock.Mock()
        job_manager = mock.Mock()

        # Create a stable 'now' for testing.
        mock_now = datetime.datetime.now(tz=tz_util.utc)
        mock_datetime.now.side_effect = [mock_now]

        compiler = sleep.Sleep(task_manager=task_manager,
                               job_manager=job_manager)
        compiler.compile(job_doc)

        task_manager.api_create_task.assert_has_calls([
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-1-13',
                status='under-construction',
                task_type='sleep',
            ),
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-14-26',
                status='under-construction',
                task_type='sleep',
            ),
            mock.call(
                job_doc,
                [
                    commands.Echo(message='Preparing to sleep'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-27-30,40-44',
                status='under-construction',
                task_type='sleep',
            ),
        ])

        # Both calls should be performed with the same 'now'.
        task_manager.api_set_task_status_for_job.assert_called_with(
            job_doc['_id'], 'under-construction', 'queued', now=mock_now)
        job_manager.api_set_job_status(job_doc['_id'],
                                       'under-construction',
                                       'queued',
                                       now=mock_now)
Exemple #5
0
    def test_create_task(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.job_compilers import commands

        manager, _, _ = self.create_manager_service_account()

        with self.app.test_request_context():
            force_cli_user()
            job_doc = self.jmngr.api_create_job(
                'test job',
                'Wörk wørk w°rk.',
                'sleep',
                {
                    'frames': '12-18, 20-22',
                    'chunk_size': 7,
                    'time_in_seconds': 3,
                },
                self.proj_id,
                ctd.EXAMPLE_PROJECT_OWNER_ID,
                manager['_id'],
            )

            self.tmngr.api_create_task(
                job_doc,
                [
                    commands.Echo(message='ẑžƶźz'),
                    commands.Sleep(time_in_seconds=3),
                ],
                'sleep-1-13',
                status='under-construction',
                task_type='exr-merge',
            )

        # Now test the database contents.
        with self.app.test_request_context():
            tasks_coll = self.flamenco.db('tasks')
            dbtasks = list(tasks_coll.find())
            self.assertEqual(
                3, len(dbtasks))  # 2 of compiled job + the one we added after.

            statuses = [task['status'] for task in dbtasks]
            self.assertEqual(['queued', 'queued', 'under-construction'],
                             statuses)

            types = [task['task_type'] for task in dbtasks]
            self.assertEqual(['sleep', 'sleep', 'exr-merge'], types)

            dbtask = dbtasks[-1]

            self.assertEqual(
                {
                    'name': 'echo',
                    'settings': {
                        'message': 'ẑžƶźz',
                    }
                }, dbtask['commands'][0])

            self.assertEqual(
                {
                    'name': 'sleep',
                    'settings': {
                        'time_in_seconds': 3,
                    }
                }, dbtask['commands'][1])

        return job_doc['_id']