X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBackgroundJob.pm;h=e8ae55bac9a394448ff16695c250b5b6716e72a5;hb=55c51cd5afd63451058373729bd689d7d726d147;hp=ce1c3991dbfbf722efd1cd7a89d248437fa4a50b;hpb=4e4bd8f9d9b5c89d42829011786d3766a0b926bf;p=kivitendo-erp.git diff --git a/SL/DB/BackgroundJob.pm b/SL/DB/BackgroundJob.pm index ce1c3991d..e8ae55bac 100644 --- a/SL/DB/BackgroundJob.pm +++ b/SL/DB/BackgroundJob.pm @@ -8,11 +8,10 @@ use English qw(-no_match_vars); use SL::DB::MetaSetup::BackgroundJob; use SL::DB::Manager::BackgroundJob; -use SL::DB::BackgroundJobHistory; - -use SL::BackgroundJob::Test; use SL::System::Process; +__PACKAGE__->meta->initialize; + __PACKAGE__->before_save('_before_save_set_next_run_at'); sub _before_save_set_next_run_at { @@ -37,7 +36,10 @@ sub run { my $run_at = DateTime->now_local; my $history; + require SL::DB::BackgroundJobHistory; + my $ok = eval { + eval "require $package" or die $@; my $result = $package->new->run($self); $history = SL::DB::BackgroundJobHistory @@ -77,6 +79,16 @@ sub data_as_hash { return {}; } +sub set_data { + my ($self, %data) = @_; + + my $data = YAML::Load($self->data); + $data->{$_} = $data{$_} for keys %data; + $self->data(YAML::Dump($data)); + + $self; +} + sub validate { my ($self) = @_; @@ -90,7 +102,7 @@ sub validate { } eval { - DateTime::Event::Cron->new_from_cron($self->cron_spec)->next(DateTime->now_local); + DateTime::Event::Cron->new_from_cron($self->cron_spec || '* * * * *')->next(DateTime->now_local); 1; } or push @errors, $::locale->text('The execution schedule is invalid.');