Bug 35948

Summary: cleanup_database.pl should remove not only finished background jobs
Product: Koha Reporter: Fridolin Somers <fridolin.somers>
Component: Command-line UtilitiesAssignee: Fridolin Somers <fridolin.somers>
Status: In Discussion --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: robin, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 31969    
Bug Blocks:    
Attachments: Bug 35948: cleanup_database.pl should remove not only finished background jobs

Description Fridolin Somers 2024-01-30 14:30:23 UTC
Bug 31969 changed cleanup_database.pl so it removes only finished background jobs.
But old background jobs with other statuses will never be removed.
I see no use to that
Comment 1 Fridolin Somers 2024-01-30 14:36:05 UTC
So we should use "enqueued_on" instead of "ended_on"
and no filter on status
Comment 2 Fridolin Somers 2024-01-30 14:49:22 UTC
Created attachment 161646 [details] [review]
Bug 35948: cleanup_database.pl should remove not only finished background jobs

Bug 31969 changed cleanup_database.pl so it removes only finished background jobs.
But old background jobs with other statuses will never be removed.

So we should use "enqueued_on" instead of "ended_on"
and no filter on status

Test plan :
1) Create a background job with for example a batch item modification
2) Simulate ancien job via SQL :
update background_jobs set status='failed',enqueued_on=DATE_SUB(NOW(),INTERVAL 10 DAY) where id=X
3) Run misc/cronjobs/cleanup_database.pl --jobs-days 9 --jobs-type all -v --confirm
4) Check the job is removed
Comment 3 Katrin Fischer 2024-01-30 16:58:09 UTC
Currently we have a lot of problems with jobs not finishing. Would this not only hide the problem? I feel it should be an option and not a change of behaviour.
Comment 4 Victor Grousset/tuxayo 2024-02-25 18:42:41 UTC
@Fridolin: see bug 35092

What are the other "final" statues that should be cleaned?
Certainly there should be "cancelled".

And on the long run, "failed" also.
Not sure about now because that might hide the current issues if --jobs-days is too small. But maybe it ok, I don't know.
Comment 5 Fridolin Somers 2024-02-26 14:47:24 UTC
Ah sure, cancelled is missing.

I set status to needs discussion ;)
Comment 6 Victor Grousset/tuxayo 2024-02-27 08:11:56 UTC
Anything else to cleanup besides cancelled and failed?