8e7588ec2663f181a567f0686051a92c7d7454a6
[lhc/web/wiklou.git] / includes / job / JobQueueRedis.php
1 <?php
2 /**
3 * Redis-backed job queue code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Aaron Schulz
22 */
23
24 /**
25 * Class to handle job queues stored in Redis
26 *
27 * @ingroup JobQueue
28 * @since 1.21
29 */
30 class JobQueueRedis extends JobQueue {
31 /** @var RedisConnectionPool */
32 protected $redisPool;
33
34 protected $server; // string; server address
35
36 const ROOTJOB_TTL = 1209600; // integer; seconds to remember root jobs (14 days)
37 const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed (7 days)
38
39 protected $key; // string; key to prefix the queue keys with (used for testing)
40
41 /**
42 * @params include:
43 * - redisConfig : An array of parameters to RedisConnectionPool::__construct().
44 * - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
45 * If a hostname is specified but no port, the standard port number
46 * 6379 will be used. Required.
47 * @param array $params
48 */
49 public function __construct( array $params ) {
50 parent::__construct( $params );
51 $this->server = $params['redisServer'];
52 $this->redisPool = RedisConnectionPool::singleton( $params['redisConfig'] );
53 }
54
55 public function supportedOrders() {
56 return array( 'timestamp', 'fifo' );
57 }
58
59 protected function optimalOrder() {
60 return 'fifo';
61 }
62
63 /**
64 * @see JobQueue::doIsEmpty()
65 * @return bool
66 * @throws MWException
67 */
68 protected function doIsEmpty() {
69 $conn = $this->getConnection();
70 try {
71 return ( $conn->lSize( $this->getQueueKey( 'l-unclaimed' ) ) == 0 );
72 } catch ( RedisException $e ) {
73 $this->throwRedisException( $this->server, $conn, $e );
74 }
75 }
76
77 /**
78 * @see JobQueue::doGetSize()
79 * @return integer
80 * @throws MWException
81 */
82 protected function doGetSize() {
83 $conn = $this->getConnection();
84 try {
85 return $conn->lSize( $this->getQueueKey( 'l-unclaimed' ) );
86 } catch ( RedisException $e ) {
87 $this->throwRedisException( $this->server, $conn, $e );
88 }
89 }
90
91 /**
92 * @see JobQueue::doGetAcquiredCount()
93 * @return integer
94 * @throws MWException
95 */
96 protected function doGetAcquiredCount() {
97 if ( $this->claimTTL <= 0 ) {
98 return 0; // no acknowledgements
99 }
100 $conn = $this->getConnection();
101 try {
102 return $conn->lSize( $this->getQueueKey( 'l-claimed' ) );
103 } catch ( RedisException $e ) {
104 $this->throwRedisException( $this->server, $conn, $e );
105 }
106 }
107
108 /**
109 * @see JobQueue::doBatchPush()
110 * @param array $jobs
111 * @param $flags
112 * @return bool
113 * @throws MWException
114 */
115 protected function doBatchPush( array $jobs, $flags ) {
116 if ( !count( $jobs ) ) {
117 return true;
118 }
119
120 // Convert the jobs into a list of field maps
121 $items = array(); // (uid => job fields map)
122 foreach ( $jobs as $job ) {
123 $item = $this->getNewJobFields( $job );
124 $items[$item['uid']] = $item;
125 }
126
127 $dedupUids = array(); // list of uids to check for duplicates
128 foreach ( $items as $item ) {
129 if ( $this->isHashUid( $item['uid'] ) ) { // hash identifier => de-duplicate
130 $dedupUids[] = $item['uid'];
131 }
132 }
133
134 $conn = $this->getConnection();
135 try {
136 // Find which of these jobs are duplicates of unclaimed jobs in the queue...
137 if ( count( $dedupUids ) ) {
138 $conn->multi( Redis::PIPELINE );
139 foreach ( $dedupUids as $uid ) { // check if job data exists
140 $conn->exists( $this->prefixWithQueueKey( 'data', $uid ) );
141 }
142 if ( $this->claimTTL > 0 ) { // check which jobs were claimed
143 foreach ( $dedupUids as $uid ) {
144 $conn->hExists( $this->prefixWithQueueKey( 'h-meta', $uid ), 'ctime' );
145 }
146 list( $exists, $claimed ) = array_chunk( $conn->exec(), count( $dedupUids ) );
147 } else {
148 $exists = $conn->exec();
149 $claimed = array(); // no claim system
150 }
151 // Remove the duplicate jobs to cut down on pushing duplicate uids...
152 foreach ( $dedupUids as $k => $uid ) {
153 if ( $exists[$k] && empty( $claimed[$k] ) ) {
154 unset( $items[$uid] );
155 }
156 }
157 }
158 // Actually push the non-duplicate jobs into the queue...
159 if ( count( $items ) ) {
160 $uids = array_keys( $items );
161 $conn->multi( Redis::MULTI ); // begin (atomic trx)
162 $conn->mSet( $this->prefixKeysWithQueueKey( 'data', $items ) );
163 call_user_func_array(
164 array( $conn, 'lPush' ),
165 array_merge( array( $this->getQueueKey( 'l-unclaimed' ) ), $uids )
166 );
167 $res = $conn->exec(); // commit (atomic trx)
168 if ( in_array( false, $res, true ) ) {
169 wfDebugLog( 'JobQueueRedis', "Could not insert {$this->type} job(s)." );
170 return false;
171 }
172 }
173 wfIncrStats( 'job-insert', count( $items ) );
174 wfIncrStats( 'job-insert-duplicate', count( $jobs ) - count( $items ) );
175 } catch ( RedisException $e ) {
176 $this->throwRedisException( $this->server, $conn, $e );
177 }
178
179 return true;
180 }
181
182 /**
183 * @see JobQueue::doPop()
184 * @return Job|bool
185 * @throws MWException
186 */
187 protected function doPop() {
188 $job = false;
189
190 if ( $this->claimTTL <= 0 && mt_rand( 0, 99 ) == 0 ) {
191 $this->cleanupClaimedJobs(); // prune jobs and IDs from the "garbage" list
192 }
193
194 $conn = $this->getConnection();
195 try {
196 do {
197 // Atomically pop an item off the queue and onto the "claimed" list
198 $uid = $conn->rpoplpush(
199 $this->getQueueKey( 'l-unclaimed' ),
200 $this->getQueueKey( 'l-claimed' )
201 );
202 if ( $uid === false ) {
203 break; // no jobs; nothing to do
204 }
205
206 wfIncrStats( 'job-pop' );
207 $conn->multi( Redis::PIPELINE );
208 $conn->get( $this->prefixWithQueueKey( 'data', $uid ) );
209 if ( $this->claimTTL > 0 ) {
210 // Set the claim timestamp metadata. If this step fails, then
211 // the timestamp will be assumed to be the current timestamp by
212 // recycleAndDeleteStaleJobs() as of the next time that it runs.
213 // If two runners claim duplicate jobs, one will abort here.
214 $conn->hSetNx( $this->prefixWithQueueKey( 'h-meta', $uid ), 'ctime', time() );
215 } else {
216 // If this fails, the message key will be deleted in cleanupClaimedJobs().
217 // If two runners claim duplicate jobs, one of them will abort here.
218 $conn->delete(
219 $this->prefixWithQueueKey( 'h-meta', $uid ),
220 $this->prefixWithQueueKey( 'data', $uid ) );
221 }
222 list( $item, $ok ) = $conn->exec();
223 if ( $item === false || ( $this->claimTTL && !$ok ) ) {
224 wfDebug( "Could not find or delete job $uid; probably was a duplicate." );
225 continue; // job was probably a duplicate
226 }
227
228 // If $item is invalid, recycleAndDeleteStaleJobs() will cleanup as needed
229 $job = $this->getJobFromFields( $item ); // may be false
230 } while ( !$job ); // job may be false if invalid
231 } catch ( RedisException $e ) {
232 $this->throwRedisException( $this->server, $conn, $e );
233 }
234
235 // Flag this job as an old duplicate based on its "root" job...
236 try {
237 if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
238 wfIncrStats( 'job-pop-duplicate' );
239 return DuplicateJob::newFromJob( $job ); // convert to a no-op
240 }
241 } catch ( MWException $e ) {} // don't lose jobs over this
242
243 return $job;
244 }
245
246 /**
247 * @see JobQueue::doAck()
248 * @param Job $job
249 * @return Job|bool
250 * @throws MWException
251 */
252 protected function doAck( Job $job ) {
253 if ( $this->claimTTL > 0 ) {
254 $conn = $this->getConnection();
255 try {
256 // Get the exact field map this Job came from, regardless of whether
257 // the job was transformed into a DuplicateJob or anything of the sort.
258 $item = $job->metadata['sourceFields'];
259
260 $conn->multi( Redis::MULTI ); // begin (atomic trx)
261 // Remove the first instance of this job scanning right-to-left.
262 // This is O(N) in the worst case, but is likely to be much faster since
263 // jobs are pushed to the left and we are starting from the right, where
264 // the longest running jobs are likely to be. These should be the first
265 // jobs to be acknowledged assuming that job run times are roughly equal.
266 $conn->lRem( $this->getQueueKey( 'l-claimed' ), $item['uid'], -1 );
267 // Delete the job data and its claim metadata
268 $conn->delete(
269 $this->prefixWithQueueKey( 'h-meta', $item['uid'] ),
270 $this->prefixWithQueueKey( 'data', $item['uid'] ) );
271 $res = $conn->exec(); // commit (atomic trx)
272
273 if ( in_array( false, $res, true ) ) {
274 wfDebugLog( 'JobQueueRedis', "Could not acknowledge {$this->type} job." );
275 return false;
276 }
277 } catch ( RedisException $e ) {
278 $this->throwRedisException( $this->server, $conn, $e );
279 }
280 }
281 return true;
282 }
283
284 /**
285 * @see JobQueue::doDeduplicateRootJob()
286 * @param Job $job
287 * @return bool
288 * @throws MWException
289 */
290 protected function doDeduplicateRootJob( Job $job ) {
291 $params = $job->getParams();
292 if ( !isset( $params['rootJobSignature'] ) ) {
293 throw new MWException( "Cannot register root job; missing 'rootJobSignature'." );
294 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
295 throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." );
296 }
297 $key = $this->getRootJobKey( $params['rootJobSignature'] );
298
299 $conn = $this->getConnection();
300 try {
301 $timestamp = $conn->get( $key ); // current last timestamp of this job
302 if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
303 return true; // a newer version of this root job was enqueued
304 }
305 // Update the timestamp of the last root job started at the location...
306 return $conn->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL ); // 2 weeks
307 } catch ( RedisException $e ) {
308 $this->throwRedisException( $this->server, $conn, $e );
309 }
310 }
311
312 /**
313 * Check if the "root" job of a given job has been superseded by a newer one
314 *
315 * @param $job Job
316 * @return bool
317 * @throws MWException
318 */
319 protected function isRootJobOldDuplicate( Job $job ) {
320 $params = $job->getParams();
321 if ( !isset( $params['rootJobSignature'] ) ) {
322 return false; // job has no de-deplication info
323 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
324 wfDebugLog( 'JobQueueRedis', "Cannot check root job; missing 'rootJobTimestamp'." );
325 return false;
326 }
327
328 $conn = $this->getConnection();
329 try {
330 // Get the last time this root job was enqueued
331 $timestamp = $conn->get( $this->getRootJobKey( $params['rootJobSignature'] ) );
332 } catch ( RedisException $e ) {
333 $this->throwRedisException( $this->server, $conn, $e );
334 }
335
336 // Check if a new root job was started at the location after this one's...
337 return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
338 }
339
340 /**
341 * @see JobQueue::getAllQueuedJobs()
342 * @return Iterator
343 */
344 public function getAllQueuedJobs() {
345 $conn = $this->getConnection();
346 if ( !$conn ) {
347 throw new MWException( "Unable to connect to redis server." );
348 }
349 try {
350 $that = $this;
351 return new MappedIterator(
352 $conn->lRange( $this->getQueueKey( 'l-unclaimed' ), 0, -1 ),
353 function( $uid ) use ( $that, $conn ) {
354 return $that->getJobFromUidInternal( $uid, $conn );
355 }
356 );
357 } catch ( RedisException $e ) {
358 $this->throwRedisException( $this->server, $conn, $e );
359 }
360 }
361
362 /**
363 * This function should not be called outside RedisJobQueue
364 *
365 * @param $uid string
366 * @param $conn RedisConnRef
367 * @return Job
368 * @throws MWException
369 */
370 public function getJobFromUidInternal( $uid, RedisConnRef $conn ) {
371 try {
372 $fields = $conn->get( $this->prefixWithQueueKey( 'data', $uid ) );
373 if ( !is_array( $fields ) ) { // wtf?
374 $conn->delete( $this->prefixWithQueueKey( 'data', $uid ) );
375 throw new MWException( "Could not find job with UID '$uid'." );
376 }
377 $title = Title::makeTitle( $fields['namespace'], $fields['title'] );
378 $job = Job::factory( $fields['type'], $title, $fields['params'] );
379 $job->metadata['sourceFields'] = $fields;
380 return $job;
381 } catch ( RedisException $e ) {
382 $this->throwRedisException( $this->server, $conn, $e );
383 }
384 }
385
386 /**
387 * Recycle or destroy any jobs that have been claimed for too long
388 *
389 * @return integer Number of jobs recycled/deleted
390 * @throws MWException
391 */
392 public function recycleAndDeleteStaleJobs() {
393 if ( $this->claimTTL <= 0 ) { // sanity
394 throw new MWException( "Cannot recycle jobs since acknowledgements are disabled." );
395 }
396 $count = 0;
397 // For each job item that can be retried, we need to add it back to the
398 // main queue and remove it from the list of currenty claimed job items.
399 $conn = $this->getConnection();
400 try {
401 // Avoid duplicate insertions of items to be re-enqueued
402 $conn->multi( Redis::MULTI );
403 $conn->setnx( $this->getQueueKey( 'lock' ), 1 );
404 $conn->expire( $this->getQueueKey( 'lock' ), 3600 );
405 if ( $conn->exec() !== array( true, true ) ) { // lock
406 return $count; // already in progress
407 }
408
409 $now = time();
410 $claimCutoff = $now - $this->claimTTL;
411 $pruneCutoff = $now - self::MAX_AGE_PRUNE;
412
413 // Get the list of all claimed jobs
414 $claimedUids = $conn->lRange( $this->getQueueKey( 'l-claimed' ), 0, -1 );
415 // Get a map of (uid => claim metadata) for all claimed jobs
416 $metadata = $conn->mGet( $this->prefixValuesWithQueueKey( 'h-meta', $claimedUids ) );
417
418 $uidsPush = array(); // items IDs to move to the "unclaimed" queue
419 $uidsRemove = array(); // item IDs to remove from "claimed" queue
420 foreach ( $claimedUids as $i => $uid ) { // all claimed items
421 $info = $metadata[$i] ? $metadata[$i] : array();
422 if ( isset( $info['ctime'] ) || isset( $info['rctime'] ) ) {
423 // Prefer "ctime" (set by pop()) over "rctime" (set by this function)
424 $ctime = isset( $info['ctime'] ) ? $info['ctime'] : $info['rctime'];
425 // Claimed job claimed for too long?
426 if ( $ctime < $claimCutoff ) {
427 // Get the number of failed attempts
428 $attempts = isset( $info['attempts'] ) ? $info['attempts'] : 0;
429 if ( $attempts < $this->maxTries ) {
430 $uidsPush[] = $uid; // retry it
431 } elseif ( $ctime < $pruneCutoff ) {
432 $uidsRemove[] = $uid; // just remove it
433 }
434 }
435 } else {
436 // If pop() failed to set the claim timestamp, set it to the current time.
437 // Since that function sets this non-atomically *after* moving the job to
438 // the "claimed" queue, it may be the case that it just didn't set it yet.
439 $conn->hSet( $this->prefixWithQueueKey( 'h-meta', $uid ), 'rctime', $now );
440 }
441 }
442
443 $conn->multi( Redis::MULTI ); // begin (atomic trx)
444 if ( count( $uidsPush ) ) { // move from "l-claimed" to "l-unclaimed"
445 call_user_func_array(
446 array( $conn, 'lPush' ),
447 array_merge( array( $this->getQueueKey( 'l-unclaimed' ) ), $uidsPush )
448 );
449 foreach ( $uidsPush as $uid ) {
450 $conn->lRem( $this->getQueueKey( 'l-claimed' ), $uid, -1 );
451 $conn->hDel( $this->prefixWithQueueKey( 'h-meta', $uid ), 'ctime', 'rctime' );
452 $conn->hIncrBy( $this->prefixWithQueueKey( 'h-meta', $uid ), 'attempts', 1 );
453 }
454 }
455 foreach ( $uidsRemove as $uid ) { // remove from "l-claimed"
456 $conn->lRem( $this->getQueueKey( 'l-claimed' ), $uid, -1 );
457 $conn->delete( // delete job data and metadata
458 $this->prefixWithQueueKey( 'h-meta', $uid ),
459 $this->prefixWithQueueKey( 'data', $uid ) );
460 }
461 $res = $conn->exec(); // commit (atomic trx)
462
463 if ( in_array( false, $res, true ) ) {
464 wfDebugLog( 'JobQueueRedis', "Could not recycle {$this->type} job(s)." );
465 } else {
466 $count += ( count( $uidsPush ) + count( $uidsRemove ) );
467 wfIncrStats( 'job-recycle', count( $uidsPush ) );
468 }
469
470 $conn->delete( $this->getQueueKey( 'lock' ) ); // unlock
471 } catch ( RedisException $e ) {
472 $this->throwRedisException( $this->server, $conn, $e );
473 }
474
475 return $count;
476 }
477
478 /**
479 * Destroy any jobs that have been claimed
480 *
481 * @return integer Number of jobs deleted
482 * @throws MWException
483 */
484 protected function cleanupClaimedJobs() {
485 $count = 0;
486 // Make sure the message for claimed jobs was deleted
487 // and remove the claimed job IDs from the "claimed" list.
488 $conn = $this->getConnection();
489 try {
490 // Avoid races and duplicate effort
491 $conn->multi( Redis::MULTI );
492 $conn->setnx( $this->getQueueKey( 'lock' ), 1 );
493 $conn->expire( $this->getQueueKey( 'lock' ), 3600 );
494 if ( $conn->exec() !== array( true, true ) ) { // lock
495 return $count; // already in progress
496 }
497 // Get the list of all claimed jobs
498 $uids = $conn->lRange( $this->getQueueKey( 'l-claimed' ), 0, -1 );
499 if ( count( $uids ) ) {
500 // Delete the message keys and delist the corresponding ids.
501 // Since the only other changes to "l-claimed" are left pushes, we can just strip
502 // off the elements read here using a right trim based on the number of ids read.
503 $conn->multi( Redis::MULTI ); // begin (atomic trx)
504 $conn->lTrim( $this->getQueueKey( 'l-claimed' ), 0, -count( $uids ) - 1 );
505 $conn->delete( array_merge(
506 $this->prefixValuesWithQueueKey( 'h-meta', $uids ),
507 $this->prefixValuesWithQueueKey( 'data', $uids )
508 ) );
509 $res = $conn->exec(); // commit (atomic trx)
510
511 if ( in_array( false, $res, true ) ) {
512 wfDebugLog( 'JobQueueRedis', "Could not purge {$this->type} job(s)." );
513 } else {
514 $count += count( $uids );
515 }
516 }
517 $conn->delete( $this->getQueueKey( 'lock' ) ); // unlock
518 } catch ( RedisException $e ) {
519 $this->throwRedisException( $this->server, $conn, $e );
520 }
521
522 return $count;
523 }
524
525 /**
526 * @return Array
527 */
528 protected function doGetPeriodicTasks() {
529 if ( $this->claimTTL > 0 ) {
530 return array(
531 'recycleAndDeleteStaleJobs' => array(
532 'callback' => array( $this, 'recycleAndDeleteStaleJobs' ),
533 'period' => ceil( $this->claimTTL / 2 )
534 )
535 );
536 } else {
537 return array();
538 }
539 }
540
541 /**
542 * @param $job Job
543 * @return array
544 */
545 protected function getNewJobFields( Job $job ) {
546 return array(
547 // Fields that describe the nature of the job
548 'type' => $job->getType(),
549 'namespace' => $job->getTitle()->getNamespace(),
550 'title' => $job->getTitle()->getDBkey(),
551 'params' => $job->getParams(),
552 // Additional metadata
553 'uid' => $job->ignoreDuplicates()
554 ? wfBaseConvert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 )
555 : wfRandomString( 32 ),
556 'timestamp' => time() // UNIX timestamp
557 );
558 }
559
560 /**
561 * @param $fields array
562 * @return Job|bool
563 */
564 protected function getJobFromFields( array $fields ) {
565 $title = Title::makeTitleSafe( $fields['namespace'], $fields['title'] );
566 if ( $title ) {
567 $job = Job::factory( $fields['type'], $title, $fields['params'] );
568 $job->metadata['sourceFields'] = $fields;
569 return $job;
570 }
571 return false;
572 }
573
574 /**
575 * @param $uid string Job UID
576 * @return bool Whether $uid is a SHA-1 hash based identifier for de-duplication
577 */
578 protected function isHashUid( $uid ) {
579 return strlen( $uid ) == 31;
580 }
581
582 /**
583 * Get a connection to the server that handles all sub-queues for this queue
584 *
585 * @return Array (server name, Redis instance)
586 * @throws MWException
587 */
588 protected function getConnection() {
589 $conn = $this->redisPool->getConnection( $this->server );
590 if ( !$conn ) {
591 throw new MWException( "Unable to connect to redis server." );
592 }
593 return $conn;
594 }
595
596 /**
597 * @param $server string
598 * @param $conn RedisConnRef
599 * @param $e RedisException
600 * @throws MWException
601 */
602 protected function throwRedisException( $server, RedisConnRef $conn, $e ) {
603 $this->redisPool->handleException( $server, $conn, $e );
604 throw new MWException( "Redis server error: {$e->getMessage()}\n" );
605 }
606
607 /**
608 * @param $prop string
609 * @return string
610 */
611 private function getQueueKey( $prop ) {
612 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
613 if ( strlen( $this->key ) ) { // namespaced queue (for testing)
614 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $this->key, $prop );
615 } else {
616 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $prop );
617 }
618 }
619
620 /**
621 * @param string $signature Hash identifier of the root job
622 * @return string
623 */
624 private function getRootJobKey( $signature ) {
625 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
626 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
627 }
628
629 /**
630 * @param $prop string
631 * @param $string string
632 * @return string
633 */
634 private function prefixWithQueueKey( $prop, $string ) {
635 return $this->getQueueKey( $prop ) . ':' . $string;
636 }
637
638 /**
639 * @param $prop string
640 * @param $items array
641 * @return Array
642 */
643 private function prefixValuesWithQueueKey( $prop, array $items ) {
644 $res = array();
645 foreach ( $items as $item ) {
646 $res[] = $this->prefixWithQueueKey( $prop, $item );
647 }
648 return $res;
649 }
650
651 /**
652 * @param $prop string
653 * @param $items array
654 * @return Array
655 */
656 private function prefixKeysWithQueueKey( $prop, array $items ) {
657 $res = array();
658 foreach ( $items as $key => $item ) {
659 $res[$this->prefixWithQueueKey( $prop, $key )] = $item;
660 }
661 return $res;
662 }
663
664 /**
665 * @param $key string
666 * @return void
667 */
668 public function setTestingPrefix( $key ) {
669 $this->key = $key;
670 }
671 }