@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 mdcIsAlsoAvailableDuringLoggingOfJobSuccess() throws Exception {
        // GIVEN
        Job job = anEnqueuedJob().build();
        MDC.put("testKey", "testValue");
        MDCMapper.saveMDCContextToJob(job);

        BackgroundJobRunner runner = mock(BackgroundJobRunner.class);
        when(backgroundJobServer.getBackgroundJobRunner(job)).thenReturn(runner);

        BackgroundJobPerformer backgroundJobPerformer = new BackgroundJobPerformer(backgroundJobServer, job);
        ListAppender logger = LoggerAssert.initFor(backgroundJobPerformer);

        // WHEN
        backgroundJobPerformer.run();

        // THEN
        assertThat(logger)
                .hasDebugMessageContaining(
                        "Job(id=" + job.getId() + ", jobName='" + job.getJobName() + "') processing succeeded",
                        Map.of(
                                "jobrunr.jobId", job.getId().toString(),
                                "jobrunr.jobName", job.getJobName(),
                                "testKey", "testValue"
                        ));

        assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); // backgroundJobPerformer clears MDC Context
    }