Revision d83769ec
Von Moritz Bunkus vor mehr als 5 Jahren hinzugefügt
SL/Controller/BackgroundJob.pm | ||
---|---|---|
8 | 8 |
use SL::Controller::Helper::GetModels; |
9 | 9 |
use SL::DB::BackgroundJob; |
10 | 10 |
use SL::Helper::Flash; |
11 |
use SL::JSON; |
|
11 | 12 |
use SL::Locale::String; |
12 | 13 |
use SL::System::TaskServer; |
13 | 14 |
|
... | ... | |
118 | 119 |
back_to => $self->url_for(action => 'edit', id => $self->background_job->id)); |
119 | 120 |
} |
120 | 121 |
|
122 |
sub action_execute_class { |
|
123 |
my ($self) = @_; |
|
124 |
|
|
125 |
my $result; |
|
126 |
|
|
127 |
my $ok = eval { |
|
128 |
die "no class name given in parameter 'class'" if !$::form->{class} || ($::form->{class} =~ m{[^a-z0-9]}i); |
|
129 |
die "invalid class" if ! -f "SL/BackgroundJob/" . $::form->{class} . ".pm"; |
|
130 |
|
|
131 |
my $package = "SL::BackgroundJob::" . $::form->{class}; |
|
132 |
|
|
133 |
eval "require $package" or die $@; |
|
134 |
$result = $package->new->run(SL::DB::BackgroundJob->new); |
|
135 |
|
|
136 |
1; |
|
137 |
}; |
|
138 |
|
|
139 |
my $reply = { |
|
140 |
status => $ok ? 'succeeded' : 'failed', |
|
141 |
result => $ok ? $result : $@, |
|
142 |
}; |
|
143 |
|
|
144 |
$self->render(\to_json($reply), { type => 'json' }); |
|
145 |
} |
|
146 |
|
|
121 | 147 |
# |
122 | 148 |
# filters |
123 | 149 |
# |
Auch abrufbar als: Unified diff
Hintergrundjobs: Controller-Action zur einmaligen Ausführung eines Jobs
Gedacht für Aufruf von extern, gibt JSON zurück. Beispiel:
curl --silent --user "<username>:<password>" \
'https://<hostname>/kivitendo/controller.pl?action=BackgroundJob/execute_class&class=CleanAuthSessions'