3 * Maintenance script that handles managing job queue admin tasks
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.
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.
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
21 * @ingroup Maintenance
24 require_once __DIR__
. '/Maintenance.php';
27 * Maintenance script that handles managing job queue admin tasks (re-push, delete, ...)
29 * @ingroup Maintenance
31 class ManageJobs
extends Maintenance
{
32 public function __construct() {
33 parent
::__construct();
34 $this->addDescription( 'Perform administrative tasks on a job queue' );
35 $this->addOption( 'type', 'Job type', true, true );
36 $this->addOption( 'action', 'Queue operation ("delete", "repush-abandoned")', true, true );
39 public function execute() {
40 $type = $this->getOption( 'type' );
41 $action = $this->getOption( 'action' );
43 $group = JobQueueGroup
::singleton();
44 $queue = $group->get( $type );
46 if ( $action === 'delete' ) {
47 $this->delete( $queue );
48 } elseif ( $action === 'repush-abandoned' ) {
49 $this->repushAbandoned( $queue );
51 $this->fatalError( "Invalid action '$action'." );
55 private function delete( JobQueue
$queue ) {
56 $this->output( "Queue has {$queue->getSize()} job(s); deleting...\n" );
58 $this->output( "Done; current size is {$queue->getSize()} job(s).\n" );
61 private function repushAbandoned( JobQueue
$queue ) {
62 $cache = ObjectCache
::getInstance( CACHE_DB
);
63 $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getDomain(), $queue->getType() );
65 $now = wfTimestampNow();
66 $lastRepushTime = $cache->get( $key );
67 if ( $lastRepushTime === false ) {
68 $lastRepushTime = wfTimestamp( TS_MW
, 1 ); // include all jobs
71 $this->output( "Last re-push time: $lastRepushTime; current time: $now\n" );
75 foreach ( $queue->getAllAbandonedJobs() as $job ) {
77 if ( $job->getQueuedTimestamp() < wfTimestamp( TS_UNIX
, $lastRepushTime ) ) {
79 continue; // already re-pushed in prior round
85 if ( ( $count %
$this->getBatchSize() ) == 0 ) {
86 $queue->waitForBackups();
90 $cache->set( $key, $now ); // next run will ignore these jobs
92 $this->output( "Re-pushed $count job(s) [$skipped skipped].\n" );
96 $maintClass = ManageJobs
::class;
97 require_once RUN_MAINTENANCE_IF_MAIN
;