Conveyor/Ticket/Dispatcher.pm

filter: Statementstmt 39.2% 20 / 51 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 100% 3 / 3 totaltotal 33.7% 30 / 89 CC 11 SCAR 33.4
CC
11
Cov
28%
finish_ticket
72.0
dispatch
6.0
__ANON__
6.0
CRAP 28.2
« Conveyor/Service/Methods.pm ↑ Summary Conveyor/Ticket/Provider.pm »
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Conveyor::Ticket::Dispatcher;
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Data::Conveyor::Ticket::Dispatcher::VERSION = '1.103130';
8 }
9 # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10  
11 2 ▶use Error ':try';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use parent 'Class::Scaffold::Storable';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use constant DEFAULTS => (transactional_authority => 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 __PACKAGE__->mk_scalar_accessors(qw(stage))
15 ->mk_framework_object_accessors(ticket => 'ticket')
16 ->mk_boolean_accessors(qw(transactional_authority));
17  
18 0 ▶sub dispatch {
Subroutine dispatch: not called CC=2 SCAR=17.9
Pod documented
19 0 my $self = shift;
20 0 ▶ $self->ticket(+shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
21 0 my $stage_name = $self->ticket->stage->name;
22 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
23 0 $self->stage($self->delegate->make_stage_object($stage_name));
24 0 ▶ $self->stage->ticket($self->ticket) if $self->stage->can('ticket');
Branch: 1 branch
BranchTrueFalseTotal
if $self->stage->can("ticket") 0 0 0
25 0 $self->stage->run;
26 0 $self->finish_ticket;
27 }
28 0 ▶ catch Error with {
Subroutine __ANON__: not called CC=2 SCAR=17.9
29 0 my $E = shift;
30 0 ▶ throw $E unless $self->transactional_authority;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->transactional_authority 0 0 0
31 0 require Data::Dumper;
32 0 local $Data::Dumper::Indent = 1;
33 0 throw Error::Hierarchy::Internal::CustomMessage(
34 custom_message => sprintf(
35 'exception while processing stage [%s]: %s',
36 $stage_name, Data::Dumper::Dumper($E)
37 )
38 );
39 0 };
40 }
41  
42 # Close_ticket is a method so subclasses get a chance to do additional things.
43 0 ▶sub close_ticket {
Subroutine close_ticket: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self = shift;
45 0 $self->ticket->close;
46 }
47  
48 0 ▶sub finish_ticket {
Subroutine finish_ticket: not called CC=8 SCAR=42.8
Pod documented
49 0 my $self = shift;
50  
51 # If there's an internal error, rollback any actions done so far (e.g.,
52 # half-finished delegations). However, do store the errors and leave the
53 # ticket with RC_INTERNAL_ERROR. To do so, we explicitly store and close
54 # the ticket after the rollback. Without doing so, the ticket wouldn't be
55 # closed and would remain in 'aktiv_*', plus the errors wouldn't be
56 # recorded.
57 #
58 # If the ticket has TS_RUNNING (regardless of the rc, which could be RC_OK
59 # or RC_ERROR), we close and shift the ticket; in any other case (e.g.,
60 # TS_HOLD), we close the ticket, but don't shift it.
61 0 ▶ if ($self->ticket->rc eq $self->delegate->RC_INTERNAL_ERROR) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ticket->rc eq $self->delegate->RC_INTERNAL_ERROR) { } 0 0 0
elsif ($self->ticket->status eq $self->delegate->TS_RUNNING) { } 0 0 0
62  
63 # special case for conveyor/epp: we want the container to be
64 # thrown. the engine will log a dump of the ticket and roll it
65 # back.
66 0 my $container =
67 $self->ticket->filter_exceptions_by_rc(
68 $self->delegate->RC_INTERNAL_ERROR);
69 0 $self->log->info($container);
70 0 ▶ if ($self->transactional_authority) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->transactional_authority) { } 0 0 0
71 0 $self->delegate->rollback;
72 0 $self->ticket->store;
73 0 $self->close_ticket;
74 } else {
75 0 throw $container;
76 }
77 } elsif ($self->ticket->status eq $self->delegate->TS_RUNNING) {
78 0 $self->close_ticket;
79 0 ▶ $self->ticket->shift_stage if $self->stage->will_shift_ticket;
Branch: 1 branch
BranchTrueFalseTotal
if $self->stage->will_shift_ticket 0 0 0
80 } else {
81 0 $self->close_ticket;
82 }
83  
84 # the conveyor needs the possibility to leave rollback/commit to a
85 # higher instance.
86 0 ▶ return unless $self->transactional_authority;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->transactional_authority 0 0 0
87  
88 # We need to commit or rollback the changes made while this ticket was
89 # processed, because the dispatcher processes a potentially large number
90 # of tickets and we wouldn't rollback everything just because the 300th
91 # ticket has a problem. Besides, committing is necessary for the ticket
92 # provider to keep handing out tickets to other processes (since the
93 # transaction under which the database changes are done are limited to
94 # this process only.
95 # Class::Scaffold::App::Test sets the rollback_mode, which is ok since we
96 # want the storages to respect that. But at this point we want to
97 # commit in test mode regardless of whether rollback_mode is set (so
98 # integration tests work).
99 0 ▶ if ($self->delegate->rollback_mode && !$self->delegate->test_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->delegate->rollback_mode and not $self->delegate->test_mode) { } 0 0 0
Condition0%0/3
$self->delegate->rollback_mode and not $self->delegate->test_mode
!ll&&!rl&&r
000
MC/DC0%0/2
$self->delegate->rollback_mode and not $self->delegate->test_mode
$self->delegate->rollback_mode not $self->delegate->test_mode
Truth table0%0/3
A and not(B)
A= $self->delegate->rollback_modeB= not $self->delegate->test_mode
ABresult
0X0
100
111
100 0 $self->delegate->rollback;
101 } else {
102 0 $self->delegate->commit;
103 }
104 }
105 2 1;
106  
107  
108 __END__
« Conveyor/Service/Methods.pm ↑ Summary Conveyor/Ticket/Provider.pm »