HPC-Runner-Command

 view release on metacpan or  search on metacpan

lib/HPC/Runner/Command/submit_jobs/Logger/JSON.pm  view on Meta::CPAN

package HPC::Runner::Command::submit_jobs::Logger::JSON;

use Moose::Role;
use namespace::autoclean;

with 'HPC::Runner::Command::execute_job::Logger::Lock';

use JSON;
use File::Spec;
use Data::UUID;
use File::Path qw(make_path remove_tree);
use File::Slurp;
use DateTime;
use Capture::Tiny ':all';

=head3 create_json_submission

Create the data for the json submission

=cut

sub create_json_submission {
    my $self = shift;

    make_path($self->data_dir);
    $self->logger('app_log');
    my $hpc_meta = $self->gen_hpc_meta;

    # my $json_text = encode_json $hpc_meta;
    # write_file(File::Spec->catdir($self->data_dir, 'submission.json'), $json_text);

    return $hpc_meta;
}

=head3 update_json_submission

Take the initial submission and update it to contain the hpcmeta

We only rerun this here to get the submission status

=cut

sub update_json_submission {
    my $self = shift;

    make_path($self->data_dir);
    my $hpc_meta = $self->gen_hpc_meta;
    my $json_text = encode_json $hpc_meta;

    # my $file_name = File::Spec->catdir( $self->logdir, 'submission.json' );
    $self->_make_the_dirs( $self->logdir );

    # write_file($file_name, $json_text);
    write_file(File::Spec->catdir($self->data_dir, 'submission.json'), $json_text);

    return $hpc_meta;
}

=head3 gen_hpc_meta

Generate the HPC meta from the submission

#TODO Check for batches

=cut

sub gen_hpc_meta {
    my $self = shift;

    my $hpc_meta = {};
    $hpc_meta->{uuid} = $self->submission_uuid;
    $hpc_meta->{project} = $self->project if $self->has_project;
    my $dt = DateTime->now( time_zone => 'local' );
    $hpc_meta->{submission_time} = "$dt";
    $hpc_meta->{jobs}            = [];
    $hpc_meta->{submissions}     = {};
    $hpc_meta->{schedule}        = $self->schedule;

    foreach my $job ( $self->all_schedules ) {
        my $job_obj = {};

        #Dependencies
        my $ref             = $self->graph_job_deps->{$job};
        my $depstring       = join( ", ", @{$ref} );
        my $count_cmd       = $self->jobs->{$job}->cmd_counter;
        my $mem             = $self->jobs->{$job}->mem;
        my $cpus            = $self->jobs->{$job}->cpus_per_task;
        my $walltime        = $self->jobs->{$job}->walltime;
        my $cmd_start       = $self->jobs->{$job}->{cmd_start};
        my $submission_stat = $self->jobs->{$job}->submission_failure || 0;

        $job_obj->{job}           = $job;
        $job_obj->{deps}          = $depstring;
        $job_obj->{total_tasks}   = $count_cmd;
        $job_obj->{walltime}      = $walltime;
        $job_obj->{cpus_per_task} = $cpus;
        $job_obj->{mem}           = $mem;
        $job_obj->{cmd_start}     = $cmd_start;
        $job_obj->{cmd_end}       = $cmd_start + $count_cmd;
        $job_obj->{schedule}      = [];

        #I think this should be scheduler_ids
        for ( my $x = 0 ; $x < $self->jobs->{$job}->{num_job_arrays} ; $x++ ) {



( run in 2.647 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )