Ok to delete mdl_task_adhoc

Ok to delete mdl_task_adhoc

by Angela Rosin -
Number of replies: 3

Hi all,

I'm on moodle 3.5, php 7.0.33, ubuntu 16.04.16. It's an internally hosted site I took over a couple of years ago and we plan to move to external hosting/management but recent events have delayed this. Just to explain why it's quite old. My sql experience was with a small site over 15 years ago, linux experience equally old, moodle admin experience not at all.

I've got a dev server which is a clone from Feb 2020 of the site when we moved it to a larger virtual server. At the start of term we were hit by the 'recycle bin' variant of runaway auto backups on the live site. Diagnosed thanks to the information on this site. It was caused when a couple of users deleted folders with 10-20 media files in. The recycle bin timed out (not sure which) and I've now four tasks in mdl_task_adhoc. running every 24 hours and filling /temp/backup. 

id: 75806, id 75807 and id 76808 are the page object from the course 465, 109614 was a folder (I think). Deletioninprogress is set to 1 and  I think failing because the original objects don't exist on the course anymore.

Am I ok to delete these tasks? And how do I do it! I've got access to toad for mysql.

I've emptied the bin for all the courses, set the recycle bin off, let it run through a few cron jobs, then switched it back on. It was set to empty after 14 days and I've reduced it to 7. 

I've been unable to replicate the problem on the dev server. The only differences between the sites is the live site has more activities on it, and is not as up to date on server patches.

id component classname nextruntime faildelay customdata

6709 \core_course\task\course_delete_modules 1632304427 86400 {"cms":[{"id":"75806","course":"465","module":"15","instance":"595",
"section":"83553","idnumber":"","added":"1536525012","score":
"0","indent":"0","visible":"1","visibleoncoursepage":"1","visibleold"
:"1","groupmode":"0","groupingid":"0","completion":"0",
"completiongradeitemnumber":null,"completionview":"0",
"completionexpected":"0","showdescription":"0",
"availability":null,"deletioninprogress":"1"}],"userid":"46",
"realuserid":"46"}
6710 \core_course\task\course_delete_modules 1632304461 86400 {"cms":[{"id":"75807","course":"465","module":"15","instance":"596",
"section":"83553","idnumber":"","added":"1536525012","score":
"0","indent":"0","visible":"1","visibleoncoursepage":"1",
"visibleold":"1","groupmode":"0","groupingid":"0","completion":
"0","completiongradeitemnumber":null,"completionview":"0",
"completionexpected":"0","showdescription":"0","availability"
:null,"deletioninprogress":"1"}],"userid":"46","realuserid":"46"}
6711 \core_course\task\course_delete_modules 1632304537 86400 {"cms":[{"id":"75808","course":"465","module":"15","instance":"597",
"section":"83553","idnumber":"","added":"1536525012","score":
"0","indent":"0","visible":"1","visibleoncoursepage":"1",
"visibleold":"1","groupmode":"0","groupingid":"0","completion":
"0","completiongradeitemnumber":null,"completionview":"0",
"completionexpected":"0","showdescription":"0","availability":
null,"deletioninprogress":"1"}],"userid":"46","realuserid":"46"}
7140 \core_course\task\course_delete_modules 1632268438 86400 {"cms":[{"id":"109614","course":"21","module":"8","instance":"9158",
"section":"73435","idnumber":"","added":"1602693874","score":
"0","indent":"0","visible":"1","visibleoncoursepage":"1","visibleold"
:"1","groupmode":"0","groupingid":"0","completion":"0",
"completiongradeitemnumber":null,"completionview":"0",
"completionexpected":"0","showdescription":"0",
"availability":null,"deletioninprogress":"1"}],"userid":"14",
"realuserid":"14"}

Average of ratings: -
In reply to Angela Rosin

Re: Ok to delete mdl_task_adhoc

by Randy Thornton -
Picture of Documentation writers
I suspect you are correct about that: these tasks are orphaned for some reason.

There are some interesting discussions in the forums about different causes of this error: eg. https://moodle.org/mod/forum/discuss.php?d=381910 and https://moodle.org/mod/forum/discuss.php?d=346326

If the relevant courses 465 and 21 are definitely deleted from the recycle bin (check in the table mdl_tool_recyclebin_course) but the course module in question still exist in the then this could be caused by something else. In the two forums above there was an issue in the cron due to the presence of other plugins such that these tasks did not get processed as they should.

To see the details of how this works, take a look at this tracker where the process was hashed out right after the recycle bin came along in core: https://tracker.moodle.org/browse/MDL-54751
In reply to Randy Thornton

Re: Ok to delete mdl_task_adhoc

by Angela Rosin -
Ok, that's interesting, and very useful. I hadn't picked up on those discussions with my search, possibly because they sat in general, not backup and restore.

Courses 465 and 21 still exist. It's the activities 7506/7/8 that no longer exist on the course... I guess next step is to drill through my database and see if they exist anywhere still. So I followed the steps re: recycle bin here: https://moodle.org/mod/forum/discuss.php?d=364963 . I've seen some discussion on editing this to remove modules causing errors if it was gradebook (just the id for that). At the moment I'm tempted to just change the unix timestamp and give myself some time to work out if I can delete safely.

I should probably mention that we have autobackup for course set off (we run a nightly site backup) and the previous admin set the config options so any manual backups go to course backup area not a specified file location.
In reply to Angela Rosin

Re: Ok to delete mdl_task_adhoc

by Randy Thornton -
Picture of Documentation writers
Ah, that is good sleuthing.

"At the moment I'm tempted to just change the unix timestamp and give myself some time to work out if I can delete safely." Hah - I thought of the same thing. If this were one of my servers, that is what I would do to buy time and get those from repeatedly filling up space.

Another way might be just to edit deletion in progress flag, presumably 1 means in progress and so what would 0 do? I'm not sure actually. You could check in the code for that to see what those values mean and would likely do.

The tracker talks about how the deletion of specific modules works in the recycle bin as opposed to the deletion of the whole course. So clearly then, that is your situation here since the courses still exist. Something is holding up the module deletion. The good news then is that it is not deadlock issue in the recycle bin between module and its course (which is not uncommon in the case of deleting categories and courses.)