[rt-devel] Linear priority escalation
Stanislav Sinyagin
ssinyagin at yahoo.com
Wed Jul 16 10:21:30 EDT 2003
Hi,
The priority escalation module in RT3 distribution (RT::Action::EscalatePriority)
uses the escalation formula
Priority = Priority + (( FinalPriority - Priority ) / ( DueDate-Today))
which is not linear and not suitable for short due periods:
In our case, the final priority is 10, and the due date is 2 days.
We want the priority to escalate linearly from 0 to 10 every few
hours during these two days.
See the new module (attached), which uses the formula
Priority = FinalPriority * (Now-Starts) / (DueDate-Starts)
Regards,
Stanislav
-------------- next part --------------
# BEGIN LICENSE BLOCK
#
# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
# Modified version of RT::Action::EscalatePriority
# (c) Stanislav Sinyagin <ssinyagin at yahoo.com>
#
# (Except where explictly superceded by other copyright notices)
#
# This work is made available to you under the terms of Version 2 of
# the GNU General Public License. A copy of that license should have
# been provided with this software, but in any event can be snarfed
# from www.gnu.org.
#
# This work is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Unless otherwise specified, all modifications, corrections or
# extensions to this work which alter its source code become the
# property of Best Practical Solutions, LLC when submitted for
# inclusion in the work.
#
#
# END LICENSE BLOCK
=head1 NAME
RT::Action::EscalatePriorityLinear
=head1 DESCRIPTION
EscalatePriorityLinear is a ScripAction which is NOT intended to be called per
transaction. It's intended to be called by an RT escalation daemon.
(The daemon is called escalator).
EsclatePriorityLinear uses the following formula to change a ticket's priority:
Priority = FinalPriority * (Now-Starts) / (DueDate-Starts)
Unless the duedate is past, in which case priority gets bumped straight
to final priority.
Unlike RT::Action::EscalatePriority, priority is not decreased
if it's above FinalPriority.
=cut
package RT::Action::EscalatePriorityLinear;
require RT::Action::Generic;
use strict;
use vars qw/@ISA/;
@ISA=qw(RT::Action::Generic);
#Do what we need to do and send it out.
#What does this type of Action does
# {{{ sub Describe
sub Describe {
my $self = shift;
return (ref $self . " will move a ticket's priority toward its final priority linearly.");
}
# }}}
# {{{ sub Prepare
sub Prepare {
my $self = shift;
if ($self->TicketObj->Priority() >= $self->TicketObj->FinalPriority()) {
# no update necessary.
return 0;
}
my $due = $self->TicketObj->DueObj()->Unix();
# The ticket start is either "Starts" or "Created"
my $starts = $self->TicketObj->StartsObj()->Unix();
if( $starts < 1 ) {
my $time = new RT::Date( $self->TicketObj->CurrentUser );
$time->Set( Format => 'sql', Value => $self->TicketObj->Created );
$starts = $time->Unix();
}
# If we don't have a due date, increase the priority by one
# until we hit the final priority
if ($due < 1 || $starts < 1) {
if ( $self->TicketObj->Priority < $self->TicketObj->FinalPriority ){
$self->{'prio'} = ($self->TicketObj->Priority + 1);
return 1;
}
else {
return 0;
}
}
# we've got a due date. now there are other things we should do
else {
my $now = time();
if( $due > $now ) {
$self->{'prio'} = int( $self->TicketObj->FinalPriority() *
($now - $starts) / ($due - $starts));
}
else {
$self->{'prio'} = $self->TicketObj->FinalPriority();
}
}
return 1;
}
# }}}
sub Commit {
my $self = shift;
my ($val, $msg) = $self->TicketObj->SetPriority($self->{'prio'});
unless ($val) {
$RT::Logger->debug($self . " $msg\n");
}
}
eval "require RT::Action::EscalatePriorityLinear_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriorityLinear_Vendor.pm});
eval "require RT::Action::EscalatePriorityLinear_Local";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/EscalatePriorityLinear_Local.pm});
1;
More information about the Rt-devel
mailing list