2006-02-24 01:56:31 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2014-01-27 21:28:47 +00:00
|
|
|
* Job queue task base code.
|
2012-05-04 06:29:11 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2010-09-03 18:24:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @defgroup JobQueue JobQueue
|
|
|
|
|
*/
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
2007-04-21 12:33:41 +00:00
|
|
|
* Class to both describe a background job and handle jobs.
|
2018-05-20 12:10:20 +00:00
|
|
|
* To push jobs onto queues, use JobQueueGroup::singleton()->push();
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2020-11-18 03:08:01 +00:00
|
|
|
* Job objects are constructed by the job queue, and must have an approriate
|
|
|
|
|
* constructor signature; see IJobSpecification.
|
|
|
|
|
*
|
2020-07-13 09:00:30 +00:00
|
|
|
* @stable to extend
|
2020-03-12 11:13:22 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup JobQueue
|
2007-04-04 05:22:37 +00:00
|
|
|
*/
|
2019-03-30 06:07:48 +00:00
|
|
|
abstract class Job implements RunnableJob {
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var string */
|
|
|
|
|
public $command;
|
2011-02-19 21:56:54 +00:00
|
|
|
|
2015-05-21 18:02:35 +00:00
|
|
|
/** @var array Array of job parameters */
|
2013-11-25 15:32:17 +00:00
|
|
|
public $params;
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var array Additional queue metadata */
|
2016-02-17 09:09:32 +00:00
|
|
|
public $metadata = [];
|
2012-12-12 00:04:03 +00:00
|
|
|
|
2013-11-25 15:32:17 +00:00
|
|
|
/** @var Title */
|
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
|
|
/** @var bool Expensive jobs may set this to true */
|
2019-03-29 20:15:58 +00:00
|
|
|
protected $removeDuplicates = false;
|
2013-11-25 15:32:17 +00:00
|
|
|
|
|
|
|
|
/** @var string Text for error that occurred last */
|
|
|
|
|
protected $error;
|
|
|
|
|
|
2016-02-17 03:25:24 +00:00
|
|
|
/** @var callable[] */
|
|
|
|
|
protected $teardownCallbacks = [];
|
|
|
|
|
|
2018-04-16 20:38:01 +00:00
|
|
|
/** @var int Bitfield of JOB_* class constants */
|
|
|
|
|
protected $executionFlags = 0;
|
|
|
|
|
|
2007-04-21 12:33:41 +00:00
|
|
|
/**
|
2007-06-21 19:11:24 +00:00
|
|
|
* Create the appropriate object to handle a specific job
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $command Job command
|
2019-04-05 00:09:30 +00:00
|
|
|
* @param array|Title $params Job parameters
|
2019-01-30 19:40:46 +00:00
|
|
|
* @throws InvalidArgumentException
|
2007-06-21 19:11:24 +00:00
|
|
|
* @return Job
|
2006-06-18 12:42:16 +00:00
|
|
|
*/
|
2019-03-29 20:15:58 +00:00
|
|
|
public static function factory( $command, $params = [] ) {
|
2007-06-21 19:11:24 +00:00
|
|
|
global $wgJobClasses;
|
2015-10-23 18:48:50 +00:00
|
|
|
|
2019-03-29 20:15:58 +00:00
|
|
|
if ( $params instanceof Title ) {
|
|
|
|
|
// Backwards compatibility for old signature ($command, $title, $params)
|
|
|
|
|
$title = $params;
|
|
|
|
|
$params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
} elseif ( isset( $params['namespace'] ) && isset( $params['title'] ) ) {
|
|
|
|
|
// Handle job classes that take title as constructor parameter.
|
|
|
|
|
// If a newer classes like GenericParameterJob uses these parameters,
|
|
|
|
|
// then this happens in Job::__construct instead.
|
|
|
|
|
$title = Title::makeTitle( $params['namespace'], $params['title'] );
|
2019-03-29 20:15:58 +00:00
|
|
|
} else {
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
// Default title for job classes not implementing GenericParameterJob.
|
|
|
|
|
// This must be a valid title because it not directly passed to
|
|
|
|
|
// our Job constructor, but rather it's subclasses which may expect
|
|
|
|
|
// to be able to use it.
|
|
|
|
|
$title = Title::makeTitle( NS_SPECIAL, 'Blankpage' );
|
2019-03-29 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( isset( $wgJobClasses[$command] ) ) {
|
2017-05-04 16:00:28 +00:00
|
|
|
$handler = $wgJobClasses[$command];
|
|
|
|
|
|
|
|
|
|
if ( is_callable( $handler ) ) {
|
|
|
|
|
$job = call_user_func( $handler, $title, $params );
|
|
|
|
|
} elseif ( class_exists( $handler ) ) {
|
2019-03-30 06:07:48 +00:00
|
|
|
if ( is_subclass_of( $handler, GenericParameterJob::class ) ) {
|
|
|
|
|
$job = new $handler( $params );
|
|
|
|
|
} else {
|
|
|
|
|
$job = new $handler( $title, $params );
|
|
|
|
|
}
|
2017-05-04 16:00:28 +00:00
|
|
|
} else {
|
|
|
|
|
$job = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $job instanceof Job ) {
|
|
|
|
|
$job->command = $command;
|
2019-03-29 20:15:58 +00:00
|
|
|
|
2017-05-04 16:00:28 +00:00
|
|
|
return $job;
|
|
|
|
|
} else {
|
2019-05-26 12:22:45 +00:00
|
|
|
throw new InvalidArgumentException(
|
|
|
|
|
"Could not instantiate job '$command': bad spec!"
|
|
|
|
|
);
|
2017-05-04 16:00:28 +00:00
|
|
|
}
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2015-10-23 18:48:50 +00:00
|
|
|
|
|
|
|
|
throw new InvalidArgumentException( "Invalid job command '{$command}'" );
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-09-22 18:31:57 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2020-03-12 11:13:22 +00:00
|
|
|
*
|
2014-09-22 18:31:57 +00:00
|
|
|
* @param string $command
|
2019-04-05 00:09:30 +00:00
|
|
|
* @param array|Title|null $params
|
2014-09-22 18:31:57 +00:00
|
|
|
*/
|
2019-04-05 00:09:30 +00:00
|
|
|
public function __construct( $command, $params = null ) {
|
2019-03-29 20:15:58 +00:00
|
|
|
if ( $params instanceof Title ) {
|
|
|
|
|
// Backwards compatibility for old signature ($command, $title, $params)
|
|
|
|
|
$title = $params;
|
2019-03-30 06:07:48 +00:00
|
|
|
$params = func_num_args() >= 3 ? func_get_arg( 2 ) : [];
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
} else {
|
|
|
|
|
// Newer jobs may choose to not have a top-level title (e.g. GenericParameterJob)
|
|
|
|
|
$title = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_array( $params ) ) {
|
|
|
|
|
throw new InvalidArgumentException( '$params must be an array' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
$title &&
|
|
|
|
|
!isset( $params['namespace'] ) &&
|
|
|
|
|
!isset( $params['title'] )
|
|
|
|
|
) {
|
|
|
|
|
// When constructing this class for submitting to the queue,
|
|
|
|
|
// normalise the $title arg of old job classes as part of $params.
|
|
|
|
|
$params['namespace'] = $title->getNamespace();
|
2019-08-31 20:59:45 +00:00
|
|
|
$params['title'] = $title->getDBkey();
|
2019-03-29 20:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-22 18:31:57 +00:00
|
|
|
$this->command = $command;
|
2019-03-30 06:07:48 +00:00
|
|
|
$this->params = $params + [ 'requestId' => WebRequest::getRequestId() ];
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
|
2019-03-30 06:07:48 +00:00
|
|
|
if ( $this->title === null ) {
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
// Set this field for access via getTitle().
|
2019-03-30 06:07:48 +00:00
|
|
|
$this->title = ( isset( $params['namespace'] ) && isset( $params['title'] ) )
|
|
|
|
|
? Title::makeTitle( $params['namespace'], $params['title'] )
|
jobqueue: Follow-up for fc5d51f12936ed (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.
* In Job::factory(), restore use of a valid title as default for passing as
constructor arg to old job classes. Their constructor may expect it to
be valid.
Keep the invalid dummy in Job::__construct, and document why.
* tests: Update test case for failure mode when using Job::factory
with a class that requires a title. It asserted getting an invalid
title. This now restores the behaviour prior to fc5d51f12936ed,
which is that job classes that require a title, get a valid one.
* tests: Remove test case for testToString that used
an explicitly passed but invalid params value. I've converted
that to expect the exception we now throw instead.
* tests: Update getMockJob(), also used by testToString, which was
relying on undocumented behaviour that 'new Title' is public
and gets namespace=0 and title=''. Before fc5d51f12936ed,
title params weren't in toString() and it asserted outputting
three spaces (delimiter, empty string from formatted title,
delimiter).
In fc5d51f12936ed, this changed to asserting "Special:" which
seems unintentional as we didn't pass it the internally reserved
NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
Given this test case doesn't deal with titles, omit it for now.
A job can either have a $title and title/namespace in params,
or neither. This test was asserting an in-memory scenario
where $title can be an object, but title/namespace absent from
params.
Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-18 15:29:41 +00:00
|
|
|
// GenericParameterJob classes without namespace/title params
|
|
|
|
|
// should not use getTitle(). Set an invalid title as placeholder.
|
2019-03-30 06:07:48 +00:00
|
|
|
: Title::makeTitle( NS_SPECIAL, '' );
|
2016-04-11 21:00:43 +00:00
|
|
|
}
|
2014-09-22 18:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2018-04-16 20:38:01 +00:00
|
|
|
public function hasExecutionFlag( $flag ) {
|
2019-03-29 01:54:29 +00:00
|
|
|
return ( $this->executionFlags & $flag ) === $flag;
|
2018-04-16 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
2020-03-12 11:13:22 +00:00
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
public function getType() {
|
|
|
|
|
return $this->command;
|
|
|
|
|
}
|
2007-04-21 12:33:41 +00:00
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2019-03-30 06:07:48 +00:00
|
|
|
final public function getTitle() {
|
2012-08-29 00:01:31 +00:00
|
|
|
return $this->title;
|
2006-02-24 01:56:31 +00:00
|
|
|
}
|
2007-04-21 12:33:41 +00:00
|
|
|
|
2011-10-26 04:15:09 +00:00
|
|
|
/**
|
2020-03-12 11:13:22 +00:00
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2011-10-26 04:15:09 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function getParams() {
|
|
|
|
|
return $this->params;
|
2006-05-31 23:56:41 +00:00
|
|
|
}
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2019-03-30 15:05:31 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2019-03-30 15:05:31 +00:00
|
|
|
* @param string|null $field Metadata field or null to get all the metadata
|
|
|
|
|
* @return mixed|null Value; null if missing
|
|
|
|
|
* @since 1.33
|
|
|
|
|
*/
|
|
|
|
|
public function getMetadata( $field = null ) {
|
|
|
|
|
if ( $field === null ) {
|
|
|
|
|
return $this->metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->metadata[$field] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2019-03-30 15:05:31 +00:00
|
|
|
* @param string $field Key name to set the value for
|
|
|
|
|
* @param mixed $value The value to set the field for
|
|
|
|
|
* @return mixed|null The prior field value; null if missing
|
|
|
|
|
* @since 1.33
|
|
|
|
|
*/
|
|
|
|
|
public function setMetadata( $field, $value ) {
|
|
|
|
|
$old = $this->getMetadata( $field );
|
|
|
|
|
if ( $value === null ) {
|
|
|
|
|
unset( $this->metadata[$field] );
|
|
|
|
|
} else {
|
|
|
|
|
$this->metadata[$field] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $old;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 03:40:01 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int|null UNIX timestamp to delay running this job until, otherwise null
|
2013-03-12 03:40:01 +00:00
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
public function getReleaseTimestamp() {
|
|
|
|
|
return isset( $this->params['jobReleaseTimestamp'] )
|
|
|
|
|
? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 19:20:38 +00:00
|
|
|
/**
|
|
|
|
|
* @return int|null UNIX timestamp of when the job was queued, or null
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
public function getQueuedTimestamp() {
|
|
|
|
|
return isset( $this->metadata['timestamp'] )
|
|
|
|
|
? wfTimestampOrNull( TS_UNIX, $this->metadata['timestamp'] )
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2016-04-11 21:00:43 +00:00
|
|
|
public function getRequestId() {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->params['requestId'] ?? null;
|
2016-04-11 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2015-07-01 19:30:06 +00:00
|
|
|
public function getReadyTimestamp() {
|
|
|
|
|
return $this->getReleaseTimestamp() ?: $this->getQueuedTimestamp();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 11:39:23 +00:00
|
|
|
/**
|
2015-01-16 23:28:38 +00:00
|
|
|
* Whether the queue should reject insertion of this job if a duplicate exists
|
|
|
|
|
*
|
|
|
|
|
* This can be used to avoid duplicated effort or combined with delayed jobs to
|
|
|
|
|
* coalesce updates into larger batches. Claimed jobs are never treated as
|
|
|
|
|
* duplicates of new jobs, and some queues may allow a few duplicates due to
|
|
|
|
|
* network partitions and fail-over. Thus, additional locking is needed to
|
|
|
|
|
* enforce mutual exclusion if this is really needed.
|
|
|
|
|
*
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*
|
2015-01-16 23:28:38 +00:00
|
|
|
* @return bool
|
2011-03-10 11:39:23 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function ignoreDuplicates() {
|
|
|
|
|
return $this->removeDuplicates;
|
|
|
|
|
}
|
2011-03-10 11:39:23 +00:00
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2013-02-20 00:56:47 +00:00
|
|
|
public function allowRetries() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2013-12-21 20:57:45 +00:00
|
|
|
public function workItemCount() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
/**
|
2013-04-03 20:51:02 +00:00
|
|
|
* Subclasses may need to override this to make duplication detection work.
|
|
|
|
|
* The resulting map conveys everything that makes the job unique. This is
|
|
|
|
|
* only checked if ignoreDuplicates() returns true, meaning that duplicate
|
|
|
|
|
* jobs are supposed to be ignored.
|
2012-11-08 22:01:40 +00:00
|
|
|
*
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return array Map of key/values
|
2013-04-03 20:13:36 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public function getDeduplicationInfo() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
2013-04-20 17:18:13 +00:00
|
|
|
'type' => $this->getType(),
|
|
|
|
|
'params' => $this->getParams()
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
if ( is_array( $info['params'] ) ) {
|
2013-03-27 21:26:47 +00:00
|
|
|
// Identical jobs with different "root" jobs should count as duplicates
|
2012-11-08 22:01:40 +00:00
|
|
|
unset( $info['params']['rootJobSignature'] );
|
|
|
|
|
unset( $info['params']['rootJobTimestamp'] );
|
2013-03-27 21:26:47 +00:00
|
|
|
// Likewise for jobs with different delay times
|
|
|
|
|
unset( $info['params']['jobReleaseTimestamp'] );
|
2016-04-11 21:00:43 +00:00
|
|
|
// Identical jobs from different requests should count as duplicates
|
|
|
|
|
unset( $info['params']['requestId'] );
|
2015-03-19 17:45:39 +00:00
|
|
|
// Queues pack and hash this array, so normalize the order
|
|
|
|
|
ksort( $info['params'] );
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-05-23 17:53:12 +00:00
|
|
|
* Get "root job" parameters for a task
|
|
|
|
|
*
|
|
|
|
|
* This is used to no-op redundant jobs, including child jobs of jobs,
|
|
|
|
|
* as long as the children inherit the root job parameters. When a job
|
|
|
|
|
* with root job parameters and "rootJobIsSelf" set is pushed, the
|
|
|
|
|
* deduplicateRootJob() method is automatically called on it. If the
|
|
|
|
|
* root job is only virtual and not actually pushed (e.g. the sub-jobs
|
|
|
|
|
* are inserted directly), then call deduplicateRootJob() directly.
|
|
|
|
|
*
|
2013-04-03 20:51:02 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
2015-05-23 17:53:12 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $key A key that identifies the task
|
2013-11-28 06:43:00 +00:00
|
|
|
* @return array Map of:
|
2015-05-23 17:53:12 +00:00
|
|
|
* - rootJobIsSelf : true
|
2013-11-28 06:43:00 +00:00
|
|
|
* - rootJobSignature : hash (e.g. SHA1) that identifies the task
|
|
|
|
|
* - rootJobTimestamp : TS_MW timestamp of this instance of the task
|
2013-04-03 20:13:36 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public static function newRootJobParams( $key ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2015-05-23 17:53:12 +00:00
|
|
|
'rootJobIsSelf' => true,
|
2012-11-08 22:01:40 +00:00
|
|
|
'rootJobSignature' => sha1( $key ),
|
|
|
|
|
'rootJobTimestamp' => wfTimestampNow()
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2013-04-03 20:51:02 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return array
|
2013-04-03 20:51:02 +00:00
|
|
|
* @since 1.21
|
2012-11-08 22:01:40 +00:00
|
|
|
*/
|
|
|
|
|
public function getRootJobParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2017-10-06 22:17:58 +00:00
|
|
|
'rootJobSignature' => $this->params['rootJobSignature'] ?? null,
|
|
|
|
|
'rootJobTimestamp' => $this->params['rootJobTimestamp'] ?? null
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-11-08 22:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-03 20:51:02 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2013-04-03 20:51:02 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
public function hasRootJobParams() {
|
|
|
|
|
return isset( $this->params['rootJobSignature'] )
|
|
|
|
|
&& isset( $this->params['rootJobTimestamp'] );
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-23 17:53:12 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2015-05-23 17:53:12 +00:00
|
|
|
* @see JobQueue::deduplicateRootJob()
|
|
|
|
|
* @return bool Whether this is job is a root job
|
|
|
|
|
*/
|
|
|
|
|
public function isRootJob() {
|
|
|
|
|
return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 03:25:24 +00:00
|
|
|
/**
|
2016-10-05 01:16:56 +00:00
|
|
|
* @param callable $callback A function with one parameter, the success status, which will be
|
|
|
|
|
* false if the job failed or it succeeded but the DB changes could not be committed or
|
|
|
|
|
* any deferred updates threw an exception. (This parameter was added in 1.28.)
|
2016-02-17 03:25:24 +00:00
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
protected function addTeardownCallback( $callback ) {
|
|
|
|
|
$this->teardownCallbacks[] = $callback;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2016-10-05 01:16:56 +00:00
|
|
|
public function teardown( $status ) {
|
2016-02-17 03:25:24 +00:00
|
|
|
foreach ( $this->teardownCallbacks as $callback ) {
|
2016-10-05 01:16:56 +00:00
|
|
|
call_user_func( $callback, $status );
|
2016-02-17 03:25:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function toString() {
|
2006-06-18 12:42:16 +00:00
|
|
|
$paramString = '';
|
|
|
|
|
if ( $this->params ) {
|
|
|
|
|
foreach ( $this->params as $key => $value ) {
|
|
|
|
|
if ( $paramString != '' ) {
|
|
|
|
|
$paramString .= ' ';
|
2006-06-15 06:35:24 +00:00
|
|
|
}
|
2013-01-23 18:39:49 +00:00
|
|
|
if ( is_array( $value ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$filteredValue = [];
|
2014-05-16 22:23:26 +00:00
|
|
|
foreach ( $value as $k => $v ) {
|
2016-03-16 10:24:10 +00:00
|
|
|
$json = FormatJson::encode( $v );
|
|
|
|
|
if ( $json === false || mb_strlen( $json ) > 512 ) {
|
|
|
|
|
$filteredValue[$k] = gettype( $v ) . '(...)';
|
2014-05-16 22:23:26 +00:00
|
|
|
} else {
|
2016-03-16 10:24:10 +00:00
|
|
|
$filteredValue[$k] = $v;
|
2014-05-16 22:23:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-16 10:24:10 +00:00
|
|
|
if ( count( $filteredValue ) <= 10 ) {
|
2014-05-16 22:23:26 +00:00
|
|
|
$value = FormatJson::encode( $filteredValue );
|
|
|
|
|
} else {
|
|
|
|
|
$value = "array(" . count( $value ) . ")";
|
|
|
|
|
}
|
2013-02-15 04:11:26 +00:00
|
|
|
} elseif ( is_object( $value ) && !method_exists( $value, '__toString' ) ) {
|
2013-01-23 18:39:49 +00:00
|
|
|
$value = "object(" . get_class( $value ) . ")";
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 10:24:10 +00:00
|
|
|
$flatValue = (string)$value;
|
|
|
|
|
if ( mb_strlen( $value ) > 1024 ) {
|
|
|
|
|
$flatValue = "string(" . mb_strlen( $value ) . ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$paramString .= "$key={$flatValue}";
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 22:07:39 +00:00
|
|
|
$metaString = '';
|
|
|
|
|
foreach ( $this->metadata as $key => $value ) {
|
|
|
|
|
if ( is_scalar( $value ) && mb_strlen( $value ) < 1024 ) {
|
|
|
|
|
$metaString .= ( $metaString ? ",$key=$value" : "$key=$value" );
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
2014-10-21 22:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$s = $this->command;
|
|
|
|
|
if ( is_object( $this->title ) ) {
|
|
|
|
|
$s .= " {$this->title->getPrefixedDBkey()}";
|
|
|
|
|
}
|
|
|
|
|
if ( $paramString != '' ) {
|
|
|
|
|
$s .= " $paramString";
|
|
|
|
|
}
|
|
|
|
|
if ( $metaString != '' ) {
|
|
|
|
|
$s .= " ($metaString)";
|
2006-02-24 01:56:31 +00:00
|
|
|
}
|
2014-10-09 00:15:05 +00:00
|
|
|
|
|
|
|
|
return $s;
|
2006-06-18 12:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-22 22:44:34 +00:00
|
|
|
protected function setLastError( $error ) {
|
|
|
|
|
$this->error = $error;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:13:22 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-03-12 11:13:22 +00:00
|
|
|
*/
|
2012-08-29 00:01:31 +00:00
|
|
|
public function getLastError() {
|
2006-06-18 12:42:16 +00:00
|
|
|
return $this->error;
|
|
|
|
|
}
|
|
|
|
|
}
|