Skip to content

Commit

Permalink
Create RunJobs.php (#5753)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
paladox and github-actions authored Dec 5, 2024
1 parent 5bb549c commit 85eada5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GlobalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,4 @@
$wgHTTPImportTimeout = 50;

// Notifications
$wgNotifyTypeAvailabilityByCategory['login-success']['web'] = false;
$wgNotifyTypeAvailabilityByCategory['login-success']['web'] = false;
66 changes: 66 additions & 0 deletions rpc/RunJobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* 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
*
* @file
* @author Aaron Schulz
*/

// This is for beta, DO NOT USE for production. Use RunSingleJob instead.

use MediaWiki\MediaWikiServices;

if ( !in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '0:0:0:0:0:0:0:1', '::1' ), true ) ) {
http_response_code( 500 );
die( "Only loopback requests are allowed.\n" );
} elseif ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
http_response_code( 405 );
header( 'Allow: POST' );
die( "Request must use POST.\n" );
}

define( 'MEDIAWIKI_JOB_RUNNER', 1 );
define( 'MW_DB', isset( $_GET['wiki'] ) ? $_GET['wiki'] : '' );

require_once __DIR__ . '/../initialise/MirahezeFunctions.php';
require MirahezeFunctions::getMediaWiki( 'includes/WebStart.php' );

// fatals but not random I/O warnings
error_reporting( E_ERROR );
ini_set( 'display_errors', 1 );
$wgShowExceptionDetails = true;

// Session consistency is not helpful here and will slow things down in some cases
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lbFactory->disableChronologyProtection();

try {
$mediawiki = new MediaWiki();
$runner = MediaWikiServices::getInstance()->getJobRunner();
$response = $runner->run( [
'type' => isset( $_GET['type'] ) ? $_GET['type'] : false,
'maxJobs' => isset( $_GET['maxjobs'] ) ? $_GET['maxjobs'] : 5000,
'maxTime' => isset( $_GET['maxtime'] ) ? $_GET['maxtime'] : 30
] );

print json_encode( $response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

$mediawiki->restInPeace();
} catch ( Exception $e ) {
http_response_code( 500 );
MWExceptionHandler::rollbackPrimaryChangesAndLog( $e );
}

0 comments on commit 85eada5

Please sign in to comment.