| 110 | } |
| 111 | |
| 112 | JobExitCode JobQueue::runJob(QueueEntry& entry) { |
| 113 | auto safeJob = [&entry] { |
| 114 | try { |
| 115 | return entry.job(); |
| 116 | } catch (const std::exception& ex) { |
| 117 | XLOGF(ERR, "Exception thrown from the job: {}", ex.what()); |
| 118 | util::printExceptionStackTraces(); |
| 119 | throw; |
| 120 | } catch (...) { |
| 121 | XLOG(ERR, "Unknown exception thrown from the job"); |
| 122 | util::printExceptionStackTraces(); |
| 123 | throw; |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | auto exitCode = safeJob(); |
| 128 | switch (exitCode) { |
| 129 | case JobExitCode::Reschedule: { |
| 130 | entry.rescheduleCount++; |
| 131 | if (entry.rescheduleCount >= kHighRescheduleCount && |
| 132 | entry.rescheduleCount % kHighRescheduleReportRate == 0) { |
| 133 | XLOGF(DBG, |
| 134 | "Job '{}' rescheduled {} times", |
| 135 | entry.name, |
| 136 | entry.rescheduleCount); |
| 137 | } |
| 138 | break; |
| 139 | } |
| 140 | case JobExitCode::Done: { |
| 141 | // Deallocate outside the lock: |
| 142 | entry.job = Job{}; |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | return exitCode; |
| 147 | } |
| 148 | |
| 149 | uint64_t JobQueue::finish() { |
| 150 | // Busy wait, but used only in tests |
nothing calls this directly
no test coverage detected