init III
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::AsynchronousExecutor;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Daemon::DaemonModules::BaseTaskWorker);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::AsynchronousExecutor - Scheduler daemon task handler module for generic asynchronous tasks
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This task handler executes scheduler generic asynchronous tasks.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
my $TaskHandlerObject = $Kernel::OM->Get('Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::AsynchronousExecutor');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{Debug} = $Param{Debug};
|
||||
$Self->{WorkerName} = 'Worker: AsynchronousExecutor';
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Performs the selected asynchronous task.
|
||||
|
||||
my $Success = $TaskHandlerObject->Run(
|
||||
TaskID => 123,
|
||||
TaskName => 'some name', # optional
|
||||
Data => {
|
||||
Object => 'Some::Object::Name',
|
||||
Function => 'SomeFunctionName',
|
||||
Params => $Params , # HashRef with the needed parameters
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success => 1, # or fail in case of an error
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check task params.
|
||||
my $CheckResult = $Self->_CheckTaskParams(
|
||||
%Param,
|
||||
NeededDataAttributes => [ 'Object', 'Function' ],
|
||||
);
|
||||
|
||||
# Stop execution if an error in params is detected.
|
||||
return if !$CheckResult;
|
||||
|
||||
$Param{Data}->{Params} //= {};
|
||||
|
||||
# Stop execution if invalid params ref is detected.
|
||||
return if !ref $Param{Data}->{Params};
|
||||
|
||||
my $LocalObject;
|
||||
eval {
|
||||
$LocalObject = $Kernel::OM->Get( $Param{Data}->{Object} );
|
||||
};
|
||||
if ( !$LocalObject ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Could not create a new object $Param{Data}->{Object}! - Task: $Param{TaskName}",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Check if the module provide the required function().
|
||||
if ( !$LocalObject->can( $Param{Data}->{Function} ) ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "$Param{Data}->{Object} does not provide $Param{Data}->{Function}()! - Task: $Param{TaskName}",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $Function = $Param{Data}->{Function};
|
||||
|
||||
my $ErrorMessage;
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} executes task: $Param{TaskName}\n";
|
||||
}
|
||||
|
||||
# Run given function on the object with the specified parameters in Data->{Params}
|
||||
eval {
|
||||
|
||||
# Restore child signal to default, main daemon set it to 'IGNORE' to be able to create
|
||||
# multiple process at the same time, but in workers this causes problems if function does
|
||||
# system calls (on linux), since system calls returns -1. See bug#12126.
|
||||
local $SIG{CHLD} = 'DEFAULT';
|
||||
|
||||
# Localize the standard error, everything will be restored after the eval block.
|
||||
local *STDERR;
|
||||
|
||||
# Redirect the standard error to a variable.
|
||||
open STDERR, ">>", \$ErrorMessage;
|
||||
|
||||
if ( ref $Param{Data}->{Params} eq 'ARRAY' ) {
|
||||
$LocalObject->$Function(
|
||||
@{ $Param{Data}->{Params} },
|
||||
);
|
||||
}
|
||||
else {
|
||||
$LocalObject->$Function(
|
||||
%{ $Param{Data}->{Params} // {} },
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
# Check if there are errors.
|
||||
if ($ErrorMessage) {
|
||||
|
||||
$Self->_HandleError(
|
||||
TaskName => $Param{TaskName},
|
||||
TaskType => 'AsynchronousExecutor',
|
||||
LogMessage => "There was an error executing $Function() in $Param{Data}->{Object}: $ErrorMessage",
|
||||
ErrorMessage => $ErrorMessage,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,109 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::CalendarAppointment;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Daemon::DaemonModules::BaseTaskWorker);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Calendar::Appointment',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::CalendarAppointment - Scheduler daemon task handler module for CalendarAppointment
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This task handler executes calendar appointment jobs.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
use Kernel::System::ObjectManager;
|
||||
local $Kernel::OM = Kernel::System::ObjectManager->new();
|
||||
my $TaskHandlerObject = $Kernel::OM-Get('Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::CalendarAppointment');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{Debug} = $Param{Debug};
|
||||
$Self->{WorkerName} = 'Worker: CalendarAppointment';
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
performs the selected task.
|
||||
|
||||
my $Result = $TaskHandlerObject->Run(
|
||||
TaskID => 123,
|
||||
TaskName => 'some name', # optional
|
||||
Data => { # appointment id as got from Kernel::System::Calendar::Appointment::AppointmentGet()
|
||||
NotifyTime => '2016-08-02 03:59:00',
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = 1; # or fail in case of an error
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check task params
|
||||
my $CheckResult = $Self->_CheckTaskParams(
|
||||
%Param,
|
||||
NeededDataAttributes => ['NotifyTime'],
|
||||
);
|
||||
|
||||
# stop execution if an error in params is detected
|
||||
return if !$CheckResult;
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} executes task: $Param{TaskName}\n";
|
||||
}
|
||||
|
||||
# trigger the appointment notification
|
||||
my $Success
|
||||
= $Kernel::OM->Get('Kernel::System::Calendar::Appointment')->AppointmentNotification( %{ $Param{Data} } );
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Could not trigger appointment notification for AppointmentID $Param{Data}->{AppointmentID}!",
|
||||
);
|
||||
}
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,205 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::Cron;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use IPC::Open3;
|
||||
use Symbol;
|
||||
|
||||
use parent qw(Kernel::System::Daemon::DaemonModules::BaseTaskWorker);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Daemon::SchedulerDB',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::Email',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::Cron - Scheduler daemon task handler module for cron like jobs
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This task handler executes scheduler tasks based in cron notation.
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
my $TaskHandlerObject = $Kernel::OM-Get('Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::Cron');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{Debug} = $Param{Debug};
|
||||
$Self->{WorkerName} = 'Worker: Cron';
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Performs the selected Cron task.
|
||||
|
||||
my $Success = $TaskHandlerObject->Run(
|
||||
TaskID => 123,
|
||||
TaskName => 'some name', # optional
|
||||
Data => {
|
||||
Module => 'Kernel::System:::Console:Command::Help',
|
||||
Function => 'Execute',
|
||||
Params => [ # parameters array reference
|
||||
'--force',
|
||||
'--option',
|
||||
'my option',
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Success => 1, # or fail in case of an error
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check task params.
|
||||
my $CheckResult = $Self->_CheckTaskParams(
|
||||
%Param,
|
||||
NeededDataAttributes => [ 'Module', 'Function' ],
|
||||
DataParamsRef => 'ARRAY',
|
||||
);
|
||||
|
||||
# Stop execution if an error in params is detected.
|
||||
return if !$CheckResult;
|
||||
|
||||
my $StartSystemTime = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
|
||||
|
||||
my $ModuleObject;
|
||||
eval {
|
||||
$ModuleObject = $Kernel::OM->Get( $Param{Data}->{Module} );
|
||||
};
|
||||
if ( !$ModuleObject ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Can not create a new Object for Module: '$Param{Data}->{Module}'! - Task: $Param{TaskName}",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
my $Function = $Param{Data}->{Function};
|
||||
|
||||
# Check if the module provide the required function.
|
||||
return if !$ModuleObject->can($Function);
|
||||
|
||||
my @Parameters = @{ $Param{Data}->{Params} || [] };
|
||||
|
||||
# To capture the standard error.
|
||||
my $ErrorMessage;
|
||||
|
||||
my $Result;
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} Executes task: $Param{TaskName}\n";
|
||||
}
|
||||
|
||||
eval {
|
||||
|
||||
# Restore child signal to default, main daemon set it to 'IGNORE' to be able to create
|
||||
# multiple process at the same time, but in workers this causes problems if function does
|
||||
# system calls (on linux), since system calls returns -1. See bug#12126.
|
||||
local $SIG{CHLD} = 'DEFAULT';
|
||||
|
||||
# Localize the standard error, everything will be restored after the eval block.
|
||||
local *STDERR;
|
||||
|
||||
# Redirect the standard error to a variable.
|
||||
open STDERR, ">>", \$ErrorMessage;
|
||||
|
||||
# Disable ANSI terminal colors for console commands, then in case of an error the output
|
||||
# will be clean.
|
||||
# Prevent used once warning, setting the variable as local and then assign the value
|
||||
# in the next statement.
|
||||
local $Kernel::System::Console::BaseCommand::SuppressANSI;
|
||||
$Kernel::System::Console::BaseCommand::SuppressANSI = 1;
|
||||
|
||||
# Run function on the module with the specified parameters in Data->{Params}
|
||||
$Result = $ModuleObject->$Function(
|
||||
@Parameters,
|
||||
);
|
||||
};
|
||||
|
||||
# Get current system time (as soon as the method has been called).
|
||||
my $EndSystemTime = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
|
||||
|
||||
my $IsConsoleCommand;
|
||||
if (
|
||||
substr( $Param{Data}->{Module}, 0, length 'Kernel::System::Console' ) eq 'Kernel::System::Console'
|
||||
&& $Function eq 'Execute'
|
||||
)
|
||||
{
|
||||
$IsConsoleCommand = 1;
|
||||
}
|
||||
|
||||
my $ConsoleCommandFailure;
|
||||
|
||||
# Console commands send 1 as result if fail.
|
||||
if ( $IsConsoleCommand && $Result ) {
|
||||
$ConsoleCommandFailure = 1;
|
||||
}
|
||||
|
||||
my $Success = 1;
|
||||
|
||||
# Check if there are errors.
|
||||
if ( $ErrorMessage || $ConsoleCommandFailure ) {
|
||||
|
||||
$ErrorMessage //= "Console command '$Param{TaskName}' is failed.";
|
||||
|
||||
$Self->_HandleError(
|
||||
TaskName => $Param{TaskName},
|
||||
TaskType => 'Cron',
|
||||
LogMessage => "There was an error executing $Function() in $Param{Data}->{Module}: $ErrorMessage",
|
||||
ErrorMessage => $ErrorMessage,
|
||||
);
|
||||
|
||||
$Success = 0;
|
||||
}
|
||||
|
||||
# Update worker task.
|
||||
$Kernel::OM->Get('Kernel::System::Daemon::SchedulerDB')->RecurrentTaskWorkerInfoSet(
|
||||
LastWorkerTaskID => $Param{TaskID},
|
||||
LastWorkerStatus => $Success,
|
||||
LastWorkerRunningTime => $EndSystemTime - $StartSystemTime,
|
||||
);
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,172 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericAgent;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Daemon::DaemonModules::BaseTaskWorker);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::Daemon::SchedulerDB',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::GenericAgent',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericAgent - Scheduler daemon task handler module for GenericAgent
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This task handler executes generic agent jobs
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
my $TaskHandlerObject = $Kernel::OM-Get('Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericAgent');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{Debug} = $Param{Debug};
|
||||
$Self->{WorkerName} = 'Worker: GenericAgent';
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Performs the selected task.
|
||||
|
||||
my $Result = $TaskHandlerObject->Run(
|
||||
TaskID => 123,
|
||||
TaskName => 'some name', # optional
|
||||
Data => { # job data as got from Kernel::System::GenericAgent::JobGet()
|
||||
Name 'job name',
|
||||
Valid 1,
|
||||
# ...
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = 1; # or fail in case of an error
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# check task params
|
||||
my $CheckResult = $Self->_CheckTaskParams(
|
||||
%Param,
|
||||
NeededDataAttributes => [ 'Name', 'Valid' ],
|
||||
);
|
||||
|
||||
# Stop execution if an error in params is detected.
|
||||
return if !$CheckResult;
|
||||
|
||||
# Skip if job is not valid.
|
||||
return if !$Param{Data}->{Valid};
|
||||
|
||||
my %Job = %{ $Param{Data} };
|
||||
|
||||
my $StartSystemTime = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
|
||||
|
||||
# Check if last run was less than 1 minute ago.
|
||||
if (
|
||||
$Job{ScheduleLastRunUnixTime}
|
||||
&& $StartSystemTime - $Job{ScheduleLastRunUnixTime} < 60
|
||||
)
|
||||
{
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "GenericAgent Job: $Job{Name}, was already executed less than 1 minute ago!",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
|
||||
|
||||
my $TicketLimit = $ConfigObject->Get('Daemon::SchedulerGenericAgentTaskManager::TicketLimit') || 0;
|
||||
my $SleepTime = $ConfigObject->Get('Daemon::SchedulerGenericAgentTaskManager::SleepTime') || 0;
|
||||
|
||||
my $Success;
|
||||
my $ErrorMessage;
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} executes task: $Param{TaskName}\n";
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
# Restore child signal to default, main daemon set it to 'IGNORE' to be able to create
|
||||
# multiple process at the same time, but in workers this causes problems if function does
|
||||
# system calls (on linux), since system calls returns -1. See bug#12126.
|
||||
local $SIG{CHLD} = 'DEFAULT';
|
||||
|
||||
# Localize the standard error, everything will be restored after the eval block.
|
||||
local *STDERR;
|
||||
|
||||
# Redirect the standard error to a variable.
|
||||
open STDERR, ">>", \$ErrorMessage;
|
||||
|
||||
$Success = $Kernel::OM->Get('Kernel::System::GenericAgent')->JobRun(
|
||||
Job => $Job{Name},
|
||||
Limit => $TicketLimit,
|
||||
SleepTime => $SleepTime,
|
||||
UserID => 1,
|
||||
);
|
||||
};
|
||||
|
||||
# Get current system time (as soon as the job finish to run).
|
||||
my $EndSystemTime = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
|
||||
|
||||
if ( !$Success ) {
|
||||
|
||||
$ErrorMessage ||= "$Job{Name} execution failed without an error message!";
|
||||
|
||||
$Self->_HandleError(
|
||||
TaskName => $Job{Name},
|
||||
TaskType => 'GenericAgent',
|
||||
LogMessage => "There was an error executing $Job{Name}: $ErrorMessage",
|
||||
ErrorMessage => "$ErrorMessage",
|
||||
);
|
||||
}
|
||||
|
||||
# Update worker task.
|
||||
$Kernel::OM->Get('Kernel::System::Daemon::SchedulerDB')->RecurrentTaskWorkerInfoSet(
|
||||
LastWorkerTaskID => $Param{TaskID},
|
||||
LastWorkerStatus => $Success,
|
||||
LastWorkerRunningTime => $EndSystemTime - $StartSystemTime,
|
||||
);
|
||||
|
||||
return $Success;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
@@ -0,0 +1,200 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericInterface;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Daemon::DaemonModules::BaseTaskWorker);
|
||||
|
||||
use Kernel::System::VariableCheck qw(:all);
|
||||
|
||||
use Storable;
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::GenericInterface::Requester',
|
||||
'Kernel::System::DateTime',
|
||||
'Kernel::System::GenericInterface::Webservice',
|
||||
'Kernel::System::Log',
|
||||
'Kernel::System::Scheduler',
|
||||
);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericInterface - Scheduler daemon task handler module for GenericInterface
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This task handler executes scheduler tasks delegated by asynchronous invoker configuration
|
||||
|
||||
=head1 PUBLIC INTERFACE
|
||||
|
||||
=head2 new()
|
||||
|
||||
my $TaskHandlerObject = $Kernel::OM-Get('Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker::GenericInterface');
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ( $Type, %Param ) = @_;
|
||||
|
||||
my $Self = {};
|
||||
bless( $Self, $Type );
|
||||
|
||||
$Self->{Debug} = $Param{Debug};
|
||||
$Self->{WorkerName} = 'Worker: GenericInterface';
|
||||
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head2 Run()
|
||||
|
||||
Performs the selected Task, causing an Invoker call via GenericInterface.
|
||||
|
||||
my $Result = $TaskHandlerObject->Run(
|
||||
TaskID => 123,
|
||||
TaskName => 'some name', # optional
|
||||
Data => {
|
||||
WebserviceID => $WebserviceID,
|
||||
Invoker => 'configured_invoker',
|
||||
Data => { # data payload for the Invoker
|
||||
...
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Returns:
|
||||
|
||||
$Result = 1; # or fail in case of an error
|
||||
|
||||
=cut
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
# Check task params.
|
||||
my $CheckResult = $Self->_CheckTaskParams(
|
||||
NeededDataAttributes => [ 'WebserviceID', 'Invoker', 'Data' ],
|
||||
%Param,
|
||||
);
|
||||
return if !$CheckResult;
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} executes task: $Param{TaskName}\n";
|
||||
}
|
||||
|
||||
my $Result = $Kernel::OM->Get('Kernel::GenericInterface::Requester')->Run(
|
||||
WebserviceID => $Param{Data}->{WebserviceID},
|
||||
Invoker => $Param{Data}->{Invoker},
|
||||
Asynchronous => 1,
|
||||
Data => Storable::dclone( $Param{Data}->{Data} ),
|
||||
PastExecutionData => $Param{Data}->{PastExecutionData},
|
||||
);
|
||||
return 1 if $Result->{Success};
|
||||
|
||||
my $Webservice = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice')->WebserviceGet(
|
||||
ID => $Param{Data}->{WebserviceID},
|
||||
);
|
||||
|
||||
my $WebServiceName = $Webservice->{Name} // 'N/A';
|
||||
|
||||
# No further retries for request.
|
||||
if (
|
||||
!IsHashRefWithData( $Result->{Data} )
|
||||
|| !$Result->{Data}->{ReSchedule}
|
||||
)
|
||||
{
|
||||
my $ErrorMessage
|
||||
= $Result->{ErrorMessage} || "$Param{Data}->{Invoker} execution failed without an error message";
|
||||
|
||||
$Self->_HandleError(
|
||||
TaskName => "$Param{Data}->{Invoker} WebService: $WebServiceName",
|
||||
TaskType => 'GenericInterface',
|
||||
LogMessage => "There was an error executing $Param{Data}->{Invoker} ($WebServiceName): $ErrorMessage",
|
||||
ErrorMessage => "$ErrorMessage",
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Schedule request for another try.
|
||||
|
||||
# Use the execution time from the return data (if any).
|
||||
my $ExecutionTime = $Result->{Data}->{ExecutionTime};
|
||||
my $ExecutionDateTime;
|
||||
|
||||
# Check if execution time is valid.
|
||||
if ( IsStringWithData($ExecutionTime) ) {
|
||||
|
||||
$ExecutionDateTime = $Kernel::OM->Create(
|
||||
'Kernel::System::DateTime',
|
||||
ObjectParams => {
|
||||
String => $ExecutionTime,
|
||||
},
|
||||
);
|
||||
if ( !$ExecutionDateTime ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message =>
|
||||
"WebService $WebServiceName, Invoker $Param{Data}->{Invoker} returned invalid execution time $ExecutionTime. Falling back to default!",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# Set default execution time.
|
||||
if ( !$ExecutionTime || !$ExecutionDateTime ) {
|
||||
|
||||
# Get default time difference from config.
|
||||
my $FutureTaskTimeDiff = int(
|
||||
$Kernel::OM->Get('Kernel::Config')->Get('Daemon::SchedulerGenericInterfaceTaskManager::FutureTaskTimeDiff')
|
||||
)
|
||||
|| 300;
|
||||
|
||||
$ExecutionDateTime = $Kernel::OM->Create('Kernel::System::DateTime');
|
||||
$ExecutionDateTime->Add( Seconds => $FutureTaskTimeDiff );
|
||||
}
|
||||
|
||||
if ( $Self->{Debug} ) {
|
||||
print " $Self->{WorkerName} re-schedule task: $Param{TaskName} for: $ExecutionDateTime->ToString()\n";
|
||||
}
|
||||
|
||||
# Create a new task (replica) that will be executed in the future.
|
||||
my $Success = $Kernel::OM->Get('Kernel::System::Scheduler')->TaskAdd(
|
||||
ExecutionTime => $ExecutionDateTime->ToString(),
|
||||
Type => 'GenericInterface',
|
||||
Name => $Param{TaskName},
|
||||
Attempts => 10,
|
||||
Data => {
|
||||
%{ $Param{Data} },
|
||||
PastExecutionData => $Result->{Data}->{PastExecutionData},
|
||||
},
|
||||
);
|
||||
|
||||
if ( !$Success ) {
|
||||
$Kernel::OM->Get('Kernel::System::Log')->Log(
|
||||
Priority => 'error',
|
||||
Message => "Could not re-schedule a task in future for task $Param{TaskName}",
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=head1 TERMS AND CONDITIONS
|
||||
|
||||
This software is part of the OTRS project (L<https://otrs.org/>).
|
||||
|
||||
This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
the enclosed file COPYING for license information (GPL). If you
|
||||
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user