NAME
cPanel::TaskQueue::Processor - Processes an individual task from the cPanel::TaskQueue.
VERSION
This document describes cPanel::TaskQueue::Processor version 0.606.
SYNOPSIS
package NewTask;
use base 'cPanel::TaskQueue::Processor';
sub process_task {
my ($self, $task) = @_;
# do something exciting.
return;
}
sub is_valid_args {
my ($self, $task) = @_;
# all args must be numeric
return !grep { /[^-\d]/ } $task->args();
}
DESCRIPTION
This module provides an abstraction for commands to be executed from/by the TaskQueue. It is used as a base class to provide default behavior for every method except process_task
that is used by the cPanel::TaskQueue
.
PUBLIC METHODS
- cPanel::TaskQueue::Processor->new
-
Create a new
cPanel::TaskQueue::Processor
object. - $proc->is_dupe( $task_a, $task_b )
-
Return true if the two supplied
cPanel::TaskQueue::Task
objects are equivalent. The parameters are guaranteed not to beundef
.The method should return a true value if the parameters are duplicates and a false value if they are not. If the method fails for some reason, throw an exception.
A subclass might want to override this to give more specific processing. The default definition is to check if the arguments for the two supplied task descriptors is the same. If so, return true, else return
undef
. - $proc->overrides( $new_task, $old_task )
-
Return true if the new_task
cPanel::TaskQueue::Task
object should override the old_task object. The parameters are guaranteed not to beundef
.The method should return a true value if there is no need to execute the old_task since the new_task results will override whatever old_task was going to do. For example, if the old task changes a user's password, and the new task deletes that user, there is no need to run the first task. Otherwise the method should return a false value. If the method fails for some reason, throw an exception.
A subclass might want to override this to give more specific processing. The default definition is aways return
undef
. - $proc->is_valid_args( $task )
-
Return true if the arguments in the supplied cPanel::TaskQueue::Task are valid for this task. The parameter is guaranteed not to be
undef
.The method should return a true value if the supplied task has valid arguments for the command, otherwise it should return false. If the method fails for some reason, the method should throw an exception.
A subclass will probably want to override this method for more specific processing. The default definition is to return true regardless of the state of the supplied task descriptor.
- $proc->process_task( $task, $logger )
-
Perform the task that is described by the supplied cPanel::TaskQueue::Task. The parameter is guaranteed not to be
undef
. The$logger
parameter is an object providing logging facilities for the system. See "#LOGGER OBJECT" in cPanel::TaskQueue for the interface of this object.This method should return a 0 if the code processing is complete. If the processing spawns a child to handle the work, the method should return the pid of the child. If the processing fails, it should throw an exception.
A subclass must override this method to get any processing. The default throws an exception if called.
- $proc->get_timeout()
-
Return the number of seconds before the task should be considered timed out. The default method returns
undef
. Any false value uses whatever the default value for the TaskQueue defines. A subclass may override this method to provide a longer time out value for cases where the processing is known to take some time. -
Return a list of tags that that the supplied
$task
defers. - $proc->is_task_deferred( $task, $defer_hash )
-
Check the supplied
$task
against the$defer_hash
to decide if the task should be deferred. Return atrue
value if the task should be deferred, false otherwise.
UTILITY METHODS
This section describes convenience methods that may be useful to classes derived from the Processor
class.
- $proc->checked_system( $hashref )
-
In many cases, the task to be processed depends on running another program. Since handling the return code from
system
is annoying, it often gets ignored. This method calls the core system routine, and checks the return code. It logs an appropriate message for error conditions and is quiet on success.checked_system
returns the same return code assystem
.The method expects a
hash ref
describing the request. The parameters in the hash ref are:- logger
-
This required parameter should provide an object following the logging interface described in "#LOGGER OBJECT" in cPanel::TaskQueue. If this parameter is missing, the method throws an exception.
- name
-
This required parameter provides a name used in any error messages. If this parameter is missing, the method throws an exception.
- cmd
-
This required parameter provides the command that system is to execute. If this parameter is missing, the method throws an exception.
- args
-
This optional parameter is an array reference containing the parameters to pass with the command to the
system
call. If this parameter is missing, an empty list is assumed.
DIAGNOSTICS
No processing has been specified for this task.
-
Either this base class has been used directly as a processor for a command or the
process_task
method was not overridden in a derived class.In either case, the default behavior for
process_task
is to throw an exception.
CONFIGURATION AND ENVIRONMENT
cPanel::TaskQueue::Processor requires no configuration files or environment variables.
DEPENDENCIES
None.
SEE ALSO
cPanel::TaskQueue, cPanel::TaskQueue::Task
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been reported.
AUTHOR
G. Wade Johnson wade@cpanel.net
LICENCE AND COPYRIGHT
Copyright (c) 2014, cPanel, Inc. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.