Operator: Wbm1058 ( talk · contribs · SUL · edit count · logs · page moves · block log · rights log · ANI search)
Time filed: 02:36, Saturday, June 25, 2022 ( UTC)
Automatic, Supervised, or Manual: automatic
Programming language(s): PHP
Source code available: refreshlinks.php, refreshmainlinks.php
Function overview: Purge pages with recursive link update in order to refresh links which are old
Links to relevant discussions (where appropriate):
Edit period(s): Continuous
Estimated number of pages affected: ALL
Exclusion compliant (Yes/No): No
Already has a bot flag (Yes/No): Yes
Function details: This task runs two scripts to refresh English Wikipedia page links. refreshmainlinks.php null-edits mainspace pages whose page_links_updated database field is older than ~32 days, and refreshlinks.php null-edits all other namespaces whose page_links_updated database field is older than ~80 days. The 32- and 80-day figures may be tweaked as needed to ensure more timely refreshing of links or reduce load on the servers. are approximate and are dynamically adjusted after each run. If fewer than 250 pages were purged by the current run then the number of days ago to purge is decremented by one, e.g. reduced from 32 to 31. If the full limit of 10,000 pages was purged then the number of days ago to purge is incremented by one, e.g. increased from 80 to 81. Each script is configured to purge a maximum of 150,000 10,000 pages on a single run, and restart every three hours if not currently running (thus each script may run up to 8 times per day). restarts after sleeping for two minutes. The tasks run as continuous jobs on the Toolforge Kubernetes as my PHP code runs continuous loops. The only "babysitting" needed is to periodically rename the log files and then restart the toolforge jobs, in order to limit the size of the log files.
Status may be monitored by these Quarry queries:
and this Toolforge systems query:
I expect speedy approval, as a technical request, as this task only makes null edits. Task has been running for over a month. My main reason for filing this is to post my source code and document the process including links to the various discussions about it. – wbm1058 ( talk) 03:02, 25 June 2022 (UTC) reply
To get some idea of the rate of null edits: the robot's maximum editing speed is 14 edits per second (150000 × 8 in a day). There are 6,851,183 articles, 61,015,295 pages total (how did we end up with almost ten times as many pages as articles?); this means that the average number of edits that need making per day is around 825000 per day, or around 9.5 per second. Wikipedia currently gets around 160000 edits per day (defined as "things that have an oldid number", so including moves, page creations, etc.), or around 2 per second. So this bot could be editing four times as fast as everyone else on Wikipedia put together (including all the other bots), which would likely be breaking new ground from the point of view of server load (although the servers might well be able to handle it anyway, and if not I guess the developers would just block its IP from making requests) – maybe a bit less, but surely a large proportion of pages rarely get edited.
As a precaution, the bot should also avoid null-editing pages that contain {{subst:
(possibly with added whitespace or comments), because
null edits can change the page content sometimes in this case (feel free to null-edit
User:ais523/Sandbox to see for yourself – just clicking "edit" and "save" is enough); it's very hard to get the wikitext to subst a template into a page in the first place (because it has a tendency to replace itself with the template's contents), but once you manage it, it can lay there ready to trigger and mess up null edits, and this seems like the sort of thing that might potentially happen by mistake (e.g.
Module:Unsubst is playing around in similar space; although that one won't have a bad interaction with the bot, it's quite possible we'll end up creating a similar template in future and that one will cause problems). --
ais523 23:06, 6 July 2022 (
U
T
C)
page_links_updated
dates. –
wbm1058 (
talk)
11:55, 12 July 2022 (UTC)
replymkdir public_html
but I don't need to create my bot's code, I just need to copy it to that directory. One of the files needed to run my bot is the file containing login passwords and I'm leery of copying that to a directory with "public" in its name! Some guidance on how to do this would be appreciated since the quickstart authors apparently felt that wasn't necessary. Microsoft Notepad probably isn't installed on the Toolforge and I probably need Linux rather than Microsoft commands. Can I import the files from wikipages (i.e.
User:Bot1058/refreshlinks.php)?
wbm1058 (
talk)
19:09, 31 August 2022 (UTC)
reply
chmod 600 file-with-password.txt
. /data/project/shared
directory, which is readable (and potentially writeable) by all Toolforge tools and users." Still trying to digest this information. –
wbm1058 (
talk)
17:41, 15 September 2022 (UTC)
reply
-r--------
which means only the owner can read and no one can modify.The recommendation to use different tool accounts per "tool" is for webservices (since each tool account can have only one web domain). For bots, just use a single tool account for multiple bots – that's easier to maintain and manage. –
SD0001 (
talk)
05:53, 18 September 2022 (UTC)
reply
refreshlinks
to a more generic name that covers all my bots, but
tools can't be renamed, nor can
maintainers delete Tool Accounts. I will follow the steps described at
Toolforge (Tools to be deleted). It should be obvious from my experience trying to get a "quick start" on Toolforge why you have such
a growing list of tools that have been volunteered for deleting by their maintainers. –
wbm1058 (
talk)
18:11, 22 September 2022 (UTC)
replymkdir php
creating a PHP directory where I can upload needed files from the PHP directory on my Windows PC. Then I go over to WinSCP to try to upload the files. There I can upload botclasses.php into /billsbots/ root directory but I don't have permission to upload to the /billsbots/php/ sub-directory I just created. I see "tools.billbots" is the owner of the /billsbots/php/ sub-directory but wbm1058 is owner of botclasses.php. I logged into WinSCP the same way I log into PuTTY as wbm1058. Is there a way inside WinSCP to "become billsbots" analogous to the way I do that in PuTTY? I assume "tools.billbots" should be the owner of its public PHP files and not "wbm1058"? Also unsure of what rights settings the php directory and the files in that directory that don't house passwords should have. Right now they just are the default from mkdir php
and the upload. –
wbm1058 (
talk)
18:52, 24 September 2022 (UTC)
reply
tools.billsbot
includes the user wbm1058
. Problem in this case is that the group doesn't have write permission. See
wikitech:Help:Access_to_Toolforge_instances_with_PuTTY_and_WinSCP#Troubleshooting_permissions_errors. Files which don't have passwords typically should have 774 (owner+group can do everything, public can read) perms. –
SD0001 (
talk)
05:38, 25 September 2022 (UTC)
reply@ SD0001: Thank you so much for your help. I've now successfully manually run refreshlinks.php from the command prompt in PuTTY. I need to be logged in as myself for it to work, and not as my tool, because I own and have read permission for my password file, and my tool does not. Per wikitech:Help:Toolforge/Grid#Submitting simple one-off jobs using 'jsub' when I become my tool then
jsub -N refreshlinks php /mnt/nfs/labstore-secondary-tools-project/billsbots/php/refreshlinks.php
and I got this in my refreshlinks.out
file:Warning: include(/mnt/nfs/labstore-secondary-tools-project/billsbots/php/logininfo.php): failed to open stream: Permission denied in /mnt/nfs/labstore-secondary-tools-project/billsbots/php/refreshlinks.php on line 28
– wbm1058 ( talk) 15:32, 1 October 2022 (UTC) reply
become
the tool, take
the file (transfers ownership to tool) and then do chmod 660
– that would give access to both yourself and the tool. –
SD0001 (
talk)
18:20, 1 October 2022 (UTC)
reply--image
as tf-php74
. –
SD0001 (
talk)
17:53, 6 October 2022 (UTC)
replyYour process `sftp-server` has been killed on tools-sgebastion-10 by the Wheel of Misfortune script.
You are receiving this email because you are listed as the shell user running the killed process or as a maintainer of the tool that was.
Long-running processes and services are intended to be run on the either the Kubernetes environment or the job grid not on the bastion servers themselves. In order to ensure that login servers don't get heavily burdened by such processes, this script selects long-running processes at random for destruction.
See < https://phabricator.wikimedia.org/T266300> for more information on this initative. You are invited to provide constructive feedback about the importance of particular types long running processes to your work in support of the Wikimedia movement.
For further support, visit #wikimedia-cloud on libera.chat or < https://wikitech.wikimedia.org>
the task as currently configured "breaks" easily and requires a lot of minding to keep it running.Thanks, I guess, for this belated message that came only 3 1⁄2 months after I got my automated process running this way. So I suppose speedy approval isn't merited and won't be forthcoming. I did not know that I was running a process named
sftp-server
. What is that, and what is it doing? Most of this bot's process is still running on my own PC. Every few hours when a new script-run starts, it logs into the replica database and does a query which, even when it returns 150K results, takes only a couple of minutes. Then it logs out. It's not like this is constantly hitting on bastion resources. The only reason I need to be logged into the bastion 24×7 (via PuTTY) is that, if I'm not, then my bot, when it starts, will not be able to "tunnel" and thus will fail. The vast majority of the time I'm logged into the bastion, I'm just sitting there idle, doing nothing. Not "heavily burdening" the login server. I need to "tunnel" because there is no MediaWiki API for the database query I need to make. Otherwise I don't need the Toolforge because there is an API for making the "null edit" purges. –
wbm1058 (
talk)
15:53, 14 October 2022 (UTC)
reply
sftp-server
kills are from my open WinSCP session. I didn't get WinSCP installed and running until September 15, and the first email I saw from the Wheel of Misfortune was sent on October 9 (and I've received several since then). I keep WinSCP open on my desktop for my convenience. I just saw there is a "Disconnect Session" option on the "Session" tab in WinSCP and I just clicked on it. Hopefully that will stop the Wheel of Misfortune's anger. Now I can just click "Reconnect Session" when I go back to use WinSCP again – which saves me the trouble of needing to close and reopen the entire app. As far as I know the Wheel of Misfortune has never actually shut down my bot itself, perhaps because individual bot runs are not sufficiently long-running processes to draw the attention of the "Wheel". Even runs that purge 150,000 pages run in a matter of hours, not days. –
wbm1058 (
talk)
17:21, 19 December 2022 (UTC)
replywbm1058@tools-sgebastion-10:~$ become billsbots
tools.billsbots@tools-sgebastion-10:~$ toolforge-jobs run refreshlinks-k8s --command "php ./php/refreshlinks.php" --image tf-php74 --wait
ERROR: timed out 300 seconds waiting for job 'refreshlinks-k8s' to complete:
+------------+-----------------------------------------------------------------+
| Job name: | refreshlinks-k8s |
+------------+-----------------------------------------------------------------+
| Command: | php ./php/refreshlinks.php |
+------------+-----------------------------------------------------------------+
| Job type: | normal |
+------------+-----------------------------------------------------------------+
| Image: | tf-php74 |
+------------+-----------------------------------------------------------------+
| File log: | yes |
+------------+-----------------------------------------------------------------+
| Emails: | none |
+------------+-----------------------------------------------------------------+
| Resources: | default |
+------------+-----------------------------------------------------------------+
| Status: | Running |
+------------+-----------------------------------------------------------------+
| Hints: | Last run at 2022-11-03T16:53:38Z. Pod in 'Running' phase. State |
| | 'running'. Started at '2022-11-03T16:53:40Z'. |
+------------+-----------------------------------------------------------------+
tools.billsbots@tools-sgebastion-10:~$ toolforge-jobs list
Job name: Job type: Status:
---------------- ----------- ---------
refreshlinks-k8s normal Running
tools.billsbots@tools-sgebastion-10:~$
Will wait a bit for new emails or Phabricators to come in telling me what I'm still doing wrong, before proceeding to the next step, creating scheduled jobs (cron jobs). – wbm1058 ( talk) 19:12, 3 November 2022 (UTC) reply
Someone (probably you) recently logged in to your account from a new device. If this was you, then you can disregard this message. If it wasn't you, then it's recommended that you change your password, and check your account activity." The Help button at the bottom of the email message links to mw:Help:Login notifications, which says "this feature relies on cookies to keep track of the devices you have used to log in". I'm guessing that cookies are not working in my Toolforge account.
The code I use to log in is:
|
---|
$objwiki = new wikipedia();
$objwiki->login($user, $pass);
/**
* This function takes a username and password and logs you into wikipedia.
* @param $user Username to login as.
* @param $pass Password that corrisponds to the username.
* @return array
**/
function login ($user,$pass) {
$post = array('lgname' => $user, 'lgpassword' => $pass);
$ret = $this->query('?action=query&meta=tokens&type=login&format=json');
print_r($ret);
/* This is now required - see https://bugzilla.wikimedia.org/show_bug.cgi?id=23076 */
$post'lgtoken' = $ret'query']['tokens']['logintoken'];
$ret = $this->query( '?action=login&format=json', $post );
if ($ret'login']['result' != 'Success') {
echo "Login error: \n";
print_r($ret);
die();
} else {
print_r($ret);
return $ret;
}
}
|
On my way to creating scheduled jobs, I ran into another issue. Per
wikitech:Help:Toolforge/Jobs framework#Job logs, Subsequent same-name job runs will append to the same files... there is no automatic way to prune log files, so tool users must take care of such files growing too large.
What?! How hard can it be to offer a "supersede" option to override the default "append"? –
wbm1058 (
talk)
22:07, 12 November 2022 (UTC)
reply
Log generation can be disabled with the --no-filelog
parameter when creating a new job
. If it makes sense to sometimes disable logs entirely, why wouldn't it also make sense to sometimes supersede them? All logs for bots running on my desktop PC are always superseded. That's usually not a problem, but sometimes it would be nice to be able to go back and look at a previous log to see what happened on the run where a bug first surfaced. The logs for this task are quite long though.Abandoned complicated workaround after T301901 closed
|
---|
@
SD0001: I'm trying to implement the somewhat complicated workaround given at
wikitech:Help:Toolforge/Jobs framework#Custom log files. I've added some explanations to this section (see the edit history) so let me know if I added anything that's not correct. I take the following as instructions to type the following directly from my PuTTY keyboard.
tools.mytool@tools-sgebastion-11:~$ cat > log-wrapper.sh <<EOF
> #!/bin/sh
> jobname=$1
> command=$2
> mkdir -p logs
> sh -c $command 1>>logs/${jobname}.log 2>>logs/${jobname}.log
> EOF
tools.mytool@tools-sgebastion-11:~$ chmod a+x log-wrapper.sh
After doing that I notice that the $1 and $2, and $command and ${jobname}, were eaten somehow. The contents of my #!/bin/sh
jobname=
command=
mkdir -p logs
sh -c 1>>logs/.log 2>>logs/.log
which doesn't seem right to me. Of course I can just copy-paste the contents of the file from the Help: page directly with WinSCP, rather than type them in with PuTTY (which I did). If this Help: page isn't giving instructions that work, it should be corrected. I've made a couple of unsuccessful attempts, and something was obviously wrong with my syntax. – wbm1058 ( talk) 19:06, 17 November 2022 (UTC) reply ./php/refreshlinks.php: 1: cannot open ?php: No such file
./php/refreshlinks.php: 2: /bin: Permission denied
./php/refreshlinks.php: 3: log-wrapper.sh: not found
./php/refreshlinks.php: 4: log-wrapper.sh: not found
./php/refreshlinks.php: 5: Syntax error: word unexpected (expecting ")")
|
there is no automatic way to prune log files, so tool users must take care of such files growing too large. Huh? I guess I made the mistake of trying to piggyback on an existing Phab rather than opening a new one. – wbm1058 ( talk) 13:29, 25 January 2023 (UTC) reply
OK, I think I'm close to having this wired. Per the advice above to process just 5-10k titles at a time, and run the script more frequently
I've set the LIMIT for database lookups to 10000 and am now running the
refreshlinks script as a
continuous job. If the number of pages processed in the previous run is less than 250, then it sleeps 20 minutes before hitting the database again; otherwise it just sleeps for two minutes. Command I used to get it started:
toolforge-jobs run refreshlinks --command "php ./php/refreshlinks.php" --image php8.2 -o ./logs/refreshlinks.log -e ./logs/refreshlinks.log --continuous
I don't get the impression it runs any faster on the Toolforge than it runs on my 12-yr old desktop; if anything it seems to be running a little slower on Toolforge.
If this setup is OK then I'll set up my other script refreshmainlinks to run this way too. At the moment that one is still running on my desktop as it has been since I filed this BRFA. – wbm1058 ( talk) 21:49, 9 February 2023 (UTC) reply
Tracking the run times for processing 10,000 pages (extracted from the job logs):
It doesn't seem like I've gained anything from having the server running your code and the database are on the same hi-speed network
. I haven't looked into how my process on Toolforge may be resource-limited and how to request more resources. I haven't really noticed any reliability issues running on my desktop, at least not as much as I had last August. –
wbm1058 (
talk)
13:50, 10 February 2023 (UTC)
reply
My bot has found a new problem, which I've reported at WP:VPT#new fat: project conflicting with a couple English wiki article titles. – wbm1058 ( talk) 12:37, 30 July 2023 (UTC) reply
After many months running refreshlinks on the Toolforge and refreshmainlinks on my PC, I've shut down all link-refreshing processes that were running on my PC and have started running refreshmainlinks on the Toolforge with the following command:
toolforge-jobs run refreshmainlinks --command "php ./php/refreshmainlinks.php" --image php8.2 -o ./logs/refreshmainlinks.log -e ./logs/refreshmainlinks.log --continuous
Now all (both) link-refreshing processes are running on the Toolforge. – wbm1058 ( talk) 19:13, 14 August 2023 (UTC) reply
I've updated the Function details to reflect how the current versions 3.2 of my PHP code work. – wbm1058 ( talk) 12:41, 16 August 2023 (UTC) reply
Approved. This bot task performs no logged edits or actions and appears to have been running fine for quite a while now. –
SD0001 (
talk)
17:56, 26 August 2023 (UTC)
reply