Merge "Remove Preprocessor_HipHop"
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
1 <?php
2 /**
3 * Database-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 the DB
26 *
27 * @ingroup JobQueue
28 * @since 1.21
29 */
30 class JobQueueDB extends JobQueue {
31 const ROOTJOB_TTL = 1209600; // integer; seconds to remember root jobs (14 days)
32 const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
33 const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
34 const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed
35 const MAX_JOB_RANDOM = 2147483647; // integer; 2^31 - 1, used for job_random
36 const MAX_OFFSET = 255; // integer; maximum number of rows to skip
37
38 protected $cluster = false; // string; name of an external DB cluster
39
40 /**
41 * Additional parameters include:
42 * - cluster : The name of an external cluster registered via LBFactory.
43 * If not specified, the primary DB cluster for the wiki will be used.
44 * This can be overridden with a custom cluster so that DB handles will
45 * be retrieved via LBFactory::getExternalLB() and getConnection().
46 * @param $params array
47 */
48 protected function __construct( array $params ) {
49 parent::__construct( $params );
50 $this->cluster = isset( $params['cluster'] ) ? $params['cluster'] : false;
51 }
52
53 /**
54 * @see JobQueue::doIsEmpty()
55 * @return bool
56 */
57 protected function doIsEmpty() {
58 global $wgMemc;
59
60 $key = $this->getCacheKey( 'empty' );
61
62 $isEmpty = $wgMemc->get( $key );
63 if ( $isEmpty === 'true' ) {
64 return true;
65 } elseif ( $isEmpty === 'false' ) {
66 return false;
67 }
68
69 list( $dbr, $scope ) = $this->getSlaveDB();
70 $found = $dbr->selectField( // unclaimed job
71 'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
72 );
73 $wgMemc->add( $key, $found ? 'false' : 'true', self::CACHE_TTL_LONG );
74
75 return !$found;
76 }
77
78 /**
79 * @see JobQueue::doGetSize()
80 * @return integer
81 */
82 protected function doGetSize() {
83 global $wgMemc;
84
85 $key = $this->getCacheKey( 'size' );
86
87 $size = $wgMemc->get( $key );
88 if ( is_int( $size ) ) {
89 return $size;
90 }
91
92 list( $dbr, $scope ) = $this->getSlaveDB();
93 $size = (int)$dbr->selectField( 'job', 'COUNT(*)',
94 array( 'job_cmd' => $this->type, 'job_token' => '' ),
95 __METHOD__
96 );
97 $wgMemc->set( $key, $size, self::CACHE_TTL_SHORT );
98
99 return $size;
100 }
101
102 /**
103 * @see JobQueue::doGetAcquiredCount()
104 * @return integer
105 */
106 protected function doGetAcquiredCount() {
107 global $wgMemc;
108
109 $key = $this->getCacheKey( 'acquiredcount' );
110
111 $count = $wgMemc->get( $key );
112 if ( is_int( $count ) ) {
113 return $count;
114 }
115
116 list( $dbr, $scope ) = $this->getSlaveDB();
117 $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
118 array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ),
119 __METHOD__
120 );
121 $wgMemc->set( $key, $count, self::CACHE_TTL_SHORT );
122
123 return $count;
124 }
125
126 /**
127 * @see JobQueue::doBatchPush()
128 * @param array $jobs
129 * @param $flags
130 * @throws DBError|Exception
131 * @return bool
132 */
133 protected function doBatchPush( array $jobs, $flags ) {
134 if ( count( $jobs ) ) {
135 list( $dbw, $scope ) = $this->getMasterDB();
136
137 $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated
138 $rowList = array(); // list of jobs for jobs that are are not de-duplicated
139
140 foreach ( $jobs as $job ) {
141 $row = $this->insertFields( $job );
142 if ( $job->ignoreDuplicates() ) {
143 $rowSet[$row['job_sha1']] = $row;
144 } else {
145 $rowList[] = $row;
146 }
147 }
148
149 $atomic = ( $flags & self::QoS_Atomic );
150 $key = $this->getCacheKey( 'empty' );
151 $ttl = self::CACHE_TTL_LONG;
152
153 $dbw->onTransactionIdle(
154 function() use ( $dbw, $rowSet, $rowList, $atomic, $key, $ttl, $scope
155 ) {
156 global $wgMemc;
157
158 if ( $atomic ) {
159 $dbw->begin( __METHOD__ ); // wrap all the job additions in one transaction
160 }
161 try {
162 // Strip out any duplicate jobs that are already in the queue...
163 if ( count( $rowSet ) ) {
164 $res = $dbw->select( 'job', 'job_sha1',
165 array(
166 // No job_type condition since it's part of the job_sha1 hash
167 'job_sha1' => array_keys( $rowSet ),
168 'job_token' => '' // unclaimed
169 ),
170 __METHOD__
171 );
172 foreach ( $res as $row ) {
173 wfDebug( "Job with hash '{$row->job_sha1}' is a duplicate." );
174 unset( $rowSet[$row->job_sha1] ); // already enqueued
175 }
176 }
177 // Build the full list of job rows to insert
178 $rows = array_merge( $rowList, array_values( $rowSet ) );
179 // Insert the job rows in chunks to avoid slave lag...
180 foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
181 $dbw->insert( 'job', $rowBatch, __METHOD__ );
182 }
183 wfIncrStats( 'job-insert', count( $rows ) );
184 wfIncrStats( 'job-insert-duplicate',
185 count( $rowSet ) + count( $rowList ) - count( $rows ) );
186 } catch ( DBError $e ) {
187 if ( $atomic ) {
188 $dbw->rollback( __METHOD__ );
189 }
190 throw $e;
191 }
192 if ( $atomic ) {
193 $dbw->commit( __METHOD__ );
194 }
195
196 $wgMemc->set( $key, 'false', $ttl ); // queue is not empty
197 } );
198 }
199
200 return true;
201 }
202
203 /**
204 * @see JobQueue::doPop()
205 * @return Job|bool
206 */
207 protected function doPop() {
208 global $wgMemc;
209
210 if ( $wgMemc->get( $this->getCacheKey( 'empty' ) ) === 'true' ) {
211 return false; // queue is empty
212 }
213
214 list( $dbw, $scope ) = $this->getMasterDB();
215 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
216
217 $uuid = wfRandomString( 32 ); // pop attempt
218 $job = false; // job popped off
219 do { // retry when our row is invalid or deleted as a duplicate
220 // Try to reserve a row in the DB...
221 if ( in_array( $this->order, array( 'fifo', 'timestamp' ) ) ) {
222 $row = $this->claimOldest( $uuid );
223 } else { // random first
224 $rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
225 $gte = (bool)mt_rand( 0, 1 ); // find rows with rand before/after $rand
226 $row = $this->claimRandom( $uuid, $rand, $gte );
227 }
228 // Check if we found a row to reserve...
229 if ( !$row ) {
230 $wgMemc->set( $this->getCacheKey( 'empty' ), 'true', self::CACHE_TTL_LONG );
231 break; // nothing to do
232 }
233 wfIncrStats( 'job-pop' );
234 // Get the job object from the row...
235 $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
236 if ( !$title ) {
237 $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
238 wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
239 continue; // try again
240 }
241 $job = Job::factory( $row->job_cmd, $title,
242 self::extractBlob( $row->job_params ), $row->job_id );
243 $job->id = $row->job_id; // XXX: work around broken subclasses
244 // Flag this job as an old duplicate based on its "root" job...
245 if ( $this->isRootJobOldDuplicate( $job ) ) {
246 wfIncrStats( 'job-pop-duplicate' );
247 $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
248 }
249 break; // done
250 } while( true );
251
252 return $job;
253 }
254
255 /**
256 * Reserve a row with a single UPDATE without holding row locks over RTTs...
257 *
258 * @param $uuid string 32 char hex string
259 * @param $rand integer Random unsigned integer (31 bits)
260 * @param $gte bool Search for job_random >= $random (otherwise job_random <= $random)
261 * @return Row|false
262 */
263 protected function claimRandom( $uuid, $rand, $gte ) {
264 global $wgMemc;
265
266 list( $dbw, $scope ) = $this->getMasterDB();
267 // Check cache to see if the queue has <= OFFSET items
268 $tinyQueue = $wgMemc->get( $this->getCacheKey( 'small' ) );
269
270 $row = false; // the row acquired
271 $invertedDirection = false; // whether one job_random direction was already scanned
272 // This uses a replication safe method for acquiring jobs. One could use UPDATE+LIMIT
273 // instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is
274 // not replication safe. Due to http://bugs.mysql.com/bug.php?id=6980, subqueries cannot
275 // be used here with MySQL.
276 do {
277 if ( $tinyQueue ) { // queue has <= MAX_OFFSET rows
278 // For small queues, using OFFSET will overshoot and return no rows more often.
279 // Instead, this uses job_random to pick a row (possibly checking both directions).
280 $ineq = $gte ? '>=' : '<=';
281 $dir = $gte ? 'ASC' : 'DESC';
282 $row = $dbw->selectRow( 'job', '*', // find a random job
283 array(
284 'job_cmd' => $this->type,
285 'job_token' => '', // unclaimed
286 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
287 __METHOD__,
288 array( 'ORDER BY' => "job_random {$dir}" )
289 );
290 if ( !$row && !$invertedDirection ) {
291 $gte = !$gte;
292 $invertedDirection = true;
293 continue; // try the other direction
294 }
295 } else { // table *may* have >= MAX_OFFSET rows
296 // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
297 // in MySQL if there are many rows for some reason. This uses a small OFFSET
298 // instead of job_random for reducing excess claim retries.
299 $row = $dbw->selectRow( 'job', '*', // find a random job
300 array(
301 'job_cmd' => $this->type,
302 'job_token' => '', // unclaimed
303 ),
304 __METHOD__,
305 array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
306 );
307 if ( !$row ) {
308 $tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
309 $wgMemc->set( $this->getCacheKey( 'small' ), 1, 30 );
310 continue; // use job_random
311 }
312 }
313 if ( $row ) { // claim the job
314 $dbw->update( 'job', // update by PK
315 array(
316 'job_token' => $uuid,
317 'job_token_timestamp' => $dbw->timestamp(),
318 'job_attempts = job_attempts+1' ),
319 array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
320 __METHOD__
321 );
322 // This might get raced out by another runner when claiming the previously
323 // selected row. The use of job_random should minimize this problem, however.
324 if ( !$dbw->affectedRows() ) {
325 $row = false; // raced out
326 }
327 } else {
328 break; // nothing to do
329 }
330 } while ( !$row );
331
332 return $row;
333 }
334
335 /**
336 * Reserve a row with a single UPDATE without holding row locks over RTTs...
337 *
338 * @param $uuid string 32 char hex string
339 * @return Row|false
340 */
341 protected function claimOldest( $uuid ) {
342 list( $dbw, $scope ) = $this->getMasterDB();
343
344 $row = false; // the row acquired
345 do {
346 if ( $dbw->getType() === 'mysql' ) {
347 // Per http://bugs.mysql.com/bug.php?id=6980, we can't use subqueries on the
348 // same table being changed in an UPDATE query in MySQL (gives Error: 1093).
349 // Oracle and Postgre have no such limitation. However, MySQL offers an
350 // alternative here by supporting ORDER BY + LIMIT for UPDATE queries.
351 $dbw->query( "UPDATE {$dbw->tableName( 'job' )} " .
352 "SET " .
353 "job_token = {$dbw->addQuotes( $uuid ) }, " .
354 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
355 "job_attempts = job_attempts+1 " .
356 "WHERE ( " .
357 "job_cmd = {$dbw->addQuotes( $this->type )} " .
358 "AND job_token = {$dbw->addQuotes( '' )} " .
359 ") ORDER BY job_id ASC LIMIT 1",
360 __METHOD__
361 );
362 } else {
363 // Use a subquery to find the job, within an UPDATE to claim it.
364 // This uses as much of the DB wrapper functions as possible.
365 $dbw->update( 'job',
366 array(
367 'job_token' => $uuid,
368 'job_token_timestamp' => $dbw->timestamp(),
369 'job_attempts = job_attempts+1' ),
370 array( 'job_id = (' .
371 $dbw->selectSQLText( 'job', 'job_id',
372 array( 'job_cmd' => $this->type, 'job_token' => '' ),
373 __METHOD__,
374 array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ) ) .
375 ')'
376 ),
377 __METHOD__
378 );
379 }
380 // Fetch any row that we just reserved...
381 if ( $dbw->affectedRows() ) {
382 $row = $dbw->selectRow( 'job', '*',
383 array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
384 );
385 if ( !$row ) { // raced out by duplicate job removal
386 wfDebugLog( 'JobQueueDB', "Row deleted as duplicate by another process." );
387 }
388 } else {
389 break; // nothing to do
390 }
391 } while ( !$row );
392
393 return $row;
394 }
395
396 /**
397 * Recycle or destroy any jobs that have been claimed for too long
398 *
399 * @return integer Number of jobs recycled/deleted
400 */
401 public function recycleAndDeleteStaleJobs() {
402 global $wgMemc;
403
404 $now = time();
405 list( $dbw, $scope ) = $this->getMasterDB();
406 $count = 0; // affected rows
407
408 if ( !$dbw->lock( "jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
409 return $count; // already in progress
410 }
411
412 // Remove claims on jobs acquired for too long if enabled...
413 if ( $this->claimTTL > 0 ) {
414 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
415 // Get the IDs of jobs that have be claimed but not finished after too long.
416 // These jobs can be recycled into the queue by expiring the claim. Selecting
417 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
418 $res = $dbw->select( 'job', 'job_id',
419 array(
420 'job_cmd' => $this->type,
421 "job_token != {$dbw->addQuotes( '' )}", // was acquired
422 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
423 "job_attempts < {$dbw->addQuotes( self::MAX_ATTEMPTS )}" ), // retries left
424 __METHOD__
425 );
426 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
427 if ( count( $ids ) ) {
428 // Reset job_token for these jobs so that other runners will pick them up.
429 // Set the timestamp to the current time, as it is useful to now that the job
430 // was already tried before (the timestamp becomes the "released" time).
431 $dbw->update( 'job',
432 array(
433 'job_token' => '',
434 'job_token_timestamp' => $dbw->timestamp( $now ) ), // time of release
435 array(
436 'job_id' => $ids ),
437 __METHOD__
438 );
439 $count += $dbw->affectedRows();
440 wfIncrStats( 'job-recycle', $dbw->affectedRows() );
441 $wgMemc->set( $this->getCacheKey( 'empty' ), 'false', self::CACHE_TTL_LONG );
442 }
443 }
444
445 // Just destroy any stale jobs...
446 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
447 $conds = array(
448 'job_cmd' => $this->type,
449 "job_token != {$dbw->addQuotes( '' )}", // was acquired
450 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
451 );
452 if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
453 $conds[] = "job_attempts >= {$dbw->addQuotes( self::MAX_ATTEMPTS )}";
454 }
455 // Get the IDs of jobs that are considered stale and should be removed. Selecting
456 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
457 $res = $dbw->select( 'job', 'job_id', $conds, __METHOD__ );
458 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
459 if ( count( $ids ) ) {
460 $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
461 $count += $dbw->affectedRows();
462 }
463
464 $dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
465
466 return $count;
467 }
468
469 /**
470 * @see JobQueue::doAck()
471 * @param Job $job
472 * @throws MWException
473 * @return Job|bool
474 */
475 protected function doAck( Job $job ) {
476 if ( !$job->getId() ) {
477 throw new MWException( "Job of type '{$job->getType()}' has no ID." );
478 }
479
480 list( $dbw, $scope ) = $this->getMasterDB();
481 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
482
483 // Delete a row with a single DELETE without holding row locks over RTTs...
484 $dbw->delete( 'job',
485 array( 'job_cmd' => $this->type, 'job_id' => $job->getId() ), __METHOD__ );
486
487 return true;
488 }
489
490 /**
491 * @see JobQueue::doDeduplicateRootJob()
492 * @param Job $job
493 * @throws MWException
494 * @return bool
495 */
496 protected function doDeduplicateRootJob( Job $job ) {
497 $params = $job->getParams();
498 if ( !isset( $params['rootJobSignature'] ) ) {
499 throw new MWException( "Cannot register root job; missing 'rootJobSignature'." );
500 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
501 throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." );
502 }
503 $key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
504 // Callers should call batchInsert() and then this function so that if the insert
505 // fails, the de-duplication registration will be aborted. Since the insert is
506 // deferred till "transaction idle", do the same here, so that the ordering is
507 // maintained. Having only the de-duplication registration succeed would cause
508 // jobs to become no-ops without any actual jobs that made them redundant.
509 list( $dbw, $scope ) = $this->getMasterDB();
510 $dbw->onTransactionIdle( function() use ( $params, $key, $scope ) {
511 global $wgMemc;
512
513 $timestamp = $wgMemc->get( $key ); // current last timestamp of this job
514 if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
515 return true; // a newer version of this root job was enqueued
516 }
517
518 // Update the timestamp of the last root job started at the location...
519 return $wgMemc->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL );
520 } );
521
522 return true;
523 }
524
525 /**
526 * Check if the "root" job of a given job has been superseded by a newer one
527 *
528 * @param $job Job
529 * @return bool
530 */
531 protected function isRootJobOldDuplicate( Job $job ) {
532 global $wgMemc;
533
534 $params = $job->getParams();
535 if ( !isset( $params['rootJobSignature'] ) ) {
536 return false; // job has no de-deplication info
537 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
538 trigger_error( "Cannot check root job; missing 'rootJobTimestamp'." );
539 return false;
540 }
541
542 // Get the last time this root job was enqueued
543 $timestamp = $wgMemc->get( $this->getRootJobCacheKey( $params['rootJobSignature'] ) );
544
545 // Check if a new root job was started at the location after this one's...
546 return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
547 }
548
549 /**
550 * @see JobQueue::doWaitForBackups()
551 * @return void
552 */
553 protected function doWaitForBackups() {
554 wfWaitForSlaves();
555 }
556
557 /**
558 * @return Array
559 */
560 protected function doGetPeriodicTasks() {
561 return array(
562 'recycleAndDeleteStaleJobs' => array(
563 'callback' => array( $this, 'recycleAndDeleteStaleJobs' ),
564 'period' => ceil( $this->claimTTL / 2 )
565 )
566 );
567 }
568
569 /**
570 * @return Array (DatabaseBase, ScopedCallback)
571 */
572 protected function getSlaveDB() {
573 return $this->getDB( DB_SLAVE );
574 }
575
576 /**
577 * @return Array (DatabaseBase, ScopedCallback)
578 */
579 protected function getMasterDB() {
580 return $this->getDB( DB_MASTER );
581 }
582
583 /**
584 * @param $index integer (DB_SLAVE/DB_MASTER)
585 * @return Array (DatabaseBase, ScopedCallback)
586 */
587 protected function getDB( $index ) {
588 $lb = ( $this->cluster !== false )
589 ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
590 : wfGetLB( $this->wiki );
591 $conn = $lb->getConnection( $index, array(), $this->wiki );
592 return array(
593 $conn,
594 new ScopedCallback( function() use ( $lb, $conn ) {
595 $lb->reuseConnection( $conn );
596 } )
597 );
598 }
599
600 /**
601 * @param $job Job
602 * @return array
603 */
604 protected function insertFields( Job $job ) {
605 list( $dbw, $scope ) = $this->getMasterDB();
606 return array(
607 // Fields that describe the nature of the job
608 'job_cmd' => $job->getType(),
609 'job_namespace' => $job->getTitle()->getNamespace(),
610 'job_title' => $job->getTitle()->getDBkey(),
611 'job_params' => self::makeBlob( $job->getParams() ),
612 // Additional job metadata
613 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
614 'job_timestamp' => $dbw->timestamp(),
615 'job_sha1' => wfBaseConvert(
616 sha1( serialize( $job->getDeduplicationInfo() ) ),
617 16, 36, 31
618 ),
619 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
620 );
621 }
622
623 /**
624 * @return string
625 */
626 private function getCacheKey( $property ) {
627 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
628 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property );
629 }
630
631 /**
632 * @param string $signature Hash identifier of the root job
633 * @return string
634 */
635 private function getRootJobCacheKey( $signature ) {
636 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
637 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
638 }
639
640 /**
641 * @param $params
642 * @return string
643 */
644 protected static function makeBlob( $params ) {
645 if ( $params !== false ) {
646 return serialize( $params );
647 } else {
648 return '';
649 }
650 }
651
652 /**
653 * @param $blob
654 * @return bool|mixed
655 */
656 protected static function extractBlob( $blob ) {
657 if ( (string)$blob !== '' ) {
658 return unserialize( $blob );
659 } else {
660 return false;
661 }
662 }
663 }