projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Module: gebundletes YAML durch dünnen Wrapper über YAML::XS & YAML ersetzt
[kivitendo-erp.git]
/
SL
/
DB
/
BackgroundJob.pm
diff --git
a/SL/DB/BackgroundJob.pm
b/SL/DB/BackgroundJob.pm
index
ce1c399
..
1fc8d99
100644
(file)
--- a/
SL/DB/BackgroundJob.pm
+++ b/
SL/DB/BackgroundJob.pm
@@
-5,13
+5,15
@@
use strict;
use DateTime::Event::Cron;
use English qw(-no_match_vars);
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::MetaSetup::BackgroundJob;
use SL::DB::Manager::BackgroundJob;
-use SL::DB::BackgroundJobHistory;
-
-use SL::BackgroundJob::Test;
use SL::System::Process;
use SL::System::Process;
+use SL::YAML;
+
+__PACKAGE__->meta->initialize;
__PACKAGE__->before_save('_before_save_set_next_run_at');
__PACKAGE__->before_save('_before_save_set_next_run_at');
@@
-37,13
+39,16
@@
sub run {
my $run_at = DateTime->now_local;
my $history;
my $run_at = DateTime->now_local;
my $history;
+ require SL::DB::BackgroundJobHistory;
+
my $ok = eval {
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,
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;
result => $result,
data => $self->data);
$history->save;
@@
-56,7
+61,7
@@
sub run {
$history = SL::DB::BackgroundJobHistory
->new(package_name => $self->package_name,
run_at => $run_at,
$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;
error_col => $error,
data => $self->data);
$history->save;
@@
-71,12
+76,26
@@
sub run {
sub data_as_hash {
my $self = shift;
sub data_as_hash {
my $self = shift;
+
+ $self->data(SL::YAML::Dump($_[0])) if @_;
+
return {} if !$self->data;
return $self->data if ref($self->{data}) eq 'HASH';
return {} if !$self->data;
return $self->data if ref($self->{data}) eq 'HASH';
- return YAML::Load($self->{data}) if !ref($self->{data});
+ return
SL::
YAML::Load($self->{data}) if !ref($self->{data});
return {};
}
return {};
}
+sub set_data {
+ my ($self, %data) = @_;
+
+ $self->data(SL::YAML::Dump({
+ %{ $self->data_as_hash },
+ %data,
+ }));
+
+ $self;
+}
+
sub validate {
my ($self) = @_;
sub validate {
my ($self) = @_;
@@
-90,7
+109,7
@@
sub validate {
}
eval {
}
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.');
1;
} or push @errors, $::locale->text('The execution schedule is invalid.');