TaskPipe/Tool/Command_RunPlan.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 73.5% 50 / 68 CC 3 SCAR 11.6
CC
3
Cov
70%
execute
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« TaskPipe/Role/MooseType_StrArrayRef.pm ↑ Summary TaskPipe/Template_Task.pm »
1 package TaskPipe::Tool::Command_RunPlan;
2  
3 39 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use TaskPipe::SchemaManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use TaskPipe::LoggerManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use TaskPipe::Task_Scrape::Settings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use TaskPipe::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 ▶use TaskPipe::JobManager;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 39 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 extends 'TaskPipe::Tool::Command';
12 39 with 'MooseX::ConfigCascade';
13  
14  
15 has option_specs => (is => 'ro', isa => 'ArrayRef', default => sub{[{
16 630 ▶ module => 'TaskPipe::PathSettings::Global',
Subroutine __ANON__: called CC=1 SCAR=0.0
17 items => [
18 'project_root',
19 'project',
20 ],
21 is_config => 1
22 }, {
23 module => 'TaskPipe::PathSettings::Project',
24 items => [
25 'plan',
26 'lib_dir',
27 'plan_dir',
28 'source_dir',
29 'log_dir'
30 ],
31 is_config => 1
32 }, {
33 module => 'TaskPipe::Plan::Settings',
34 is_config => 1
35 }, {
36 module => 'TaskPipe::Task::Settings',
37 items => [
38 'plan_mode'
39 ]
40 39 }]});
41  
42  
43 has schema_manager => (is => 'rw', isa => 'TaskPipe::SchemaManager', lazy => 1, default => sub{
44 315 ▶ my $sm = TaskPipe::SchemaManager->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
45 315 $sm->connect_schema;
46 315 return $sm;
47 39 });
48  
49  
50  
51 has job_manager => (is => 'ro', isa => 'TaskPipe::JobManager', lazy => 1, default => sub{
52 315 ▶ TaskPipe::JobManager->new(
Subroutine __ANON__: called CC=1 SCAR=0.0
53 name => $_[0]->name,
54 project => $_[0]->schema_manager->path_settings->project_name,
55 shell => $_[0]->plan->settings->shell
56 );
57 39 });
58  
59  
60 has plan => (is => 'rw', isa => 'TaskPipe::Plan', lazy => 1, default => sub{
61 315 ▶ TaskPipe::Plan->new(
Subroutine __ANON__: called CC=1 SCAR=0.0
62 schema_manager => $_[0]->schema_manager
63 );
64 39 });
65  
66  
67  
68  
69 sub execute{
70  
71 0 ▶ my ($self) = @_;
Subroutine execute: not called CC=3 SCAR=24.8
Pod undocumented
72  
73 # $self->plan->task->rinfo->job_id( $self->job_manager->job_id );
74 # $self->plan->task->rinfo->orig_cmd( $self->orig_cmd );
75 # $self->plan->task->logger_manager->run_info->job_id( $self->job_manager->job_id );
76 # $self->plan->task->logger_manager->run_info->orig_cmd( $self->orig_cmd );
77 0 $self->plan->task->logger_manager->init_logger;
78  
79 0 ▶ if ( $self->plan->settings->shell eq 'background' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->plan->settings->shell eq "background") 0 0 0
80 0 $self->run_info->shell('background');
81 0 $self->job_manager->daemonize;
82 }
83  
84 0 ▶ if ( $self->plan->settings->iterate eq 'repeat' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->plan->settings->iterate eq 'repeat') { } 0 0 0
85  
86 0 while(1){
87 0 $self->plan->load_content;
88 0 $self->plan->task->plan( $self->content );
89 0 $self->plan->task->execute;
90 0 sleep( $self->plan->settings->poll_interval );
91 }
92  
93 } else {
94 0 $self->plan->run;
95 }
96  
97 }
98  
99  
100 #sub set_run_id{
101 # my ($self) = @_;
102  
103 # my $last_run = $self->sm->table('run')->search({},{
104 # order_by => 'id desc',
105 # rows => 1
106 # })->first;
107  
108  
109 # if ( $last_run && $last_run->status ne 'complete' ){
110 # $self->run_info->run_id( $last_run->id );
111 # } else {
112 # my $this_run = $self->sm->table('run')->create({
113 # status => 'processing',
114 # started => $dt,
115 # });
116  
117 # $self->run_info->run_id( $this_run->id );
118 # }
119 #}
120 #
121  
122  
123 =head1 NAME
124  
125 TaskPipe::Tool::Command_RunPlan - command to run a TaskPipe plan
126  
127 =head1 PURPOSE
128  
129 Execute the specified plan, or the default plan from configuration if no explicit C<--plan> option is provided
130  
131 =head1 DESCRIPTION
132  
133 C<run plan> executes the specified plan in accordance with the settings in your config. To run the default plan (usually C<plan.yml>) over the default project (as specified by the C<project> parameter in the C<TaskPipe::PathSettings::Global> section of your config) simply type
134  
135 taskpipe run plan
136  
137 To specify a particular plan include C<--plan>:
138  
139 taskpipe run plan --plan=specificplan.yml
140  
141 To name a project other than the default, use
142  
143 taskpipe run plan --project=otherproject
144  
145 To run the plan in the background use the C<--shell=background> parameter. To run it repeatedly use C<--iterate=repeat>. You can daemonize a process by combining the two:
146  
147 taskpipe run plan --shell=background --iterate=repeat
148  
149 See L<OPTIONS> for more information.
150  
151 =head1 AUTHOR
152  
153 Tom Gracey <tomgracey@gmail.com>
154  
155 =head1 COPYRIGHT AND LICENSE
156  
157 Copyright (c) Tom Gracey 2018
158  
159 TaskPipe is free software, licensed under
160  
161 The GNU Public License Version 3
162 =cut
163  
164 39 __PACKAGE__->meta->make_immutable;
165 39 1;
166  
167  
168  
« TaskPipe/Role/MooseType_StrArrayRef.pm ↑ Summary TaskPipe/Template_Task.pm »