Skip to content

Commit

Permalink
Merge pull request #23 from jrha/call_handler
Browse files Browse the repository at this point in the history
cdp-listend: Factor out calls to notification handlers
  • Loading branch information
jrha authored Sep 10, 2024
2 parents 0887e2c + 85a080b commit b711d67
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/scripts/cdp-listend
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,25 @@ while($ip1->recv($newmsg,1024)) {
my $ntype = $1;
my $time = $2;
logit('info',"Received UDP packet ($ntype|$time) from $r_host");
# time extraction!
if ($ntype eq"ccm") {
my $smear = int(rand($fetch_smear));
my $delay = $smear + $fetch_offset;
logit('info', "$fetch will be called in $delay seconds (offset=$fetch_offset, smear=$smear)");
sleep($delay);
logit('info', "Calling $fetch with unix time $time (after $delay seconds)");
system ("$fetch --profile-time=$time") == 0
or logit('err',"[ERROR] call of ccm-fetch ($fetch) failed: $!");
if ($ntype eq "ccm") {
my $delay = int(rand($fetch_smear)) + $fetch_offset;
call_handler($fetch, "--profile-time=$time", $delay);
} elsif ($ntype eq "cdb") {
my $smear = int(rand($nch_smear));
logit('info', "$nch will be called in $smear seconds");
sleep($smear);
logit('info', "Calling $nch with unix time $time (after $smear seconds)");
system ("$nch") == 0
or logit('err',"[ERROR] call of cdbsync-nch ($nch) failed: $!");
my $delay = int(rand($nch_smear));
call_handler($nch, "", $delay);
} else {
logit('err', "[ERROR] Ignoring packet, unknown notification type");
}
}

sub call_handler {
my ($handler, $handler_args, $delay) = @_;
logit('info', "$handler will be called in $delay seconds");
sleep($delay);
logit('info', "Calling $handler now");
system ("$handler $handler_args") == 0 or logit('err',"[ERROR] call of $handler failed: $!");
}

sub logit {
my ($priority, $msg) = @_;
return 0 unless ($priority =~ /info|err|debug/);
Expand Down

0 comments on commit b711d67

Please sign in to comment.