JobQueueSecondTestQueue.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /**
  3. * A wrapper for the JobQueue that delegates all the method calls to a single,
  4. * main queue, and also pushes all the jobs to a second job queue that's being
  5. * debugged.
  6. *
  7. * This class was temporary added to test transitioning to the JobQueueEventBus
  8. * and will removed after the transition is completed. This code is only needed
  9. * while we are testing the new infrastructure to be able to compare the results
  10. * between the queue implementations and make sure that they process the same jobs,
  11. * deduplicate correctly, compare the delays, backlogs and make sure no jobs are lost.
  12. * When the new infrastructure is well tested this will not be needed any more.
  13. *
  14. * @deprecated since 1.30
  15. * @since 1.30
  16. */
  17. class JobQueueSecondTestQueue extends JobQueue {
  18. /**
  19. * @var JobQueue
  20. */
  21. private $mainQueue;
  22. /**
  23. * @var JobQueue
  24. */
  25. private $debugQueue;
  26. /**
  27. * @var bool
  28. */
  29. private $onlyWriteToDebugQueue;
  30. protected function __construct( array $params ) {
  31. if ( !isset( $params['mainqueue'] ) ) {
  32. throw new MWException( "mainqueue parameter must be provided to the debug queue" );
  33. }
  34. if ( !isset( $params['debugqueue'] ) ) {
  35. throw new MWException( "debugqueue parameter must be provided to the debug queue" );
  36. }
  37. $conf = [ 'wiki' => $params['wiki'], 'type' => $params['type'] ];
  38. $this->mainQueue = JobQueue::factory( $params['mainqueue'] + $conf );
  39. $this->debugQueue = JobQueue::factory( $params['debugqueue'] + $conf );
  40. $this->onlyWriteToDebugQueue = isset( $params['readonly'] ) ? $params['readonly'] : false;
  41. // We need to construct parent after creating the main and debug queue
  42. // because super constructor calls some methods we delegate to the main queue.
  43. parent::__construct( $params );
  44. }
  45. /**
  46. * Get the allowed queue orders for configuration validation
  47. *
  48. * @return array Subset of (random, timestamp, fifo, undefined)
  49. */
  50. protected function supportedOrders() {
  51. return $this->mainQueue->supportedOrders();
  52. }
  53. /**
  54. * Get the default queue order to use if configuration does not specify one
  55. *
  56. * @return string One of (random, timestamp, fifo, undefined)
  57. */
  58. protected function optimalOrder() {
  59. return $this->mainQueue->optimalOrder();
  60. }
  61. /**
  62. * Find out if delayed jobs are supported for configuration validation
  63. *
  64. * @return bool Whether delayed jobs are supported
  65. */
  66. protected function supportsDelayedJobs() {
  67. return $this->mainQueue->supportsDelayedJobs();
  68. }
  69. /**
  70. * @see JobQueue::isEmpty()
  71. * @return bool
  72. */
  73. protected function doIsEmpty() {
  74. return $this->mainQueue->doIsEmpty();
  75. }
  76. /**
  77. * @see JobQueue::getSize()
  78. * @return int
  79. */
  80. protected function doGetSize() {
  81. return $this->mainQueue->doGetSize();
  82. }
  83. /**
  84. * @see JobQueue::getAcquiredCount()
  85. * @return int
  86. */
  87. protected function doGetAcquiredCount() {
  88. return $this->mainQueue->doGetAcquiredCount();
  89. }
  90. /**
  91. * @see JobQueue::getDelayedCount()
  92. * @return int
  93. */
  94. protected function doGetDelayedCount() {
  95. return $this->mainQueue->doGetDelayedCount();
  96. }
  97. /**
  98. * @see JobQueue::getAbandonedCount()
  99. * @return int
  100. */
  101. protected function doGetAbandonedCount() {
  102. return $this->mainQueue->doGetAbandonedCount();
  103. }
  104. /**
  105. * @see JobQueue::batchPush()
  106. * @param IJobSpecification[] $jobs
  107. * @param int $flags
  108. */
  109. protected function doBatchPush( array $jobs, $flags ) {
  110. if ( !$this->onlyWriteToDebugQueue ) {
  111. $this->mainQueue->doBatchPush( $jobs, $flags );
  112. }
  113. try {
  114. $this->debugQueue->doBatchPush( $jobs, $flags );
  115. } catch ( Exception $exception ) {
  116. MWExceptionHandler::logException( $exception );
  117. }
  118. }
  119. /**
  120. * @see JobQueue::pop()
  121. * @return Job|bool
  122. */
  123. protected function doPop() {
  124. return $this->mainQueue->doPop();
  125. }
  126. /**
  127. * @see JobQueue::ack()
  128. * @param Job $job
  129. * @return Job|bool
  130. */
  131. protected function doAck( Job $job ) {
  132. return $this->mainQueue->doAck( $job );
  133. }
  134. /**
  135. * @see JobQueue::deduplicateRootJob()
  136. * @param IJobSpecification $job
  137. * @throws MWException
  138. * @return bool
  139. */
  140. protected function doDeduplicateRootJob( IJobSpecification $job ) {
  141. return $this->mainQueue->doDeduplicateRootJob( $job );
  142. }
  143. /**
  144. * @see JobQueue::isRootJobOldDuplicate()
  145. * @param Job $job
  146. * @return bool
  147. */
  148. protected function doIsRootJobOldDuplicate( Job $job ) {
  149. return $this->mainQueue->doIsRootJobOldDuplicate( $job );
  150. }
  151. /**
  152. * @param string $signature Hash identifier of the root job
  153. * @return string
  154. */
  155. protected function getRootJobCacheKey( $signature ) {
  156. return $this->mainQueue->getRootJobCacheKey( $signature );
  157. }
  158. /**
  159. * @see JobQueue::delete()
  160. * @return bool
  161. * @throws MWException
  162. */
  163. protected function doDelete() {
  164. return $this->mainQueue->doDelete();
  165. }
  166. /**
  167. * @see JobQueue::waitForBackups()
  168. * @return void
  169. */
  170. protected function doWaitForBackups() {
  171. $this->mainQueue->doWaitForBackups();
  172. }
  173. /**
  174. * @see JobQueue::flushCaches()
  175. * @return void
  176. */
  177. protected function doFlushCaches() {
  178. $this->mainQueue->doFlushCaches();
  179. }
  180. /**
  181. * Get an iterator to traverse over all available jobs in this queue.
  182. * This does not include jobs that are currently acquired or delayed.
  183. * Note: results may be stale if the queue is concurrently modified.
  184. *
  185. * @return Iterator
  186. * @throws JobQueueError
  187. */
  188. public function getAllQueuedJobs() {
  189. return $this->mainQueue->getAllQueuedJobs();
  190. }
  191. /**
  192. * Get an iterator to traverse over all delayed jobs in this queue.
  193. * Note: results may be stale if the queue is concurrently modified.
  194. *
  195. * @return Iterator
  196. * @throws JobQueueError
  197. * @since 1.22
  198. */
  199. public function getAllDelayedJobs() {
  200. return $this->mainQueue->getAllDelayedJobs();
  201. }
  202. /**
  203. * Get an iterator to traverse over all claimed jobs in this queue
  204. *
  205. * Callers should be quick to iterator over it or few results
  206. * will be returned due to jobs being acknowledged and deleted
  207. *
  208. * @return Iterator
  209. * @throws JobQueueError
  210. * @since 1.26
  211. */
  212. public function getAllAcquiredJobs() {
  213. return $this->mainQueue->getAllAcquiredJobs();
  214. }
  215. /**
  216. * Get an iterator to traverse over all abandoned jobs in this queue
  217. *
  218. * @return Iterator
  219. * @throws JobQueueError
  220. * @since 1.25
  221. */
  222. public function getAllAbandonedJobs() {
  223. return $this->mainQueue->getAllAbandonedJobs();
  224. }
  225. /**
  226. * Do not use this function outside of JobQueue/JobQueueGroup
  227. *
  228. * @return string
  229. * @since 1.22
  230. */
  231. public function getCoalesceLocationInternal() {
  232. return $this->mainQueue->getCoalesceLocationInternal();
  233. }
  234. /**
  235. * @see JobQueue::getSiblingQueuesWithJobs()
  236. * @param array $types List of queues types
  237. * @return array|null (list of queue types) or null if unsupported
  238. */
  239. protected function doGetSiblingQueuesWithJobs( array $types ) {
  240. return $this->mainQueue->doGetSiblingQueuesWithJobs( $types );
  241. }
  242. /**
  243. * @see JobQueue::getSiblingQueuesSize()
  244. * @param array $types List of queues types
  245. * @return array|null (list of queue types) or null if unsupported
  246. */
  247. protected function doGetSiblingQueueSizes( array $types ) {
  248. return $this->mainQueue->doGetSiblingQueueSizes( $types );
  249. }
  250. /**
  251. * @throws JobQueueReadOnlyError
  252. */
  253. protected function assertNotReadOnly() {
  254. $this->mainQueue->assertNotReadOnly();
  255. }
  256. }