X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FManager%2FBackgroundJob.pm;h=8b2e99aa8f1c965a4d45315e7a25d2e062fe0dc4;hb=053d0c377df96e552ae9bc28c1c1bded0fdfacac;hp=178f9d37a36493e38124e024e80036096a0e2225;hpb=782fd7884fb686cd2e336756dadeb4ab5d05a415;p=kivitendo-erp.git diff --git a/SL/DB/Manager/BackgroundJob.pm b/SL/DB/Manager/BackgroundJob.pm index 178f9d37a..8b2e99aa8 100644 --- a/SL/DB/Manager/BackgroundJob.pm +++ b/SL/DB/Manager/BackgroundJob.pm @@ -2,21 +2,57 @@ package SL::DB::Manager::BackgroundJob; use strict; -use SL::DB::Helpers::Manager; -use base qw(SL::DB::Helpers::Manager); +use SL::DB::Helper::Manager; +use base qw(SL::DB::Helper::Manager); + +use SL::DB::Helper::Paginated; +use SL::DB::Helper::Sorted; + +use SL::System::TaskServer; sub object_class { 'SL::DB::BackgroundJob' } __PACKAGE__->make_manager_methods; +sub _sort_spec { + return ( default => [ 'next_run_at', 1 ], + columns => { SIMPLE => 'ALL' } ); +} + sub cleanup { my $class = shift; $class->delete_all(where => [ and => [ type => 'once', last_run_at => { lt => DateTime->now_local->subtract(days => '1') } ] ]); } sub get_all_need_to_run { - my $class = shift; - return $class->get_all(where => [ and => [ active => 1, next_run_at => { le => DateTime->now_local } ] ]); + my $class = shift; + + my $now = DateTime->now_local; + my @interval_args = (and => [ type => 'interval', + active => 1, + next_run_at => { le => $now } ]); + my @once_args = (and => [ type => 'once', + active => 1, + last_run_at => undef, + or => [ cron_spec => undef, + cron_spec => '', + next_run_at => undef, + next_run_at => { le => $now } ] ]); + my @node_filter; + + my $node_id = SL::System::TaskServer->node_id; + if ($::lx_office_conf{task_server}->{only_run_tasks_for_this_node}) { + @node_filter = (node_id => $node_id); + } else { + @node_filter = ( + or => [ + node_id => undef, + node_id => '', + node_id => $node_id, + ]); + } + + return $class->get_all(query => [ or => [ @interval_args, @once_args ], @node_filter ]); } 1;