RunCommand: move JSON generation to its own function

[?]
Dec 8, 2021, 4:29 PM
354QHWZ7XFIDL4YLGMJB6TTCZDXIU2NJG2JXMYNXTQKEHM5VQOOAC

Dependencies

  • [2] GD2WBYPT RunCommand: Return metrics as a float
  • [3] E4TV6NH6 RunCommand: pass homepage, description, license, system, and nixname
  • [4] Z4AMS3T7 RunCommand: emit the `finished` field as a boolean
  • [5] OAGCZHK6 Allow for precisely one instance of RunCommand plugin
  • [6] HPXFXHFS Remove SHA-1 hash from BuildProducts
  • [7] 6ZXL5UOP Add a plugin to execute arbitrary commands when a build finishes

Change contents

  • edit in src/lib/Hydra/Plugin/RunCommand.pm at line 39
    [5.748]
    [5.748]
    }
    sub makeJsonPayload {
    my ($event, $build) = @_;
    my $json = {
    event => $event,
    build => $build->id,
    finished => $build->get_column('finished') ? JSON::true : JSON::false,
    timestamp => $build->get_column('timestamp'),
    project => $build->get_column('project'),
    jobset => $build->get_column('jobset'),
    job => $build->get_column('job'),
    drvPath => $build->get_column('drvpath'),
    startTime => $build->get_column('starttime'),
    stopTime => $build->get_column('stoptime'),
    buildStatus => $build->get_column('buildstatus'),
    nixName => $build->get_column('nixname'),
    system => $build->get_column('system'),
    homepage => $build->get_column('homepage'),
    description => $build->get_column('description'),
    license => $build->get_column('license'),
    outputs => [],
    products => [],
    metrics => [],
    };
    for my $output ($build->buildoutputs) {
    my $j = {
    name => $output->name,
    path => $output->path,
    };
    push @{$json->{outputs}}, $j;
    }
    for my $product ($build->buildproducts) {
    my $j = {
    productNr => $product->productnr,
    type => $product->type,
    subtype => $product->subtype,
    fileSize => $product->filesize,
    sha256hash => $product->sha256hash,
    path => $product->path,
    name => $product->name,
    defaultPath => $product->defaultpath,
    };
    push @{$json->{products}}, $j;
    }
    for my $metric ($build->buildmetrics) {
    my $j = {
    name => $metric->name,
    unit => $metric->unit,
    value => 0 + $metric->value,
    };
    push @{$json->{metrics}}, $j;
    }
    return $json;
  • replacement in src/lib/Hydra/Plugin/RunCommand.pm at line 120
    [5.1383][5.1383:1479](),[5.1479][4.0:87](),[4.87][5.1539:2011](),[5.1539][5.1539:2011](),[5.2011][3.0:298](),[3.298][5.2011:2645](),[5.2011][5.2011:2645](),[5.2697][5.2697:3144](),[5.3144][2.0:49](),[2.49][5.3189:3319](),[5.3189][5.3189:3319]()
    my $json = {
    event => $event,
    build => $build->id,
    finished => $build->get_column('finished') ? JSON::true : JSON::false,
    timestamp => $build->get_column('timestamp'),
    project => $build->get_column('project'),
    jobset => $build->get_column('jobset'),
    job => $build->get_column('job'),
    drvPath => $build->get_column('drvpath'),
    startTime => $build->get_column('starttime'),
    stopTime => $build->get_column('stoptime'),
    buildStatus => $build->get_column('buildstatus'),
    nixName => $build->get_column('nixname'),
    system => $build->get_column('system'),
    homepage => $build->get_column('homepage'),
    description => $build->get_column('description'),
    license => $build->get_column('license'),
    outputs => [],
    products => [],
    metrics => [],
    };
    for my $output ($build->buildoutputs) {
    my $j = {
    name => $output->name,
    path => $output->path,
    };
    push @{$json->{outputs}}, $j;
    }
    for my $product ($build->buildproducts) {
    my $j = {
    productNr => $product->productnr,
    type => $product->type,
    subtype => $product->subtype,
    fileSize => $product->filesize,
    sha256hash => $product->sha256hash,
    path => $product->path,
    name => $product->name,
    defaultPath => $product->defaultpath,
    };
    push @{$json->{products}}, $j;
    }
    for my $metric ($build->buildmetrics) {
    my $j = {
    name => $metric->name,
    unit => $metric->unit,
    value => 0 + $metric->value,
    };
    push @{$json->{metrics}}, $j;
    }
    print $tmp encode_json($json) or die;
    [5.1383]
    [5.3319]
    print $tmp encode_json(makeJsonPayload($event, $build)) or die;