Job queue: Difference between revisions

From Saintapedia
Jump to navigation Jump to search
Line 13: Line 13:


=== Cron job ===
=== Cron job ===
<code>
<syntaxhighlight lang="bash">
#!/bin/bash
#!/bin/bash
# Put the MediaWiki installation path on the line below
# <translate nowrap><!--T:103--> Put the MediaWiki installation path on the line below</translate>
MW_INSTALL_PATH="/home/www/www.mywikisite.example/mediawiki"
MW_INSTALL_PATH="/home/www/www.mywikisite.example/mediawiki"
RUN_JOBS="$MW_INSTALL_PATH/maintenance/runJobs.php --maxtime=3600"
RUN_JOBS="$MW_INSTALL_PATH/maintenance/runJobs.php --maxtime=3600"
echo Starting job service...
echo <translate nowrap><!--T:104--> Starting job service...</translate>
# Wait a minute after the server starts up to give other processes time to get started
# <translate nowrap><!--T:105--> Wait a minute after the server starts up to give other processes time to get started</translate>
sleep 60
sleep 60
echo Started.
echo <translate nowrap><!--T:106--> Started.</translate>
while true; do
while true; do
# Job types that need to be run ASAP no matter how many of them are in the queue
# <translate nowrap><!--T:107--> Job types that need to be run ASAP no matter how many of them are in the queue</translate>
# Those jobs should be very "cheap" to run
# <translate nowrap><!--T:108--> Those jobs should be very "cheap" to run</translate>
php $RUN_JOBS --type="enotifNotify"
php $RUN_JOBS --type="enotifNotify"
# Everything else, limit the number of jobs on each batch
# <translate nowrap><!--T:109--> Everything else, limit the number of jobs on each batch</translate>
# The --wait parameter will pause the execution here until new jobs are added,
# <translate nowrap><!--T:110--> The <tvar name=1>--wait</tvar> parameter will pause the execution here until new jobs are added,</translate>
# to avoid running the loop without anything to do
# <translate nowrap><!--T:111--> to avoid running the loop without anything to do</translate>
php $RUN_JOBS --wait --maxjobs=20
php $RUN_JOBS --wait --maxjobs=20
# Wait some seconds to let the CPU do other things, like handling web requests, etc
# <translate nowrap><!--T:112--> Wait some seconds to let the CPU do other things, like handling web requests, etc</translate>
echo Waiting for 10 seconds...
echo <translate nowrap><!--T:113--> Waiting for 10 seconds...</translate>
sleep 10
sleep 10
done
done
</code>
</syntaxhighlight>


=== Docker ===
=== Docker ===

Revision as of 11:07, 4 October 2024

Job queue on Wikipedia

The job queue in MediaWiki is a system designed to handle tasks that are too time-consuming or resource-intensive to be performed during a normal web request-response cycle.

The job queue allows MediaWiki to defer tasks that do not need immediate execution. This includes operations like updating link tables when templates change, sending notification emails, re-rendering pages after template edits, or any batch processing tasks.

Saintapedia reference

Example

Cron job

#!/bin/bash
# <translate nowrap><!--T:103--> Put the MediaWiki installation path on the line below</translate>
MW_INSTALL_PATH="/home/www/www.mywikisite.example/mediawiki"
RUN_JOBS="$MW_INSTALL_PATH/maintenance/runJobs.php --maxtime=3600"
echo <translate nowrap><!--T:104--> Starting job service...</translate>
# <translate nowrap><!--T:105--> Wait a minute after the server starts up to give other processes time to get started</translate>
sleep 60
echo <translate nowrap><!--T:106--> Started.</translate>
while true; do
	# <translate nowrap><!--T:107--> Job types that need to be run ASAP no matter how many of them are in the queue</translate>
	# <translate nowrap><!--T:108--> Those jobs should be very "cheap" to run</translate>
	php $RUN_JOBS --type="enotifNotify"
	# <translate nowrap><!--T:109--> Everything else, limit the number of jobs on each batch</translate>
	# <translate nowrap><!--T:110--> The <tvar name=1>--wait</tvar> parameter will pause the execution here until new jobs are added,</translate>
	# <translate nowrap><!--T:111--> to avoid running the loop without anything to do</translate>
	php $RUN_JOBS --wait --maxjobs=20
	# <translate nowrap><!--T:112--> Wait some seconds to let the CPU do other things, like handling web requests, etc</translate>
	echo <translate nowrap><!--T:113--> Waiting for 10 seconds...</translate>
	sleep 10
done

Docker

* * * * * docker exec web php maintenance/runJobs.php --maxjobs 700 --maxtime=55

sudo crontab -e

External