#!/usr/bin/perl
#$Id: load_cluster_cache.pl,v 1.1 2026/05/29 11:55:20 sqko Exp $
use strict;
use warnings;
use RFC::Main;
my $file = '/tmp/RFCcache.txt';
my $listserver =  get_cv('servers','listserver');
exit unless ($listserver);
use SemaforeFile;
my $conf = SemaforeFile->new($file);
my %cache = ();
my @list = ();
my @listservers = ();
my $str= &RFC::Main::report_client($listserver,'servers');
my @l = split(/\t/,$str) if ($str && $str !~ /ERROR/);
foreach (@l)
{
    if (/([\w\.\-]+)/)
    {
	push @list,$1;
    }
}
$cache{'servers'} = join(',',@list);
$str= &RFC::Main::report_client($listserver,'list_servers');
@l = ();
@l = split(/\t/,$str) if ($str && $str !~ /ERROR/);
foreach (@l)
{
    if (/([\w\.\-]+)/)
    {
	push @listservers,$1;
    }
}
$cache{'listservers'} = join(',',@listservers);
foreach my $s (@list)
{
    $str = &RFC::Main::report_client($s,'active_rigs');
    $str = '' unless defined($str);
    $cache{$s.'_active_rigs'} = $str;
    $str = &RFC::Main::report_client($s,'rigs');
    $str = '' unless defined($str);
    $cache{$s.'_rigs'} = $str;
}
$conf->lock_ex();
$conf->writeline('');
foreach my $key (keys %cache)
{
    $conf->append($key.'#'.$cache{$key});
}
chmod 0666,$file;
$conf->lock_un();
exit;



