#!/usr/bin/perl

# A way, using a counter separate from MOPS, of tracking the night number as a
# test is run.

use strict;
use PS::MOPS::DC::Instance;

our $inst=PS::MOPS::DC::Instance->new(DBNAME=>$ENV{MOPS_DBINSTANCE});
our $mops_logger=$inst->getLogger;

# Advance night number.

my $filepath="$ENV{MOPS_VAR}/config/current-mpc-export-night-number.txt";
open(F,"<$filepath");
my @data=<F>;
close(F);

my $cnt=@data[0];
chomp($cnt);

print "cnt=$cnt\n";
if(!$cnt){
    $cnt=1;
}
else {
    $cnt++;
}

# write the new cnt
open(F,">$filepath");
print F "$cnt\n";
close(F);

$mops_logger->info("MPC-EXPORT: Current night number is $cnt");
