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
22 * @author Aaron Schulz
25 require_once __DIR__
. '/Maintenance.php';
28 * Maintenance script that handles managing job queue admin tasks (re-push, delete, ...)
30 * @ingroup Maintenance
32 class ManageJobs
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->addDescription( 'Perform administrative tasks on a job queue' );
36 $this->addOption( 'type', 'Job type', true, true );
37 $this->addOption( 'action', 'Queue operation ("delete", "repush-abandoned")', true, true );
40 public function execute() {
41 $type = $this->getOption( 'type' );
42 $action = $this->getOption( 'action' );
44 $group = JobQueueGroup
::singleton();
45 $queue = $group->get( $type );
47 if ( $action === 'delete' ) {
48 $this->delete( $queue );
49 } elseif ( $action === 'repush-abandoned' ) {
50 $this->repushAbandoned( $queue );
52 $this->error( "Invalid action '$action'.", 1 );
56 private function delete( JobQueue
$queue ) {
57 $this->output( "Queue has {$queue->getSize()} job(s); deleting...\n" );
59 $this->output( "Done; current size is {$queue->getSize()} job(s).\n" );
62 private function repushAbandoned( JobQueue
$queue ) {
63 $cache = ObjectCache
::getInstance( CACHE_DB
);
64 $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getWiki(), $queue->getType() );
66 $now = wfTimestampNow();
67 $lastRepushTime = $cache->get( $key );
68 if ( $lastRepushTime === false ) {
69 $lastRepushTime = wfTimestamp( TS_MW
, 1 ); // include all jobs
72 $this->output( "Last re-push time: $lastRepushTime; current time: $now\n" );
76 foreach ( $queue->getAllAbandonedJobs() as $job ) {
78 if ( $job->getQueuedTimestamp() < wfTimestamp( TS_UNIX
, $lastRepushTime ) ) {
80 continue; // already re-pushed in prior round
86 if ( ( $count %
$this->mBatchSize
) == 0 ) {
87 $queue->waitForBackups();
91 $cache->set( $key, $now ); // next run will ignore these jobs
93 $this->output( "Re-pushed $count job(s) [$skipped skipped].\n" );
97 $maintClass = "ManageJobs";
98 require_once RUN_MAINTENANCE_IF_MAIN
;