Volltext-Suche: Hintergrund-Job zum Extrahieren von Texten aus Dokumenten
[kivitendo-erp.git] / SL / BackgroundJob / CleanBackgroundJobHistory.pm
1 package SL::BackgroundJob::CleanBackgroundJobHistory;
2
3 use strict;
4
5 use parent qw(SL::BackgroundJob::Base);
6
7 use SL::DB::BackgroundJobHistory;
8
9 sub create_job {
10   $_[0]->create_standard_job('0 3 * * *'); # daily at 3:00 am
11 }
12
13 sub run {
14   my $self    = shift;
15   my $db_obj  = shift;
16
17   my $options = $db_obj->data_as_hash;
18   $options->{retention_success} ||= 14;
19   $options->{retention_failure} ||= 3 * 30;
20
21   my $today = DateTime->today_local;
22
23   for my $status (qw(success failure)) {
24     SL::DB::Manager::BackgroundJobHistory->delete_all(where =>  [ status => $status,
25                                                                   run_at => { lt => $today->clone->subtract(days => $options->{"retention_${status}"}) } ]);
26   }
27
28   return 1;
29 }
30
31 1;
32
33 __END__
34
35 =encoding utf8
36
37 =head1 NAME
38
39 SL::BackgroundJob::CleanBackgroundJobHistory - Background job for
40 cleaning the history table of all executed jobs
41
42 =head1 SYNOPSIS
43
44 This background job deletes old entries from the table
45 C<background_job_histories>. Each time a job is run an entry is
46 created in that table.
47
48 The associated C<SL::DB::BackgroundJob> instance's C<data> may be a
49 hash containing the retention periods for successful and failed
50 jobs. Both are the number of days a history entry is to be kept.  C<<
51 $data->{retention_success} >> defaults to 14.  C<<
52 $data->{retention_failure} >> defaults to 90.
53
54 The job is supposed to run once a day.
55
56 =head1 BUGS
57
58 Nothing here yet.
59
60 =head1 AUTHOR
61
62 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
63
64 =cut