« blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/Files.pm
↑ Summary
blib/lib/HPC/Runner/Command/new.pm »
| 1 | package HPC::Runner::Command::submit_jobs; | ||
| 2 | |||
| 3 | =head1 HPC::Runner::Command::submit_jobs | ||
| 4 | |||
| 5 | Call the hpcrunner.pl submit_jobs command | ||
| 6 | |||
| 7 | hpcrunner.pl submit_jobs -h | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | use MooseX::App::Command; | ||
| 12 | use Moose::Util qw/apply_all_roles/; | ||
| 13 | |||
| 14 | use File::Spec; | ||
| 15 | use File::Slurp; | ||
| 16 | use DateTime; | ||
| 17 | |||
| 18 | extends 'HPC::Runner::Command'; | ||
| 19 | |||
| 20 | with 'HPC::Runner::Command::submit_jobs::Utils::Plugin'; | ||
| 21 | with 'HPC::Runner::Command::execute_job::Utils::Plugin'; | ||
| 22 | with 'HPC::Runner::Command::Logger::JSON'; | ||
| 23 | with 'HPC::Runner::Command::Utils::Base'; | ||
| 24 | with 'HPC::Runner::Command::Utils::Log'; | ||
| 25 | with 'BioSAILs::Integrations::Github'; | ||
| 26 | with 'BioSAILs::Utils::CacheUtils'; | ||
| 27 | with 'HPC::Runner::Command::submit_jobs::Utils::Scheduler'; | ||
| 28 | with 'HPC::Runner::Command::submit_jobs::Logger::JSON'; | ||
| 29 | |||
| 30 | command_short_description 'Submit jobs to the HPC system'; | ||
| 31 | command_long_description 'This job parses your input file and writes out one or | ||
| 32 | more templates to submit to the scheduler of your choice (SLURM, PBS, etc)'; | ||
| 33 | |||
| 34 | =head2 Attributes | ||
| 35 | |||
| 36 | =head2 Subroutines | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | option 'dry_run' => ( | ||
| 41 | is => 'rw', | ||
| 42 | isa => 'Bool', | ||
| 43 | default => 0, | ||
| 44 | documentation => 'Do a dry run - do not submit to the scheduler.', | ||
| 45 | cmd_aliases => ['dr'], | ||
| 46 | ); | ||
| 47 | |||
| 48 | sub BUILD { | ||
| 49 | my $self = shift; | ||
| 50 | |||
| 51 | if ( $self->dry_run ) { | ||
| 52 | $self->hpc_plugins( ['Dummy'] ); | ||
| 53 | } | ||
| 54 | |||
| 55 | $self->gen_load_plugins; | ||
| 56 | $self->hpc_load_plugins; | ||
| 57 | |||
| 58 | if ( $self->use_batches ) { | ||
| 59 | apply_all_roles( $self, | ||
| 60 | 'HPC::Runner::Command::submit_jobs::Utils::Scheduler::UseBatches' ); | ||
| 61 | } | ||
| 62 | else { | ||
| 63 | apply_all_roles( $self, | ||
| 64 | 'HPC::Runner::Command::submit_jobs::Utils::Scheduler::UseArrays' ); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | sub execute { | ||
| 69 | my $self = shift; | ||
| 70 | |||
| 71 | $self->write_cache_files; | ||
| 72 | $self->git_things; | ||
| 73 | $self->app_log->info('Parsing input file'); | ||
| 74 | $self->parse_file_slurm; | ||
| 75 | $self->create_json_submission; | ||
| 76 | $self->app_log->info('Submitting jobs'); | ||
| 77 | $self->iterate_schedule; | ||
| 78 | $self->update_json_submission; | ||
| 79 | $self->app_log->info('Your jobs have been submitted.'); | ||
| 80 | |||
| 81 | ##Rolling this back until a future release | ||
| 82 | $self->app_log->info('Experimental! For status updates please run:'); | ||
| 83 | $self->app_log->info('hpcrunner.pl stats'); | ||
| 84 | $self->app_log->info( | ||
| 85 | 'To get status updates for only this submission please run:'); | ||
| 86 | $self->app_log->info( 'hpcrunner.pl stats --data_dir ' . $self->data_dir ); | ||
| 87 | } | ||
| 88 | |||
| 89 | ##TODO Combine this with the BioX cache file functions | ||
| 90 | |||
| 91 | sub write_cache_files { | ||
| 92 | my $self = shift; | ||
| 93 | my $cmd_line_opts = $self->print_cmd_line_opts; | ||
| 94 | my $config_data = $self->print_config_data; | ||
| 95 | |||
| 96 | my $dt = DateTime->now( time_zone => 'local' ); | ||
| 97 | $dt = "$dt"; | ||
| 98 | $dt =~ s/:/-/g; | ||
| 99 | |||
| 100 | my $cache_base = $self->infile->basename; | ||
| 101 | |||
| 102 | $self->cache_file( | ||
| 103 | File::Spec->catdir( | ||
| 104 | $self->cache_dir, '.hpcrunner-cache', | ||
| 105 | $cache_base . '--' . $dt . '.cache' | ||
| 106 | ) | ||
| 107 | ); | ||
| 108 | |||
| 109 | write_file($self->cache_file, $cmd_line_opts); | ||
| 110 | write_file($self->cache_file, {append => 1}, $config_data); | ||
| 111 | |||
| 112 | my $data = read_file($self->infile); | ||
| 113 | write_file($self->cache_file, {append => 1}, $data); | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; |