X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBackgroundJob.pm;h=10e319ba396de6ef8cd7a38c3b28e8f41e5e3250;hb=fc35d1dd4441b0dd26fe0b1b397cc66508a715f3;hp=ce1c3991dbfbf722efd1cd7a89d248437fa4a50b;hpb=572adb38daf24b2a8adf0521e8f4920a7d1991ea;p=kivitendo-erp.git diff --git a/SL/DB/BackgroundJob.pm b/SL/DB/BackgroundJob.pm index ce1c3991d..10e319ba3 100644 --- a/SL/DB/BackgroundJob.pm +++ b/SL/DB/BackgroundJob.pm @@ -5,14 +5,15 @@ use strict; use DateTime::Event::Cron; use English qw(-no_match_vars); +use Rose::DB::Object::Helpers qw(as_tree); + 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,13 +38,16 @@ 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 ->new(package_name => $self->package_name, run_at => $run_at, - status => 'success', + status => SL::DB::BackgroundJobHistory::SUCCESS(), result => $result, data => $self->data); $history->save; @@ -56,7 +60,7 @@ sub run { $history = SL::DB::BackgroundJobHistory ->new(package_name => $self->package_name, run_at => $run_at, - status => 'failure', + status => SL::DB::BackgroundJobHistory::FAILURE(), error_col => $error, data => $self->data); $history->save; @@ -77,6 +81,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 +104,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.');