def delete()

in src/lambdas/r8s_api_handler/processors/job_processor.py [0:0]


    def delete(self, event):
        _LOG.debug(f'Terminate job event: {event}')
        validate_params(event, (ID_ATTR,))

        user = event.get(PARAM_USER_ID)

        applications = self.application_service.resolve_application(
            event=event
        )
        if not applications:
            _LOG.error(f'No suitable applications found matching user.')
            return build_response(
                code=RESPONSE_BAD_REQUEST_CODE,
                content=f'No suitable applications found matching user.'
            )

        job_id = event.get(ID_ATTR)
        _LOG.debug(f'Describing job by id \'{job_id}\'')
        job: Job = self.job_service.get_by_id(object_id=job_id)

        user_customer = event.get(PARAM_USER_CUSTOMER)
        user_id = event.get(USER_ID_ATTR)

        application_ids = [app.application_id for app in applications]
        if user_customer != 'admin' and job.parent_id \
                not in application_ids:
            _LOG.warning(f'User \'{user_id}\' is not authorize to affect '
                         f'application jobs \'{job.parent_id}\'')
            return build_response(
                code=RESPONSE_FORBIDDEN_CODE,
                content=f'User \'{user_id}\' is not authorize to affect '
                        f'application jobs \'{job.parent_id}\''
            )

        if not job:
            _LOG.debug(f'Job with id \'{job_id}\' does not exist')
            return build_response(
                code=RESPONSE_RESOURCE_NOT_FOUND_CODE,
                content=f'Job with id \'{job_id}\' does not exist'
            )

        if job.status in (JobStatusEnum.JOB_SUCCEEDED_STATUS,
                          JobStatusEnum.JOB_FAILED_STATUS):
            _LOG.error('Wrong job status, exiting')
            return build_response(
                code=RESPONSE_BAD_REQUEST_CODE,
                content='Can not terminate job with status '
                        'SUCCEEDED or FAILED'
            )

        job.status = JobStatusEnum.JOB_FAILED_STATUS
        job.fail_reason = f'Terminated by user \'{user}\''

        _LOG.debug(f'Terminating Batch job')
        self.job_service.terminate_job(
            job_id=job_id,
            reason=job.fail_reason)
        _LOG.debug(f'Saving job')
        self.job_service.save(job=job)

        return build_response(
            code=RESPONSE_OK_CODE,
            content=f'The job with id \'{job_id}\' will be terminated')