Bugzilla – Attachment 142728 Details for
Bug 31969
Options for cleanup_database.pl to remove finished jobs from the background job queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31969: (follow-up) Move deletion code to Koha::BackgroundJobs->purge for reuse.
Bug-31969-follow-up-Move-deletion-code-to-KohaBack.patch (text/plain), 3.71 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-10-27 18:00:39 UTC
(
hide
)
Description:
Bug 31969: (follow-up) Move deletion code to Koha::BackgroundJobs->purge for reuse.
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-10-27 18:00:39 UTC
Size:
3.71 KB
patch
obsolete
>From c5c74a511ad5ff2e47a4882a2a2979ccbbc3a9ec Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= <bjorn.nylen@ub.lu.se> >Date: Wed, 26 Oct 2022 14:45:23 +0200 >Subject: [PATCH] Bug 31969: (follow-up) Move deletion code to > Koha::BackgroundJobs->purge for reuse. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/BackgroundJobs.pm | 45 +++++++++++++++++++++++++++++++ > misc/cronjobs/cleanup_database.pl | 30 ++++----------------- > 2 files changed, 50 insertions(+), 25 deletions(-) > >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >index 48afbf68fa..8d7ae64e0e 100644 >--- a/Koha/BackgroundJobs.pm >+++ b/Koha/BackgroundJobs.pm >@@ -72,6 +72,51 @@ sub filter_by_current { > ); > } > >+=head3 purge >+ >+ my $params = { job_types => ('all') , # Arrayref of jobtypes to be purged >+ days => 1, # Age in days of jobs to be purged >+ confirm => 1, # Confirm deletion >+ }; >+ my $count = Koha::BackgroundJobs->purge( $params ); >+ >+Deletes finished background jobs. Returns the number of jobs that was / would've been deleted. >+ >+=cut >+ >+sub purge { >+ my ( $self, $params) = @_; >+ >+ return 0 unless ( exists $params->{job_types} && scalar @{ $params->{job_types} } >= 1 ); >+ return 0 unless ( exists $params->{days} ); >+ >+ my $types = $params->{job_types}; >+ my $days = $params->{days}; >+ >+ my $confirm = exists $params->{confirm} ? $params->{confirm} : 0; >+ >+ my $rs; >+ if ( $types->[0] eq 'all' ){ >+ $rs = $self->search( >+ { >+ ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] }, >+ status => 'finished', >+ }); >+ >+ } else { >+ $rs = $self->search( >+ { >+ ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] }, >+ type => $types, >+ status => 'finished', >+ }); >+ } >+ my $count = $rs->count(); >+ $rs->delete if $confirm; >+ >+ return $count; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 612ae3639b..aff16f987b 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -690,7 +690,11 @@ if ($cards) { > > if ($background_days) { > print "Purging background jobs more than $background_days days ago.\n" if $verbose; >- my $count = PurgeBackgroundJobs($background_days, \@background_types, $confirm); >+ my $params = { job_types => \@background_types , >+ days => $background_days, >+ confirm => $confirm, >+ }; >+ my $count = Koha::BackgroundJobs->purge( $params ); > if ($verbose) { > say $confirm > ? sprintf "Done with purging %d background jobs of type(s): %s added more than %d days ago.\n", $count, join(',', @background_types), $background_days >@@ -836,27 +840,3 @@ sub DeleteSpecialHolidays { > print "Removed $count unique holidays\n" if $verbose; > } > >-sub PurgeBackgroundJobs { >- my ( $days, $types, $confirm ) = @_; >- >- my $rs; >- if ( $types->[0] eq 'all' ){ >- $rs = Koha::BackgroundJobs->search( >- { >- ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] }, >- status => 'finished', >- }); >- >- } else { >- $rs = Koha::BackgroundJobs->search( >- { >- ended_on => { '<' => \[ 'date_sub(curdate(), INTERVAL ? DAY)', $days ] }, >- type => \@{$types}, >- status => 'finished', >- }); >- } >- my $count = $rs->count(); >- $rs->delete if $confirm; >- >- return $count; >-} >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31969
:
142603
|
142668
|
142699
|
142700
|
142727
| 142728 |
142729
|
144189
|
144190