@Override
    public void run() {
        try {
            backgroundJobServer.getJobSteward().notifyThreadOccupied();
            MDCMapper.loadMDCContextFromJob(job);
            performJob();
        } catch (Exception e) {
            if (isJobDeletedWhileProcessing(e)) {
                // nothing to do anymore as Job is deleted
                return;
            } else if (isJobServerStopped(e)) {
                updateJobStateToFailedAndRunJobFilters("Job processing was stopped as background job server has stopped", e);
                Thread.currentThread().interrupt();
            } else if (isJobNotFoundException(e)) {
                updateJobStateToFailedAndRunJobFilters("Job method not found", e);
            } else {
                updateJobStateToFailedAndRunJobFilters("An exception occurred during the performance of the job", e);
            }
        } finally {
            backgroundJobServer.getJobSteward().notifyThreadIdle();
            MDC.clear();
        }
    }
@Test
    void onSuccessIllegalJobStateChangeIsThrown() throws Exception {
        Job job = anEnqueuedJob().build();

        mockBackgroundJobRunner(job, jobFromStorage -> jobFromStorage.failed("boe", new Exception()));

        BackgroundJobPerformer backgroundJobPerformer = new BackgroundJobPerformer(backgroundJobServer, job);
        assertThatThrownBy(() -> backgroundJobPerformer.run())
                .isInstanceOf(IllegalJobStateChangeException.class);
    }