1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
use MediaWiki\JobQueue\JobFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\ObjectCache\WANObjectCache;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\Stats\NullStatsdDataFactory;
use Wikimedia\UUID\GlobalIdGenerator;
/**
* @defgroup JobQueue JobQueue
*
*
* See [the architecture doc](@ref jobqueuearch) for more information.
*/
/**
* Base class for queueing and running background jobs from a storage backend.
*
* See [the architecture doc](@ref jobqueuearch) for more information.
*
* @ingroup JobQueue
* @since 1.21
* @stable to extend
*/
abstract class JobQueue {
/** @var string DB domain ID */
protected $domain;
/** @var string Job type */
protected $type;
/** @var string Job priority for pop() */
protected $order;
/** @var int Time to live in seconds */
protected $claimTTL;
/** @var int Maximum number of times to try a job */
protected $maxTries;
/** @var string|false Read only rationale (or false if r/w) */
protected $readOnlyReason;
/** @var StatsdDataFactoryInterface */
protected $stats;
/** @var GlobalIdGenerator */
protected $idGenerator;
/** @var WANObjectCache */
protected $wanCache;
/** @var bool */
protected $typeAgnostic;
private JobFactory $jobFactory;
/* Bit flag for "all-or-nothing" job insertions */
protected const QOS_ATOMIC = 1;
/* Seconds to remember root jobs (28 days) */
protected const ROOTJOB_TTL = 28 * 24 * 3600;
/**
* @stable to call
*
* @param array $params
* - type : A job type, 'default' if typeAgnostic is set
* - domain : A DB domain ID
* - idGenerator : A GlobalIdGenerator instance.
* - wanCache : An instance of WANObjectCache to use for caching [default: none]
* - stats : An instance of StatsdDataFactoryInterface [default: none]
* - claimTTL : Seconds a job can be claimed for exclusive execution [default: forever]
* - maxTries : Total times a job can be tried, assuming claims expire [default: 3]
* - order : Queue order, one of ("fifo", "timestamp", "random") [default: variable]
* - readOnlyReason : Mark the queue as read-only with this reason [default: false]
* - typeAgnostic : If the jobqueue should operate agnostic to the job types
* @throws JobQueueError
*
*/
protected function __construct( array $params ) {
$this->domain = $params['domain'] ?? $params['wiki']; // b/c
$this->type = $params['type'];
$this->claimTTL = $params['claimTTL'] ?? 0;
$this->maxTries = $params['maxTries'] ?? 3;
if ( isset( $params['order'] ) && $params['order'] !== 'any' ) {
$this->order = $params['order'];
} else {
$this->order = $this->optimalOrder();
}
if ( !in_array( $this->order, $this->supportedOrders() ) ) {
throw new JobQueueError( __CLASS__ . " does not support '{$this->order}' order." );
}
$this->readOnlyReason = $params['readOnlyReason'] ?? false;
$this->stats = $params['stats'] ?? new NullStatsdDataFactory();
$this->wanCache = $params['wanCache'] ?? WANObjectCache::newEmpty();
$this->idGenerator = $params['idGenerator'];
if ( ( $params['typeAgnostic'] ?? false ) && !$this->supportsTypeAgnostic() ) {
throw new JobQueueError( __CLASS__ . " does not support type agnostic queues." );
}
$this->typeAgnostic = ( $params['typeAgnostic'] ?? false );
if ( $this->typeAgnostic ) {
$this->type = 'default';
}
$this->jobFactory = MediaWikiServices::getInstance()->getJobFactory();
}
/**
* Get a job queue object of the specified type.
* $params includes:
* - class : What job class to use (determines job type)
* - domain : Database domain ID of the wiki the jobs are for (defaults to current wiki)
* - type : The name of the job types this queue handles
* - order : Order that pop() selects jobs, one of "fifo", "timestamp" or "random".
* If "fifo" is used, the queue will effectively be FIFO. Note that job
* completion will not appear to be exactly FIFO if there are multiple
* job runners since jobs can take different times to finish once popped.
* If "timestamp" is used, the queue will at least be loosely ordered
* by timestamp, allowing for some jobs to be popped off out of order.
* If "random" is used, pop() will pick jobs in random order.
* Note that it may only be weakly random (e.g. a lottery of the oldest X).
* If "any" is chosen, the queue will use whatever order is the fastest.
* This might be useful for improving concurrency for job acquisition.
* - claimTTL : If supported, the queue will recycle jobs that have been popped
* but not acknowledged as completed after this many seconds. Recycling
* of jobs simply means re-inserting them into the queue. Jobs can be
* attempted up to three times before being discarded.
* - readOnlyReason : Set this to a string to make the queue read-only. [optional]
* - idGenerator : A GlobalIdGenerator instance.
* - stats : A StatsdDataFactoryInterface. [optional]
*
* Queue classes should throw an exception if they do not support the options given.
*
* @param array $params
* @return JobQueue
* @throws JobQueueError
*/
final public static function factory( array $params ) {
$class = $params['class'];
if ( !class_exists( $class ) ) {
throw new JobQueueError( "Invalid job queue class '$class'." );
}
$obj = new $class( $params );
if ( !( $obj instanceof self ) ) {
throw new JobQueueError( "Class '$class' is not a " . __CLASS__ . " class." );
}
return $obj;
}
/**
* @return string Database domain ID
*/
final public function getDomain() {
return $this->domain;
}
/**
* @return string Job type that this queue handles
*/
final public function getType() {
return $this->type;
}
/**
* @return string One of (random, timestamp, fifo, undefined)
*/
final public function getOrder() {
return $this->order;
}
/**
* Get the allowed queue orders for configuration validation
*
* @return array Subset of (random, timestamp, fifo, undefined)
*/
abstract protected function supportedOrders();
/**
* Get the default queue order to use if configuration does not specify one
*
* @return string One of (random, timestamp, fifo, undefined)
*/
abstract protected function optimalOrder();
/**
* Find out if delayed jobs are supported for configuration validation
*
* @stable to override
* @return bool Whether delayed jobs are supported
*/
protected function supportsDelayedJobs() {
return false; // not implemented
}
/**
* @return bool Whether delayed jobs are enabled
* @since 1.22
*/
final public function delayedJobsEnabled() {
return $this->supportsDelayedJobs();
}
/**
* @return string|false Read-only rational or false if r/w
* @since 1.27
*/
public function getReadOnlyReason() {
return $this->readOnlyReason;
}
/**
* Quickly check if the queue has no available (unacquired, non-delayed) jobs.
* Queue classes should use caching if they are any slower without memcached.
*
* If caching is used, this might return false when there are actually no jobs.
* If pop() is called and returns false then it should correct the cache. Also,
* calling flushCaches() first prevents this. However, this effect is typically
* not distinguishable from the race condition between isEmpty() and pop().
*
* @return bool
* @throws JobQueueError
*/
final public function isEmpty() {
$res = $this->doIsEmpty();
return $res;
}
/**
* @see JobQueue::isEmpty()
* @return bool
*/
abstract protected function doIsEmpty();
/**
* Get the number of available (unacquired, non-delayed) jobs in the queue.
* Queue classes should use caching if they are any slower without memcached.
*
* If caching is used, this number might be out of date for a minute.
*
* @return int
* @throws JobQueueError
*/
final public function getSize() {
$res = $this->doGetSize();
return $res;
}
/**
* @see JobQueue::getSize()
* @return int
*/
abstract protected function doGetSize();
/**
* Get the number of acquired jobs (these are temporarily out of the queue).
* Queue classes should use caching if they are any slower without memcached.
*
* If caching is used, this number might be out of date for a minute.
*
* @return int
* @throws JobQueueError
*/
final public function getAcquiredCount() {
$res = $this->doGetAcquiredCount();
return $res;
}
/**
* @see JobQueue::getAcquiredCount()
* @return int
*/
abstract protected function doGetAcquiredCount();
/**
* Get the number of delayed jobs (these are temporarily out of the queue).
* Queue classes should use caching if they are any slower without memcached.
*
* If caching is used, this number might be out of date for a minute.
*
* @return int
* @throws JobQueueError
* @since 1.22
*/
final public function getDelayedCount() {
$res = $this->doGetDelayedCount();
return $res;
}
/**
* @stable to override
* @see JobQueue::getDelayedCount()
* @return int
*/
protected function doGetDelayedCount() {
return 0; // not implemented
}
/**
* Get the number of acquired jobs that can no longer be attempted.
* Queue classes should use caching if they are any slower without memcached.
*
* If caching is used, this number might be out of date for a minute.
*
* @return int
* @throws JobQueueError
*/
final public function getAbandonedCount() {
$res = $this->doGetAbandonedCount();
return $res;
}
/**
* @stable to override
* @see JobQueue::getAbandonedCount()
* @return int
*/
protected function doGetAbandonedCount() {
return 0; // not implemented
}
/**
* Push one or more jobs into the queue.
* This does not require $wgJobClasses to be set for the given job type.
* Outside callers should use JobQueueGroup::push() instead of this function.
*
* @param IJobSpecification|IJobSpecification[] $jobs
* @param int $flags Bitfield (supports JobQueue::QOS_ATOMIC)
* @return void
* @throws JobQueueError
*/
final public function push( $jobs, $flags = 0 ) {
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
$this->batchPush( $jobs, $flags );
}
/**
* Push a batch of jobs into the queue.
* This does not require $wgJobClasses to be set for the given job type.
* Outside callers should use JobQueueGroup::push() instead of this function.
*
* @param IJobSpecification[] $jobs
* @param int $flags Bitfield (supports JobQueue::QOS_ATOMIC)
* @return void
* @throws JobQueueError
*/
final public function batchPush( array $jobs, $flags = 0 ) {
$this->assertNotReadOnly();
if ( $jobs === [] ) {
return; // nothing to do
}
foreach ( $jobs as $job ) {
$this->assertMatchingJobType( $job );
if ( $job->getReleaseTimestamp() && !$this->supportsDelayedJobs() ) {
throw new JobQueueError(
"Got delayed '{$job->getType()}' job; delays are not supported." );
}
}
$this->doBatchPush( $jobs, $flags );
foreach ( $jobs as $job ) {
if ( $job->isRootJob() ) {
$this->deduplicateRootJob( $job );
}
}
}
/**
* @see JobQueue::batchPush()
* @param IJobSpecification[] $jobs
* @param int $flags
*/
abstract protected function doBatchPush( array $jobs, $flags );
/**
* Pop a job off of the queue.
* This requires $wgJobClasses to be set for the given job type.
* Outside callers should use JobQueueGroup::pop() instead of this function.
*
* @throws JobQueueError
* @return RunnableJob|false Returns false if there are no jobs
*/
final public function pop() {
$this->assertNotReadOnly();
$job = $this->doPop();
// Flag this job as an old duplicate based on its "root" job...
try {
if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
$this->incrStats( 'dupe_pops', $job->getType() );
$job = DuplicateJob::newFromJob( $job ); // convert to a no-op
}
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// don't lose jobs over this
}
return $job;
}
/**
* @see JobQueue::pop()
* @return RunnableJob|false
*/
abstract protected function doPop();
/**
* Acknowledge that a job was completed.
*
* This does nothing for certain queue classes or if "claimTTL" is not set.
* Outside callers should use JobQueueGroup::ack() instead of this function.
*
* @param RunnableJob $job
* @return void
* @throws JobQueueError
*/
final public function ack( RunnableJob $job ) {
$this->assertNotReadOnly();
$this->assertMatchingJobType( $job );
$this->doAck( $job );
}
/**
* @see JobQueue::ack()
* @param RunnableJob $job
*/
abstract protected function doAck( RunnableJob $job );
/**
* Register the "root job" of a given job into the queue for de-duplication.
* This should only be called right *after* all the new jobs have been inserted.
* This is used to turn older, duplicate, job entries into no-ops. The root job
* information will remain in the registry until it simply falls out of cache.
*
* This requires that $job has two special fields in the "params" array:
* - rootJobSignature : hash (e.g. SHA1) that identifies the task
* - rootJobTimestamp : TS_MW timestamp of this instance of the task
*
* A "root job" is a conceptual job that consist of potentially many smaller jobs
* that are actually inserted into the queue. For example, "refreshLinks" jobs are
* spawned when a template is edited. One can think of the task as "update links
* of pages that use template X" and an instance of that task as a "root job".
* However, what actually goes into the queue are range and leaf job subtypes.
* Since these jobs include things like page ID ranges and DB primary positions,
* and can morph into smaller jobs recursively, simple duplicate detection
* for individual jobs being identical (like that of job_sha1) is not useful.
*
* In the case of "refreshLinks", if these jobs are still in the queue when the template
* is edited again, we want all of these old refreshLinks jobs for that template to become
* no-ops. This can greatly reduce server load, since refreshLinks jobs involves parsing.
* Essentially, the new batch of jobs belong to a new "root job" and the older ones to a
* previous "root job" for the same task of "update links of pages that use template X".
*
* This does nothing for certain queue classes.
*
* @internal For use within JobQueue only
* @param IJobSpecification $job
* @throws JobQueueError
* @return bool
*/
final public function deduplicateRootJob( IJobSpecification $job ) {
$this->assertNotReadOnly();
$this->assertMatchingJobType( $job );
return $this->doDeduplicateRootJob( $job );
}
/**
* @stable to override
* @see JobQueue::deduplicateRootJob()
* @param IJobSpecification $job
* @throws JobQueueError
* @return bool
*/
protected function doDeduplicateRootJob( IJobSpecification $job ) {
$params = $job->hasRootJobParams() ? $job->getRootJobParams() : null;
if ( !$params ) {
throw new JobQueueError( "Cannot register root job; missing parameters." );
}
$key = $this->getRootJobCacheKey( $params['rootJobSignature'], $job->getType() );
// Callers should call JobQueueGroup::push() before this method so that if the
// insert fails, the de-duplication registration will be aborted. Having only the
// de-duplication registration succeed would cause jobs to become no-ops without
// any actual jobs that made them redundant.
$timestamp = $this->wanCache->get( $key ); // last known timestamp of such a root job
if ( $timestamp !== false && $timestamp >= $params['rootJobTimestamp'] ) {
return true; // a newer version of this root job was enqueued
}
// Update the timestamp of the last root job started at the location...
return $this->wanCache->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL );
}
/**
* Check if the "root" job of a given job has been superseded by a newer one
*
* @param IJobSpecification $job
* @throws JobQueueError
* @return bool
*/
final protected function isRootJobOldDuplicate( IJobSpecification $job ) {
$this->assertMatchingJobType( $job );
return $this->doIsRootJobOldDuplicate( $job );
}
/**
* @stable to override
* @see JobQueue::isRootJobOldDuplicate()
* @param IJobSpecification $job
* @return bool
*/
protected function doIsRootJobOldDuplicate( IJobSpecification $job ) {
$params = $job->hasRootJobParams() ? $job->getRootJobParams() : null;
if ( !$params ) {
return false; // job has no de-duplication info
}
$key = $this->getRootJobCacheKey( $params['rootJobSignature'], $job->getType() );
// Get the last time this root job was enqueued
$timestamp = $this->wanCache->get( $key );
if ( $timestamp === false || $params['rootJobTimestamp'] > $timestamp ) {
// Update the timestamp of the last known root job started at the location...
$this->wanCache->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL );
}
// Check if a new root job was started at the location after this one's...
return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
}
/**
* @param string $signature Hash identifier of the root job
* @param string $type job type
* @return string
*/
protected function getRootJobCacheKey( $signature, $type ) {
return $this->wanCache->makeGlobalKey(
'jobqueue',
$this->domain,
$type,
'rootjob',
$signature
);
}
/**
* Delete all unclaimed and delayed jobs from the queue
*
* @throws JobQueueError
* @since 1.22
* @return void
*/
final public function delete() {
$this->assertNotReadOnly();
$this->doDelete();
}
/**
* @stable to override
* @see JobQueue::delete()
* @throws JobQueueError
*/
protected function doDelete() {
throw new JobQueueError( "This method is not implemented." );
}
/**
* Wait for any replica DBs or backup servers to catch up.
*
* This does nothing for certain queue classes.
*
* @return void
* @throws JobQueueError
*/
final public function waitForBackups() {
$this->doWaitForBackups();
}
/**
* @stable to override
* @see JobQueue::waitForBackups()
* @return void
*/
protected function doWaitForBackups() {
}
/**
* Clear any process and persistent caches
*
* @return void
*/
final public function flushCaches() {
$this->doFlushCaches();
}
/**
* @stable to override
* @see JobQueue::flushCaches()
* @return void
*/
protected function doFlushCaches() {
}
/**
* Get an iterator to traverse over all available jobs in this queue.
* This does not include jobs that are currently acquired or delayed.
* Note: results may be stale if the queue is concurrently modified.
*
* @return Iterator<RunnableJob>
* @throws JobQueueError
*/
abstract public function getAllQueuedJobs();
/**
* Get an iterator to traverse over all delayed jobs in this queue.
* Note: results may be stale if the queue is concurrently modified.
*
* @stable to override
* @return Iterator<RunnableJob>
* @throws JobQueueError
* @since 1.22
*/
public function getAllDelayedJobs() {
return new ArrayIterator( [] ); // not implemented
}
/**
* Get an iterator to traverse over all claimed jobs in this queue
*
* Callers should be quick to iterator over it or few results
* will be returned due to jobs being acknowledged and deleted
*
* @stable to override
* @return Iterator<RunnableJob>
* @throws JobQueueError
* @since 1.26
*/
public function getAllAcquiredJobs() {
return new ArrayIterator( [] ); // not implemented
}
/**
* Get an iterator to traverse over all abandoned jobs in this queue
*
* @stable to override
* @return Iterator<RunnableJob>
* @throws JobQueueError
* @since 1.25
*/
public function getAllAbandonedJobs() {
return new ArrayIterator( [] ); // not implemented
}
/**
* Do not use this function outside of JobQueue/JobQueueGroup
*
* @stable to override
* @return string|null
* @since 1.22
*/
public function getCoalesceLocationInternal() {
return null;
}
/**
* Check whether each of the given queues are empty.
* This is used for batching checks for queues stored at the same place.
*
* @param array $types List of queues types
* @return array|null (list of non-empty queue types) or null if unsupported
* @throws JobQueueError
* @since 1.22
*/
final public function getSiblingQueuesWithJobs( array $types ) {
return $this->doGetSiblingQueuesWithJobs( $types );
}
/**
* @stable to override
* @see JobQueue::getSiblingQueuesWithJobs()
* @param array $types List of queues types
* @return array|null (list of queue types) or null if unsupported
*/
protected function doGetSiblingQueuesWithJobs( array $types ) {
return null; // not supported
}
/**
* Check the size of each of the given queues.
* For queues not served by the same store as this one, 0 is returned.
* This is used for batching checks for queues stored at the same place.
*
* @param array $types List of queues types
* @return array|null (job type => whether queue is empty) or null if unsupported
* @throws JobQueueError
* @since 1.22
*/
final public function getSiblingQueueSizes( array $types ) {
return $this->doGetSiblingQueueSizes( $types );
}
/**
* @stable to override
* @see JobQueue::getSiblingQueuesSize()
* @param array $types List of queues types
* @return array|null (list of queue types) or null if unsupported
*/
protected function doGetSiblingQueueSizes( array $types ) {
return null; // not supported
}
/**
* @param string $command
* @param array $params
* @return Job
*/
protected function factoryJob( $command, $params ) {
return $this->jobFactory->newJob( $command, $params );
}
/**
* @throws JobQueueReadOnlyError
*/
protected function assertNotReadOnly() {
if ( $this->readOnlyReason !== false ) {
throw new JobQueueReadOnlyError( "Job queue is read-only: {$this->readOnlyReason}" );
}
}
/**
* @param IJobSpecification $job
* @throws JobQueueError
*/
private function assertMatchingJobType( IJobSpecification $job ) {
if ( $this->typeAgnostic ) {
return;
}
if ( $job->getType() !== $this->type ) {
throw new JobQueueError( "Got '{$job->getType()}' job; expected '{$this->type}'." );
}
}
/**
* Call StatsdDataFactoryInterface::updateCount() for the queue overall and for the queue type
*
* @param string $key Event type
* @param string $type Job type
* @param int $delta
* @since 1.22
*/
protected function incrStats( $key, $type, $delta = 1 ) {
$this->stats->updateCount( "jobqueue.{$key}.all", $delta );
$this->stats->updateCount( "jobqueue.{$key}.{$type}", $delta );
}
/**
* Subclasses should set this to true if they support type agnostic queues
*
* @return bool
* @since 1.38
*/
protected function supportsTypeAgnostic(): bool {
return false;
}
}
|