Rückstände aus Umbenennung von SL/DB/Helpers nach SL/DB/Helper gefixt
[kivitendo-erp.git] / SL / DB / Manager / BackgroundJob.pm
1 package SL::DB::Manager::BackgroundJob;
2
3 use strict;
4
5 use SL::DB::Helper::Manager;
6 use base qw(SL::DB::Helper::Manager);
7
8 sub object_class { 'SL::DB::BackgroundJob' }
9
10 __PACKAGE__->make_manager_methods;
11
12 sub cleanup {
13   my $class = shift;
14   $class->delete_all(where => [ and => [ type => 'once', last_run_at => { lt => DateTime->now_local->subtract(days => '1') } ] ]);
15 }
16
17 sub get_all_need_to_run {
18   my $class         = shift;
19
20   my $now           = DateTime->now_local;
21   my @interval_args = (and => [ type        => 'interval',
22                                 active      => 1,
23                                 next_run_at => { le => $now } ]);
24   my @once_args     = (and => [ type        => 'once',
25                                 active      => 1,
26                                 last_run_at => undef,
27                                 or          => [ cron_spec   => undef,
28                                                  cron_spec   => '',
29                                                  next_run_at => undef,
30                                                  next_run_at => { le => $now } ] ]);
31
32   return $class->get_all(where => [ or => [ @interval_args, @once_args ] ]);
33 }
34
35 1;