+ MAINPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
+
+function getJobCount() {
+ let bot = new MWBot( {
+ apiUrl: `${browser.options.baseUrl}/api.php`
+ } );
+ return bot.request( {
+ action: 'query',
+ meta: 'siteinfo',
+ siprop: 'statistics'
+ } ).then( ( response ) => {
+ return response.query.statistics.jobs;
+ } );
+}
+
+function log( message ) {
+ process.stdout.write( `RunJobs ${message}\n` );
+}
+
+function runThroughMainPageRequests( runCount = 1 ) {
+ let page = new Page();
+ log( `through requests to the main page (run ${runCount}).` );
+
+ page.openTitle( '' );
+
+ return getJobCount().then( ( jobCount ) => {
+ if ( jobCount === 0 ) {
+ log( 'found no more queued jobs.' );
+ return;
+ }
+ log( `detected ${jobCount} more queued job(s).` );
+ if ( runCount >= MAINPAGE_REQUESTS_MAX_RUNS ) {
+ log( 'stopping requests to the main page due to reached limit.' );
+ return;
+ }
+ return runThroughMainPageRequests( ++runCount );
+ } );
+}