Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions maintenance/RequeueForAIEvaluation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Miraheze\MirahezeMagic\Maintenance;

/**
* 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
* @ingroup Maintenance
* @author Agent Isai
* @version 1.0
*/

use MediaWiki\JobQueue\JobSpecification;
use MediaWiki\Maintenance\Maintenance;
use MediaWiki\MediaWikiServices;

class RequeueForAIEvaluation extends Maintenance {

public function __construct() {
parent::__construct();
$this->addDescription( "Loads wiki requests in a defined queue (defaults to 'inreview') for AI evaluation." );

$this->addArg( 'from', 'Timestamp defining from when to start loading requests.', required: true );
$this->addOption( 'sleep', 'How many seconds the script should sleep for', required: false, withArg: true );
$this->addOption( 'queue-name', 'What queue should be processed?', required: false, withArg: true );
}

public function execute() {
$dbw = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_PRIMARY, 'virtual-createwiki-central' );

$queueName = $this->getOption( 'queue-name', 'inreview' );
$this->output( "Fetching all '$queueName' requests...\n" );

$from = $this->getArg( 'from', '20250901000000' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Remove the default value from the required argument.

Line 37 declares the from argument as required: true, but Line 50 provides a default value '20250901000000'. This makes the argument effectively optional. Remove the default value to enforce the requirement, or make the argument optional in the constructor.

Apply this diff:

-		$from = $this->getArg( 'from', '20250901000000' );
+		$from = $this->getArg( 'from' );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$from = $this->getArg( 'from', '20250901000000' );
$from = $this->getArg( 'from' );
🤖 Prompt for AI Agents
In maintenance/RequeueForAIEvaluation.php around line 50, the call to
$this->getArg provides a default ('20250901000000') even though the constructor
declares the 'from' argument required; remove the default so the call enforces
the required argument (i.e., call getArg with just the argument name and no
default), or alternatively change the constructor to make 'from' optional if you
intend to keep the default—update the code accordingly so the requirement and
default behavior are consistent.


$res = $dbw->newSelectQueryBuilder()
->select( 'cw_id' )
->from( 'cw_requests' )
->where( [ 'cw_status' => $queueName ] )
->andWhere( $dbw->expr( 'cw_timestamp', '>', $dbw->timestamp( $from ) ) )
->caller( __METHOD__ )
->fetchResultSet();

if ( !$res->numRows() ) {
$this->output( "No requests found with status '$queueName' within the specified range.\n" );
return;
}

$jobQueueGroup = MediaWikiServices::getInstance()->getJobQueueGroup();

foreach ( $res as $row ) {
$requestId = (int)$row->cw_id;
$this->output( "Adding wiki request $requestId to queue...\n" );

$job = new JobSpecification(
'RequestWikiRemoteAIJob',
[ 'id' => $requestId ]
);

$jobQueueGroup->push( $job );
$this->output( "Successfully added wiki request $requestId to the AI evaluation queue!\n" );

$sleepFor = $this->getOption( 'sleep', 30 );
$this->output( "Sleeping for $sleepFor seconds...\n" );
sleep( $sleepFor );
}

$this->output( "All '$queueName' requests have been queued for processing.\n" );
}
}

// @codeCoverageIgnoreStart
return RequeueForAIEvaluation::class;
// @codeCoverageIgnoreEnd
Loading