Manybubbles has uploaded a new change for review. https://gerrit.wikimedia.org/r/127647
Change subject: Add created and caused timestamp to jobs ...................................................................... Add created and caused timestamp to jobs The created timestamp is just a timestamp for when the job was created. The caused timestamp is a timestamp for the user action that caused the job to be created. It can be specified as a parameter but by default it picks up either the caused timestamp of the last job to be popped or now if no such job exists or it doesn't have the timestamp. Change-Id: I7e9a5203ded1e39e0abe8fa41246c7fed3da66db --- M includes/jobqueue/Job.php M includes/jobqueue/JobQueueGroup.php 2 files changed, 44 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/47/127647/1 diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index 5fc1e06..a6895db 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -146,6 +146,36 @@ public function __construct( $command, $title, $params = false ) { $this->command = $command; $this->title = $title; + + // Default the job's created time to now. + if ( !isset( $params['createTimestamp'] ) ) { + $params['createTimestamp'] = wfTimestampNow(); + } + // Default the timestamp of the action that caused the job to be + // created to the same timestamp on the last job that was popped from + // from the queue or now. The same timestamp from the last pop because + // that popped job very likely caused this job to be created. Now + // because either: + // 1. The job the caused this one didn't have a causedTimestamp + // meaning it is old. This should be temporary and now is as good + // a default as any in this case. + // 2. This job was not caused by a job but by a user action. In that + // case now is as close close to the time that the user performed + // the action as we're going to get. + if ( !isset( $params['causedTimestamp'] ) ) { + $lastPopped = JobQueueGroup::singleton()->getLastPopped(); + if ( $lastPopped ) { + $lastPoppedParams = $lastPopped->getParams(); + if ( isset( $lastPoppedParams['causedTimestamp'] ) ) { + $params['causedTimestamp'] = + $lastPoppedParams['causedTimestamp']; + } + } + if ( !isset( $params['causedTimestamp'] ) ) { + $params['causedTimestamp'] = wfTimestampNow(); + } + } + $this->params = $params; // expensive jobs may set this to true diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 6591282..b60fd76 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -40,6 +40,9 @@ /** @var array Map of (bucket => (queue => JobQueue, types => list of types) */ protected $coalescedQueues; + /** @var IJobSpecification|null the last popped job on any queue */ + protected $lastPopped = null; + const TYPE_DEFAULT = 1; // integer; jobs popped by default const TYPE_ANY = 2; // integer; any job @@ -152,6 +155,9 @@ */ public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = array() ) { $job = false; + // Clear lastPopped during the popping process because we don't want it to leak into + // the next job. + $this->lastPopped = null; if ( is_string( $qtype ) ) { // specific job type if ( !in_array( $qtype, $blacklist ) ) { @@ -188,10 +194,18 @@ } } + $this->lastPopped = $job; return $job; } /** + * Get the last job popped off the queue. + */ + public function getLastPopped() { + return $this->lastPopped; + } + + /** * Acknowledge that a job was completed * * @param Job $job -- To view, visit https://gerrit.wikimedia.org/r/127647 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7e9a5203ded1e39e0abe8fa41246c7fed3da66db Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Manybubbles <never...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits