| 1 | package Zapp::Controller::Run; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Controller', -signatures; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::JSON qw( decode_json encode_json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mojo::Loader qw( data_section ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Zapp::Task; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Zapp::Util qw( build_data_from_params ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub _get_run_tasks( $self, $run_id, $filter={} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_run_tasks: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | my @run_tasks; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my @tasks = $self->app->get_tasks( zapp_run_tasks => { %$filter, run_id => $run_id } ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # XXX: Need to be run through type method | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my $run = $self->yancy->get( zapp_runs => $run_id ) || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->yancy->get('zapp_runs', $run_id) || {}
MC/DC0%0/1
$self->yancy->get('zapp_runs', $run_id) || {}
$self->yancy->get('zapp_runs', $run_id)
Truth table0%0/2
A
A= $self->yancy->get('zapp_runs', $run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $input = decode_json( $run->{input} ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | my %context = ( | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | map { $_->{name} => decode_json( $_->{output} ) } | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | grep { $_->{state} eq 'finished' } @tasks | |||||||||||||||||||||||||||||||||||||||||
| 20 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | map { $_->{name} => $_->{value} } @$input | |||||||||||||||||||||||||||||||||||||||||
| 23 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | for my $task ( @tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $task->{input} = decode_json( $task->{input} ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $task->{output} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $task->{output} = decode_json( $task->{output} ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( $task->{state} ne 'inactive' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Instantiate the job to process the input. Can't use minion | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # as the minion job may have been deleted by now. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | my $job = $task->{class}->new( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | minion => $self->minion, | |||||||||||||||||||||||||||||||||||||||||
| 37 | # Pre-fill caches to avoid database lookups | ||||||||||||||||||||||||||||||||||||||||||
| 38 | zapp_run => $run, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | zapp_task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | _context => \%context, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $task->{input} = $job->process_input( $task->{input} ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return \@tasks, | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | ▶ | sub _get_run( $self, $run_id ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_run: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $run = $self->yancy->get( zapp_runs => $run_id ) || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->yancy->get('zapp_runs', $run_id) || {}
MC/DC0%0/1
$self->yancy->get('zapp_runs', $run_id) || {}
$self->yancy->get('zapp_runs', $run_id)
Truth table0%0/2
A
A= $self->yancy->get('zapp_runs', $run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( my $run_id = $run->{run_id} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $run->{input} = decode_json( $run->{input} ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $run->{output} = decode_json( $run->{output} // '{}' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$run->{"output"} // "{}"
MC/DC0%0/1
$run->{"output"} // "{}"
$run->{"output"}
Truth table0%0/2
A
A= $run->{"output"}
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $run->{tasks} = $self->_get_run_tasks( $run_id ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $run; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | ▶ | sub create_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( my $plan_id = $self->param( 'plan_id' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $plan = $self->app->get_plan( $plan_id ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | %params = ( | ||||||||||||||||||||||||||||||||||||||||||
| 64 | name => $plan->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | description => $plan->{description}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | inputs => $plan->{inputs}, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | tasks => $plan->{tasks}, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ( my $run_id = $self->param( 'run_id' ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $run = $self->_get_run( $run_id ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | %params = ( | ||||||||||||||||||||||||||||||||||||||||||
| 73 | name => $run->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | description => $run->{description}, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | inputs => $run->{input}, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | tasks => $run->{tasks}, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $self->render( 'zapp/run/create', %params ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | ▶ | sub save_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_run: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $input_fields = build_data_from_params( $self, 'input' ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my @run_input; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | for my $i ( 0..$#$input_fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $input = $input_fields->[ $i ]; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $input->{config} &&= decode_json( $input->{config} ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$input->{"config"} &&= decode_json($input->{"config"})
MC/DC0%0/2
$input->{"config"} &&= decode_json($input->{"config"})
$input->{"config"}
decode_json($input->{"config"})
Truth table0%0/3
A &&= B
A= $input->{"config"}B= decode_json($input->{"config"})
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | my $type = $self->app->zapp->types->{ $input->{type} } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | or die qq{Could not find type "$input->{type}"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | push @run_input, { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | name => $input->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | type => $input->{type}, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | config => $input->{config}, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | value => $type->process_input( $self, $input->{config}, $input->{value} ), | |||||||||||||||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $run; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( my $plan_id = $self->param( 'plan_id' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $run = $self->app->enqueue_plan( $plan_id, { map { $_->{name} => $_->{value} } @run_input } ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | elsif ( my $run_id = $self->param( 'run_id' ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( my $task_id = $self->param( 'task_id' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $opt{ task_id } = $task_id; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $run = $self->app->enqueue_run( $run_id, \@run_input, %opt ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->redirect_to( 'zapp.get_run' => { run_id => $run->{run_id} } ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | ▶ | sub get_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_run: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $run_id = $self->stash( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $run = $self->_get_run( $run_id ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( $run->{started} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $run->{started} = Time::Piece->new( $run->{started} )->strftime( '%Y-%m-%d %H:%M:%S' ); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( $run->{finished} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $run->{finished} = Time::Piece->new( $run->{finished} )->strftime( '%Y-%m-%d %H:%M:%S' ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # Find any actions that are waiting | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my @actions; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | for my $task ( grep { $_->{state} eq 'waiting' } $run->{tasks}->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | next unless $task->{class}->isa( 'Zapp::Task::Action' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $job = $task->{class}->new( minion => $self->minion ); | |||||||||||||||||||||||||||||||||||||||||
| 130 | push @actions, { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | action_field => $job->action_field( $self, $task->{input} ), | |||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | $self->render( | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | 'zapp/run/view', | |||||||||||||||||||||||||||||||||||||||||
| 138 | run => $run, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | actions => \@actions, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | ▶ | sub save_task_action( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_task_action: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $run_id = $self->param( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $task_id = $self->param( 'task_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ( $task ) = $self->_get_run_tasks( $run_id, { task_id => $task_id } )->@*; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | die "Task $task_id not found\n" if !$task; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | die "Task is not waiting for an action\n" unless $task->{state} eq 'waiting'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $job = $self->minion->job( $task->{job_id} ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $form_input = build_data_from_params( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $job->action( $self, @{ $job->args }, $form_input ); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return $self->redirect_to( 'zapp.get_run' => { run_id => $run_id } ); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | ▶ | sub stop_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop_run: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $run_id = $self->stash( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $run = $self->_get_run( $run_id ) || return $self->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_run($run_id) || (return $self->reply->not_found)
MC/DC0%0/1
$self->_get_run($run_id) || (return $self->reply->not_found)
$self->_get_run($run_id)
Truth table0%0/2
A
A= $self->_get_run($run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ( $self->req->method eq 'GET' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $self->render( | |||||||||||||||||||||||||||||||||||||||||
| 161 | 'zapp/run/note', | ||||||||||||||||||||||||||||||||||||||||||
| 162 | heading => 'Stop Run', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | next => 'zapp.stop_run_confirm', | ||||||||||||||||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # Add the note | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $self->yancy->create( zapp_run_notes => { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $run->%{qw( run_id )}, | |||||||||||||||||||||||||||||||||||||||||
| 170 | event => 'stop', | ||||||||||||||||||||||||||||||||||||||||||
| 171 | note => $self->param( 'note' ), | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # Stop inactive jobs | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | for my $task ( $run->{tasks}->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $job_id = $task->{job_id}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $job = $self->minion->job( $job_id ) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->minion->job($job_id) || (next)
MC/DC0%0/1
$self->minion->job($job_id) || (next)
$self->minion->job($job_id)
Truth table0%0/2
A
A= $self->minion->job($job_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | next if $job->info->{state} ne 'inactive'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $job->remove; | |||||||||||||||||||||||||||||||||||||||||
| 180 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 181 | zapp_run_tasks => $task->{task_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | state => 'stopped', | |||||||||||||||||||||||||||||||||||||||||
| 184 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # Stop run | ||||||||||||||||||||||||||||||||||||||||||
| 189 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | zapp_runs => $run_id, | |||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | state => 'stopped', | ||||||||||||||||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return $self->redirect_to( 'zapp.get_run' => { run_id => $run_id } ); | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | ▶ | sub start_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_run: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $run_id = $self->stash( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $run = $self->_get_run( $run_id ) || return $self->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_run($run_id) || (return $self->reply->not_found)
MC/DC0%0/1
$self->_get_run($run_id) || (return $self->reply->not_found)
$self->_get_run($run_id)
Truth table0%0/2
A
A= $self->_get_run($run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # Requeue all jobs that were stopped | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my %task_jobs; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | for my $task ( $run->{tasks}->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ( $task->{state} ne 'stopped' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $task_jobs{ $task->{task_id} } = $task->{job_id}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $old_job_id = $task->{job_id}; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my %job_opts; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ( my @parents = $self->yancy->list( zapp_run_task_parents => { $task->%{'task_id'} } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | next if grep { !$task_jobs{ $_->{parent_task_id} } } @parents; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | $job_opts{ parents } = [ | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | map $task_jobs{ $_ }, @parents | |||||||||||||||||||||||||||||||||||||||||
| 217 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $args = $task->{input}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ( ref $args ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $args = [ $args ]; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->log->debug( sprintf 'Enqueuing task %s', $task->{class} ); | |||||||||||||||||||||||||||||||||||||||||
| 226 | my $new_job_id = $self->minion->enqueue( | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $task->{class} => $args, | |||||||||||||||||||||||||||||||||||||||||
| 228 | \%job_opts, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $task_jobs{ $task->{ task_id } } = $new_job_id; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 233 | zapp_run_tasks => $task->{task_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | job_id => $new_job_id, | |||||||||||||||||||||||||||||||||||||||||
| 236 | state => 'inactive', | ||||||||||||||||||||||||||||||||||||||||||
| 237 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | zapp_runs => $run_id, | |||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | state => 'active', | ||||||||||||||||||||||||||||||||||||||||||
| 245 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return $self->redirect_to( 'zapp.get_run' => { run_id => $run_id } ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | ▶ | sub kill_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kill_run: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $run_id = $self->stash( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $run = $self->_get_run( $run_id ) || return $self->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_run($run_id) || (return $self->reply->not_found)
MC/DC0%0/1
$self->_get_run($run_id) || (return $self->reply->not_found)
$self->_get_run($run_id)
Truth table0%0/2
A
A= $self->_get_run($run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( $self->req->method eq 'GET' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return $self->render( | |||||||||||||||||||||||||||||||||||||||||
| 257 | 'zapp/run/note', | ||||||||||||||||||||||||||||||||||||||||||
| 258 | heading => 'Kill Run', | ||||||||||||||||||||||||||||||||||||||||||
| 259 | next => 'zapp.kill_run_confirm', | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | # Add the note | ||||||||||||||||||||||||||||||||||||||||||
| 264 | $self->yancy->create( zapp_run_notes => { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $run->%{qw( run_id )}, | |||||||||||||||||||||||||||||||||||||||||
| 266 | event => 'kill', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | note => $self->param( 'note' ), | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # Kill inactive and active jobs | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | for my $task ( $run->{tasks}->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $job_id = $task->{job_id}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | my $job = $self->minion->job( $job_id ) || next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->minion->job($job_id) || (next)
MC/DC0%0/1
$self->minion->job($job_id) || (next)
$self->minion->job($job_id)
Truth table0%0/2
A
A= $self->minion->job($job_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | next if $job->info->{state} !~ qr{inactive|active}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( $job->info->{state} eq 'active' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->minion->broadcast( 'kill', [ TERM => $job_id ]); | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $job->remove; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 282 | zapp_run_tasks => $task->{task_id}, | ||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | state => 'killed', | |||||||||||||||||||||||||||||||||||||||||
| 285 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | # Kill run | ||||||||||||||||||||||||||||||||||||||||||
| 290 | $self->yancy->backend->set( | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | zapp_runs => $run_id, | |||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | state => 'killed', | ||||||||||||||||||||||||||||||||||||||||||
| 294 | finished => Time::Piece->new->datetime, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return $self->redirect_to( 'zapp.get_run' => { run_id => $run_id } ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | ▶ | sub get_run_task( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_run_task: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $run_id = $self->stash( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $task_id = $self->stash( 'task_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my ( $run_task ) = grep { $_->{task_id} eq $task_id } $self->_get_run_tasks( $run_id )->@* | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | or return $self->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $template = data_section( $run_task->{class}, 'output.html.ep' ); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | return $self->render( inline => $template, task => $run_task ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | ▶ | sub list_runs( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_runs: not called CC=4 SCAR=25.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my @runs = $self->yancy->list( zapp_runs => {}, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 312 | # XXX: Order should be: | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # 1. Jobs that have not started | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # 2. Jobs that have not finished | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # 3. Jobs by finished datetime | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # 4. Jobs by started datetime | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # 5. Jobs by created datetime | ||||||||||||||||||||||||||||||||||||||||||
| 318 | @runs = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | ( $b->{state} =~ /(in)?active/n ) cmp ( $a->{state} =~ /(in)?active/n ) | ||||||||||||||||||||||||||||||||||||||||||
| 321 | || $b->{finished} cmp $a->{finished} | ||||||||||||||||||||||||||||||||||||||||||
| 322 | || $b->{started} cmp $a->{started} | ||||||||||||||||||||||||||||||||||||||||||
| 323 | || $b->{created} cmp $a->{created} | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | } @runs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$Zapp::Controller::Run::b->{"state"} =~ /(in)?active/nu cmp $Zapp::Controller::Run::a->{"state"} =~ /(in)?active/nu or $Zapp::Controller::Run::b->{"finished"} cmp $Zapp::Controller::Run::a->{"finished"} or $Zapp::Controller::Run::b->{"started"} cmp $Zapp::Controller::Run::a->{"started"}
$Zapp::Controller::Run::b->{"state"} =~ /(in)?active/nu cmp $Zapp::Controller::Run::a->{"state"} =~ /(in)?active/nu or $Zapp::Controller::Run::b->{"finished"} cmp $Zapp::Controller::Run::a->{"finished"}
MC/DC0%0/3
$Zapp::Controller::Run::b->{"state"} =~ /(in)?active/nu cmp $Zapp::Controller::Run::a->{"state"} =~ /(in)?active/nu or $Zapp::Controller::Run::b->{"finished"} cmp $Zapp::Controller::Run::a->{"finished"} or $Zapp::Controller::Run::b->{"started"} cmp $Zapp::Controller::Run::a->{"started"}
$Zapp::Controller::Run::b->{"state"} =~ /(in)?active/nu cmp $Zapp::Controller::Run::a->{"state"} =~ /(in)?active/nu
$Zapp::Controller::Run::b->{"finished"} cmp $Zapp::Controller::Run::a->{"finished"}
$Zapp::Controller::Run::b->{"started"} cmp $Zapp::Controller::Run::a->{"started"}
Truth table0%0/4
A or B or C
A= $Zapp::Controller::Run::b->{"state"} =~ /(in)?active/nu cmp $Zapp::Controller::Run::a->{"state"} =~ /(in)?active/nuB= $Zapp::Controller::Run::b->{"finished"} cmp $Zapp::Controller::Run::a->{"finished"}C= $Zapp::Controller::Run::b->{"started"} cmp $Zapp::Controller::Run::a->{"started"}
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $self->render( 'zapp/run/list', runs => \@runs ); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | ▶ | sub feed_run( $self ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
feed_run: not called CC=4 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $self->inactivity_timeout(3600); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $interval = int( $self->param( 'interval' ) ) || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
int $self->param('interval') || 1
MC/DC0%0/1
int $self->param('interval') || 1
int $self->param('interval')
Truth table0%0/2
A
A= int $self->param('interval')
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Establish the current state of the run and every task | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $run_id = $self->param( 'run_id' ); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my $old_run = $self->_get_run( $run_id ) || return $self->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_run($run_id) || (return $self->reply->not_found)
MC/DC0%0/1
$self->_get_run($run_id) || (return $self->reply->not_found)
$self->_get_run($run_id)
Truth table0%0/2
A
A= $self->_get_run($run_id)
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my @old_tasks = @{ delete $old_run->{tasks} }; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # Send the initial state in case something has changed since the | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # original HTML page was sent | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $self->send({ | |||||||||||||||||||||||||||||||||||||||||
| 340 | json => { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | %$old_run, | ||||||||||||||||||||||||||||||||||||||||||
| 342 | tasks => \@old_tasks, | ||||||||||||||||||||||||||||||||||||||||||
| 343 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 344 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | # If the run is finished or failed, we're done here: Nothing can | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # change about this run. | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $old_run->{state} =~ /^(finished|failed)$/n ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | # See https://tools.ietf.org/html/rfc6455#section-7.4.1 for | ||||||||||||||||||||||||||||||||||||||||||
| 350 | # websocket status codes | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $self->finish(1000); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | # Poll for updates | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $timer_id; | |||||||||||||||||||||||||||||||||||||||||
| 357 | $self->on( finish => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ( $timer_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | Mojo::IOLoop->remove( $timer_id ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $timer_id = undef; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 363 | ▶ | $timer_id = Mojo::IOLoop->recurring( $interval, sub( $loop ) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $new_run = $self->_get_run( $run_id ); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my @new_tasks = @{ delete $new_run->{tasks} }; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # Send any changed fields / tasks | ||||||||||||||||||||||||||||||||||||||||||
| 368 | my %delta = ( | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | map { $_ => $new_run->{ $_ } } | |||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | grep { no warnings 'uninitialized'; $old_run->{ $_ } ne $new_run->{ $_ } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | keys %$new_run | ||||||||||||||||||||||||||||||||||||||||||
| 372 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | for my $i ( 0..$#new_tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my ( $old_task, $new_task ) = ( $old_tasks[ $i ], $new_tasks[ $i ] ); | |||||||||||||||||||||||||||||||||||||||||
| 375 | # XXX: What if we add new tasks? | ||||||||||||||||||||||||||||||||||||||||||
| 376 | my %task_delta = ( | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | map { $_ => $new_task->{ $_ } } | |||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | ▶ | grep { no warnings 'uninitialized'; $old_task->{ $_ } ne $new_task->{ $_ } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | keys %$new_task | ||||||||||||||||||||||||||||||||||||||||||
| 380 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( %task_delta ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $task_delta{ task_id } = $new_task->{ task_id }; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | push @{ $delta{tasks} }, \%task_delta; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ( %delta ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->send({ json => \%delta }); | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | # Update the state with the new information | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $old_run = $new_run; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | @old_tasks = @new_tasks; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ( $old_run->{state} =~ /^(finished|failed)$/n ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | # We're done here... | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( $timer_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $loop->remove( $timer_id ); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $timer_id = undef; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # See https://tools.ietf.org/html/rfc6455#section-7.4.1 for | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # websocket status codes | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $self->finish(1000); | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | __END__ | ||||||||||||||||||||||||||||||||||||||||||