1 package SL::DB::Manager::BackgroundJob;
5 use SL::DB::Helper::Manager;
6 use base qw(SL::DB::Helper::Manager);
8 use SL::DB::Helper::Paginated;
9 use SL::DB::Helper::Sorted;
11 use SL::System::TaskServer;
13 sub object_class { 'SL::DB::BackgroundJob' }
15 __PACKAGE__->make_manager_methods;
18 return ( default => [ 'next_run_at', 1 ],
19 columns => { SIMPLE => 'ALL' } );
24 $class->delete_all(where => [ and => [ type => 'once', last_run_at => { lt => DateTime->now_local->subtract(days => '1') } ] ]);
27 sub get_all_need_to_run {
30 my $now = DateTime->now_local;
31 my @interval_args = (and => [ type => 'interval',
33 next_run_at => { le => $now } ]);
34 my @once_args = (and => [ type => 'once',
37 or => [ cron_spec => undef,
40 next_run_at => { le => $now } ] ]);
43 my $node_id = SL::System::TaskServer->node_id;
44 if ($::lx_office_conf{task_server}->{only_run_tasks_for_this_node}) {
45 @node_filter = (node_id => $node_id);
55 return $class->get_all(query => [ or => [ @interval_args, @once_args ], @node_filter ]);