Changeset 145

Show
Ignore:
Timestamp:
10/25/06 06:19:25 (7 years ago)
Author:
lincoln
Message:

more missing_data debugging added

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • shepherd

    r144 r145  
    33# "Shepherd" 
    44 
    5 my $version = '0.2.24'; 
     5my $version = '0.2.25'; 
    66 
    77# A wrapper for various Aussie TV guide data grabbers 
     
    3737#           explicitly tell reconciler the preferred _title_ source 
    3838# 0.2.24  : logging and log files 
     39# 0.2.25  : use open-with-pipe rather than system() and look at 
     40#           return codes from called programmes 
    3941 
    4042BEGIN { *CORE::GLOBAL::die = \&my_die; } 
     
    202204} 
    203205 
    204 unless ($opt->{nolog}) { 
    205     &rotate_logfiles; 
    206     open(LOG_FILE,">$log_file") || die "can't open log file $log_file for writing: $!\n"; 
    207 } 
     206&open_logfile unless ($opt->{nolog}); 
    208207 
    209208# --------------------------------------------------------------------------- 
     
    323322        $comm .= " @ARGV" if (@ARGV); 
    324323 
     324        my $retval = 0; 
    325325        if ((defined $opt->{dontcallgrabbers}) && ($opt->{dontcallgrabbers})) { 
    326326            &log("SHEPHERD: not calling grabber because of --dontcallgrabbers option, but will instead use existing $output\n"); 
     
    329329            &log("SHEPHERD: Excuting command: $comm\n"); 
    330330            chdir "$CWD/grabbers/$grabber/"; 
    331             system($comm); 
     331            $retval = call_prog($comm); 
    332332            chdir $CWD; 
     333        } 
     334 
     335        if ($retval != 0) { 
     336            &log("grabber returned with non-zero return code $retval: assuming it failed.\n"); 
     337            next; 
    333338        } 
    334339 
     
    10061011        $data->{missing} = 0; 
    10071012 
     1013        my $already_missing = ""; 
     1014        my $already_missing_last = ""; 
     1015 
    10081016        for my $slotnum (0..($policy{num_timeslots}-1)) { 
    10091017            my $bucket_start_offset = ($slotnum * $policy{timeslot_size}); 
     
    10241032 
    10251033                $data->{day}->[$day]->{day_ok} = 1; # until proven otherwise 
     1034 
     1035                # day changed, dump any 'already_missing' data 
     1036                if ($already_missing ne "") { 
     1037                    $already_missing .= sprintf "-%02d:%02d", 
     1038                      int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
     1039                      if ($already_missing_last ne ""); 
     1040                    push(@{($data->{missing_all})}, $already_missing); 
     1041                    $already_missing = ""; 
     1042                    $already_missing_last = ""; 
     1043                } 
    10261044            } 
    10271045 
     
    10291047            if ((defined $channel_data->{$ch}->{timeslots}[$slotnum]) && 
    10301048                ($channel_data->{$ch}->{timeslots}[$slotnum] > 0)) { 
     1049 
     1050                # if we have missing data queued up, push it now 
     1051                if ($already_missing ne "") { 
     1052                    $already_missing .= sprintf "-%02d:%02d", 
     1053                      int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
     1054                      if ($already_missing_last ne ""); 
     1055                    push(@{($data->{missing_all})}, $already_missing); 
     1056                    $already_missing = ""; 
     1057                    $already_missing_last = ""; 
     1058                } 
     1059 
    10311060                $data->{day}->[$day]->{have} += $policy{timeslot_size}; 
    10321061                $data->{have} += $policy{timeslot_size}; 
     
    10441073 
    10451074            # store details of where we are missing data 
    1046             push(@{($data->{missing_all})}, "$day:$bucket_seconds_offset"); 
     1075            if ($already_missing eq "") { 
     1076                $already_missing = sprintf "#%d/%02d:%02d", $day, 
     1077                      int($bucket_seconds_offset/3600),int(($bucket_seconds_offset%3600)/60); 
     1078                $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
     1079            } else { 
     1080                $already_missing_last = $bucket_seconds_offset + $policy{timeslot_size} - 1; 
     1081            } 
     1082 
    10471083            $data->{day}->[$day]->{missing} += $policy{timeslot_size}; 
    10481084            $data->{missing} += $policy{timeslot_size}; 
     
    10691105        } 
    10701106 
    1071         my $statusstring = sprintf "ch %s: have %s (%s)%s",  
     1107        # if we have missing data queued up, push it now 
     1108        if ($already_missing ne "") { 
     1109            $already_missing .= sprintf "-%02d:%02d", 
     1110              int($already_missing_last/3600),int(($already_missing_last%3600)/60) 
     1111              if ($already_missing_last ne ""); 
     1112            push(@{($data->{missing_all})}, $already_missing); 
     1113            $already_missing = ""; 
     1114            $already_missing_last = ""; 
     1115        } 
     1116 
     1117        my $statusstring = sprintf "ch %s: %s (%s)%s",  
    10721118          $ch, pretty_duration($data->{have}), $data->{data_ok} ? "pass" : "fail", 
    10731119          ($data->{missing} ? " missing" : ""); 
     
    10931139                      if ($day->{missing_other} > 0); 
    10941140                } else { 
    1095                     $statusstring .= "all"; 
     1141                    $statusstring .= "all[!]"; 
    10961142                } 
    10971143 
     
    11001146        } 
    11011147        &log(" > $statusstring\n") unless $quiet; 
     1148 
     1149        &log("[debug] Missing the following bucket slots for this $ch: ". 
     1150          join(" ",(@{($data->{missing_all})}))."\n") 
     1151          if ($data->{missing} > 0); 
    11021152 
    11031153        delete $channel_data->{$ch}->{analysis} if (defined $channel_data->{$ch}->{analysis}); 
     
    13311381    my $dir = sprintf "%s/%ss/%s/",$CWD,$data_processor_type,$data_processor_name; 
    13321382    chdir $dir; 
    1333     system($comm); 
     1383    my $retval = call_prog($comm); 
    13341384    chdir $CWD; 
     1385 
     1386    if ($retval != 0) { 
     1387        &log("$data_processor_type returned with non-zero return code $retval: assuming it failed.\n"); 
     1388        return 0; 
     1389    } 
    13351390 
    13361391    # 
     
    14981553 
    14991554    # Make component executable 
    1500     system('chmod u+x ' . $newfile); 
     1555    chmod 0755,$newfile; 
    15011556 
    15021557    -d $ARCHIVE_DIR or mkdir $ARCHIVE_DIR or die "Cannot create directory $ARCHIVE_DIR: $!"; 
     
    15621617 
    15631618    chdir($testdir); 
    1564     system("$proggyexec --ready"); 
     1619    my $result = call_prog("$proggyexec --ready"); 
    15651620    chdir ($CWD); 
    15661621 
    1567     my $result = $?; 
    15681622    print "Return value: $result\n" if ($debug); 
    15691623 
     
    17171771} 
    17181772 
     1773sub open_logfile 
     1774{ 
     1775    &rotate_logfiles; 
     1776    printf "Logging to $log_file.\n"; 
     1777    open(LOG_FILE,">$log_file") || die "can't open log file $log_file for writing: $!\n"; 
     1778} 
     1779 
    17191780sub close_logfile 
    17201781{ 
     
    17271788    my $entry = shift; 
    17281789    print $entry; 
    1729     printf LOG_FILE "%s %s",time,$entry unless $opt->{nolog}; 
    1730 } 
    1731  
     1790    printf LOG_FILE "%s",$entry unless $opt->{nolog}; 
     1791} 
     1792 
     1793sub call_prog 
     1794{ 
     1795    my $prog = shift; 
     1796    if (!(open(PROG,"$prog|"))) { 
     1797        &log("warning: couldn't exec \"$prog\": $!\n"); 
     1798        return -1; 
     1799    } 
     1800    while(<PROG>) { 
     1801        &log($_); 
     1802    } 
     1803    close(PROG); 
     1804 
     1805    if ($? == -1) { 
     1806        &log("Failed to execute prog: $!\n"); 
     1807        return -1; 
     1808    } elsif ($? & 127) { 
     1809        &log((sprintf "prog died with signal %d, %s coredump\n", 
     1810          ($? & 127),  ($? & 128) ? "with" : "without")); 
     1811        return $?; 
     1812    } else { 
     1813        &log((sprintf "prog exited with value %d\n", $? >> 8)); 
     1814        return ($? >> 8); 
     1815    } 
     1816} 
    17321817 
    17331818# ----------------------------------------- 
  • status

    r144 r145  
    1 shepherd:0.2.24:shepherd 
     1shepherd:0.2.25:shepherd 
    22grabber:rex:3.3.5-r2 
    33grabber:oztivo:0.8-r2