| 1 | package TaskPipe::Tool::Command_RunPlan; | ||||||||||
| 2 | |||||||||||
| 3 | 37 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 37 | ▶ | use TaskPipe::SchemaManager; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 37 | ▶ | use TaskPipe::LoggerManager; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 37 | ▶ | use TaskPipe::Task_Scrape::Settings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 37 | ▶ | use TaskPipe::Plan; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 37 | ▶ | use Module::Runtime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 37 | ▶ | use TaskPipe::JobManager; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 37 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 37 | extends 'TaskPipe::Tool::Command'; | |||||||||
| 12 | 37 | with 'MooseX::ConfigCascade'; | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | has option_specs => (is => 'ro', isa => 'ArrayRef', default => sub{[{ | ||||||||||
| 16 | 602 | ▶ | 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 | 37 | }]}); | |||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | has schema_manager => (is => 'rw', isa => 'TaskPipe::SchemaManager', lazy => 1, default => sub{ | ||||||||||
| 44 | 301 | ▶ | my $sm = TaskPipe::SchemaManager->new; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 301 | $sm->connect_schema; | |||||||||
| 46 | 301 | return $sm; | |||||||||
| 47 | 37 | }); | |||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | has job_manager => (is => 'ro', isa => 'TaskPipe::JobManager', lazy => 1, default => sub{ | ||||||||||
| 52 | 301 | ▶ | 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 | 37 | }); | |||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | has plan => (is => 'rw', isa => 'TaskPipe::Plan', lazy => 1, default => sub{ | ||||||||||
| 61 | 301 | ▶ | TaskPipe::Plan->new( | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 62 | schema_manager => $_[0]->schema_manager | ||||||||||
| 63 | ); | ||||||||||
| 64 | 37 | }); | |||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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 | 37 | __PACKAGE__->meta->make_immutable; | |||||||||
| 165 | 37 | 1; | |||||||||
| 166 | |||||||||||
| 167 | |||||||||||
| 168 | |||||||||||