Example #1
0
    def api_recreate_job(self, job_id: bson.ObjectId):
        """Deletes all tasks of a job, then recompiles the job to construct new tasks.

        The job MUST be in state 'canceled', to ensure that the manager has stopped task execution.

        As this functionality requires access to both the task manager and the job manager,
        this is implemented on FlamencoExtension itself.
        """

        from flamenco import job_compilers
        from flamenco.jobs import RECREATABLE_JOB_STATES

        jobs_coll = current_flamenco.db('jobs')
        job_doc = jobs_coll.find_one({'_id': job_id})
        if not job_doc:
            raise ValueError('Job ID %s not found', job_id)

        if job_doc['status'] not in RECREATABLE_JOB_STATES:
            raise ValueError(
                'Job recreation is only possible on jobs in state %s.',
                ', '.join(RECREATABLE_JOB_STATES))

        # Delete the tasks and revert the job to 'under-construction' status before recompiling it.
        self._log.info('Recreating job %s', job_id)
        self.job_manager.api_set_job_status(job_id, 'under-construction')
        self.task_manager.api_delete_tasks_for_job(job_id)
        job_compilers.compile_job(job_doc)
        self._log.info('Recreated job %s', job_id)
Example #2
0
    def api_construct_job(self,
                          job_id: ObjectId,
                          new_job_settings: typing.Optional[typing.Dict[str, typing.Any]]=None,
                          *, reason: str):
        """Construct the tasks for a job."""

        jobs_coll = current_flamenco.db('jobs')
        job = jobs_coll.find_one({'_id': job_id})
        if not job:
            raise ValueError(f'Job {job_id} does not exist')

        if new_job_settings:
            self._log.info('Updating settings for job %s: %s', job_id, new_job_settings)
            job_settings = job.setdefault('settings', {})
            job_settings.update(new_job_settings)
            result = jobs_coll.update_one({'_id': job_id}, {'$set': {'settings': job_settings}})
            if result.matched_count != 1:
                raise ValueError(f'Could not find job {job_id} for updating new settings')

        self.api_set_job_status(job_id, 'under-construction', reason=reason)
        self._log.info('Generating tasks for job %s', job_id)

        try:
            job_compilers.compile_job(job)
        except Exception as ex:
            self._log.exception('Compiling job %s failed', job_id)
            current_flamenco.job_manager.api_set_job_status(
                job_id, 'construction-failed', reason=f'{reason}; compilation failed: {ex}')
Example #3
0
def after_inserting_jobs(jobs):
    from flamenco import job_compilers, current_flamenco

    for job in jobs:
        job_id = job['_id']
        # Prepare storage dir for the job files?
        # Generate tasks
        log.info(f'Generating tasks for job {job_id}')
        job_compilers.compile_job(job)
Example #4
0
    def api_construct_job(
            self,
            job_id: ObjectId,
            new_job_settings: typing.Optional[typing.Dict[str,
                                                          typing.Any]] = None,
            *,
            reason: str):
        """Construct the tasks for a job."""

        jobs_coll = current_flamenco.db('jobs')
        job = jobs_coll.find_one({'_id': job_id})
        if not job:
            raise ValueError(f'Job {job_id} does not exist')

        if new_job_settings:
            self._log.info('Updating settings for job %s: %s', job_id,
                           new_job_settings)
            job_settings = job.setdefault('settings', {})
            job_settings.update(new_job_settings)
            result = jobs_coll.update_one({'_id': job_id},
                                          {'$set': {
                                              'settings': job_settings
                                          }})
            if result.matched_count != 1:
                raise ValueError(
                    f'Could not find job {job_id} for updating new settings')

        self.api_set_job_status(job_id, 'under-construction', reason=reason)
        self._log.info('Generating tasks for job %s', job_id)

        try:
            job_compilers.compile_job(job)
        except Exception as ex:
            self._log.exception('Compiling job %s failed', job_id)
            current_flamenco.job_manager.api_set_job_status(
                job_id,
                'construction-failed',
                reason=f'{reason}; compilation failed: {ex}')
Example #5
0
    def api_recreate_job(self, job_id: bson.ObjectId):
        """Delete all tasks of a job, then recompile the job.

        The job state MUST be in RECREATABLE_JOB_STATES, to ensure that the
        manager has stopped task execution.

        As this functionality requires access to both the task manager and the
        job manager, this is implemented on FlamencoExtension itself.
        """

        from flamenco import job_compilers
        from flamenco.jobs import RECREATABLE_JOB_STATES

        jobs_coll = current_flamenco.db('jobs')
        job_doc = jobs_coll.find_one({'_id': job_id})
        if not job_doc:
            raise ValueError('Job ID %s not found', job_id)

        if job_doc['status'] not in RECREATABLE_JOB_STATES:
            raise ValueError('Job recreation is only possible on jobs in state %s.' %
                             ', '.join(RECREATABLE_JOB_STATES))

        # Delete the tasks and revert the job to 'under-construction' status before recompiling it.
        self._log.info('Recreating job %s', job_id)
        self.job_manager.api_set_job_status(
            job_id, 'under-construction',
            reason=f'Recreated by {current_user.full_name} (@{current_user.username})')
        self.task_manager.api_delete_tasks_for_job(job_id)

        try:
            job_compilers.compile_job(job_doc)
        except Exception as ex:
            self._log.exception('Recreating job %s failed', job_id)
            self.job_manager.api_set_job_status(job_id, 'construction-failed')
            raise ValueError('Job recreation failed: %s' % ex)
        else:
            self._log.info('Recreated job %s', job_id)