Projekt

Allgemein

Profil

Herunterladen (1,68 KB) Statistiken
| Zweig: | Markierung: | Revision:
782fd788 Moritz Bunkus
package SL::DB::Manager::BackgroundJob;

use strict;

ea65e003 Moritz Bunkus
use SL::DB::Helper::Manager;
use base qw(SL::DB::Helper::Manager);
782fd788 Moritz Bunkus
220746bf Moritz Bunkus
use SL::DB::Helper::Paginated;
a16a7068 Moritz Bunkus
use SL::DB::Helper::Sorted;

a354dfce Moritz Bunkus
use SL::System::TaskServer;

782fd788 Moritz Bunkus
sub object_class { 'SL::DB::BackgroundJob' }

__PACKAGE__->make_manager_methods;

a16a7068 Moritz Bunkus
sub _sort_spec {
return ( default => [ 'next_run_at', 1 ],
columns => { SIMPLE => 'ALL' } );
}

782fd788 Moritz Bunkus
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 {
ee71ba33 Moritz Bunkus
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 } ] ]);
a354dfce Moritz Bunkus
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 ]);
782fd788 Moritz Bunkus
}

1;