Merge "Reset scoped session for upload jobs after deferred updates"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 1 Mar 2016 11:30:55 +0000 (11:30 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 1 Mar 2016 11:30:55 +0000 (11:30 +0000)
includes/jobqueue/Job.php
includes/jobqueue/JobRunner.php
includes/jobqueue/jobs/AssembleUploadChunksJob.php
includes/jobqueue/jobs/PublishStashedFileJob.php

index 37e3d0f..48d38d9 100644 (file)
@@ -47,6 +47,9 @@ abstract class Job implements IJobSpecification {
        /** @var string Text for error that occurred last */
        protected $error;
 
+       /** @var callable[] */
+       protected $teardownCallbacks = [];
+
        /**
         * Run the job
         * @return bool Success
@@ -279,6 +282,25 @@ abstract class Job implements IJobSpecification {
                return $this->hasRootJobParams() && !empty( $this->params['rootJobIsSelf'] );
        }
 
+       /**
+        * @param callable $callback
+        * @since 1.27
+        */
+       protected function addTeardownCallback( $callback ) {
+               $this->teardownCallbacks[] = $callback;
+       }
+
+       /**
+        * Do any final cleanup after run(), deferred updates, and all DB commits happen
+        *
+        * @since 1.27
+        */
+       public function teardown() {
+               foreach ( $this->teardownCallbacks as $callback ) {
+                       call_user_func( $callback );
+               }
+       }
+
        /**
         * Insert a single job into the queue.
         * @return bool True on success
index c542d97..ef3d61d 100644 (file)
@@ -266,6 +266,7 @@ class JobRunner implements LoggerAwareInterface {
 
                        DeferredUpdates::doUpdates();
                        $this->commitMasterChanges( $job );
+                       $job->teardown();
                } catch ( Exception $e ) {
                        MWExceptionHandler::rollbackMasterChangesAndLog( $e );
                        $status = false;
index 395da22..bc2f7c4 100644 (file)
@@ -35,6 +35,10 @@ class AssembleUploadChunksJob extends Job {
        public function run() {
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scope = RequestContext::importScopedSession( $this->params['session'] );
+               $this->addTeardownCallback( function () use ( &$scope ) {
+                       ScopedCallback::consume( $scope ); // T126450
+               } );
+
                $context = RequestContext::getMain();
                $user = $context->getUser();
                try {
index 34ce4fe..a6d2f70 100644 (file)
@@ -37,6 +37,10 @@ class PublishStashedFileJob extends Job {
        public function run() {
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scope = RequestContext::importScopedSession( $this->params['session'] );
+               $this->addTeardownCallback( function () use ( &$scope ) {
+                       ScopedCallback::consume( $scope ); // T126450
+               } );
+
                $context = RequestContext::getMain();
                $user = $context->getUser();
                try {