Changeset 705

Show
Ignore:
Timestamp:
05/28/07 20:30:48 (6 years ago)
Author:
lincoln
Message:

keep proper history of runs

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/shepherd

    r704 r705  
    22 
    33my $progname = 'shepherd'; 
    4 my $version = '0.4.97'; 
     4my $version = '0.4.98'; 
    55 
    66# tv_grab_au 
     
    8080my $last_successful_run; 
    8181my $last_successful_run_data; 
     82my $last_successful_runs; 
    8283my $components = { }; 
    8384my $components_pending_install = { }; 
     
    8990my $log_file = "$progname.log"; 
    9091my $sysid = time.".".$$; 
    91 my $oldest_days = 30; 
    9292my $pending_messages = { }; 
    9393my $starttime = time; 
     
    726726    my $total_wanted = $plugin_data->{$progname}->{total_duration} + $plugin_data->{$progname}->{total_missing}; 
    727727    $last_successful_run_data = ($total_wanted ? 100* $plugin_data->{$progname}->{total_duration} / $total_wanted : 0); 
     728 
     729    $last_successful_runs->{$last_successful_run} = $last_successful_run_data; 
    728730} 
    729731 
     
    890892    &log(2, "WARNING: ".ucfirst($progname)." is being run too frequently.\n"); 
    891893 
    892     if ($oldest_days <= 7) { 
     894    # enforce hard limit 
     895    my $num_runs = 0; 
     896    my $earliest_run = time; 
     897    foreach my $when (sort {$b <=> $a} keys %{$last_successful_runs}) { 
     898        if (($when + (86400*30)) < time) { 
     899            delete $last_successful_runs->{$when}; # age out old entries 
     900            next; 
     901        } 
     902 
     903        if ($when >= (time - (86400*7))) { 
     904            $num_runs++; 
     905            $earliest_run = $when if ($num_runs == 30); 
     906        } 
     907    } 
     908    if ($num_runs >= 30) { 
    893909        &log(2, "\n*** ERROR: EXTREME OVERUSE ***\n\n". 
    894910            "Shepherd has run more than 30 times in the last 7 days! To avoid overloading\n". 
     
    898914            "TO AVOID THIS ERROR: Please do not run Shepherd more than once or twice per\n". 
    899915            "day. Shepherd is now in a locked state. To unlock Shepherd, wait \n". 
    900             (8-$oldest_days)." days. Alternately, you may reinstall Shepherd.\n\n". 
     916            pretty_duration((7*86400)-(time-$earliest_run)). 
     917            ". Alternately, you may reinstall Shepherd.\n\n". 
    901918            "Please do not abuse Shepherd. All users depend on your courtesy.\n\n"); 
    902919 
     
    10581075    # keep last 30 log files 
    10591076    my $num; 
    1060     my $found = 0; 
    1061     $oldest_days = 0; 
    1062  
    10631077    for ($num = 30; $num > 0; $num--) { 
    10641078        my $f1 = sprintf "%s/%s.%d.gz",$LOG_DIR,$log_file,$num; 
     
    10661080        unlink($f2); 
    10671081        rename($f1,$f2); 
    1068  
    1069         if (-s $f2) { 
    1070             $found++; 
    1071             $oldest_days = -M $f2 if ((-M $f2) > $oldest_days); 
    1072         } 
    10731082    } 
    10741083 
     
    10761085    my $f2 = sprintf "%s/%s.1",$LOG_DIR,$log_file; 
    10771086    rename($f1,$f2); 
    1078  
    1079     $oldest_days = 30 if ($found <= 28); 
    10801087} 
    10811088 
     
    13901397{ 
    13911398    write_file($config_file, 'configuration',  
    1392         [$region,  $pref_title_source,  $want_paytv_channels,  $sysid,  $last_successful_run, $last_successful_run_data, $mirror_site,  $components,  $components_pending_install,  $pending_messages ], 
    1393         ["region", "pref_title_source", "want_paytv_channels", "sysid", "last_successful_run", "last_successful_run_data", "mirror_site", "components", "components_pending_install", "pending_messages" ]); 
     1399        [$region,  $pref_title_source,  $want_paytv_channels,  $sysid,  $last_successful_run, $last_successful_run_data, $last_successful_runs, $mirror_site,  $components,  $components_pending_install,  $pending_messages ], 
     1400        ["region", "pref_title_source", "want_paytv_channels", "sysid", "last_successful_run", "last_successful_run_data", "last_successful_runs", "mirror_site", "components", "components_pending_install", "pending_messages" ]); 
    13941401} 
    13951402 
     
    21962203             ($ctype eq 'grabber' ? 
    21972204                "                         Enabled/\n". 
    2198                 sprintf(" %-17s Version Ready  Last Run  Status", ucfirst($ctype))  
     2205                sprintf(" %-15s Version Ready  Last Run  Status", ucfirst($ctype))  
    21992206                : ucfirst($ctype)) . 
    2200              "\n -------------- ---------- ----- ---------- -----------------------------------\n"); 
     2207             "\n ------------ ---------- ----- ---------- -------------------------------------\n"); 
    22012208        foreach (sort { ($components->{$b}->{lastdata} or 0) <=> ($components->{$a}->{lastdata} or 0) } query_component_type($ctype)) 
    22022209        { 
    22032210            my $h = $components->{$_}; 
    2204             &log(sprintf  " %-15s%10s %1s/%1s%1s %11s %s\n", 
    2205                  length($_) > 15 ? substr($_,0,13).".." : $_, 
     2211            &log(sprintf  " %-13s%10s %1s/%1s%1s %11s %s\n", 
     2212                 length($_) > 13 ? substr($_,0,11).".." : $_, 
    22062213                 $h->{ver}, 
    22072214                 $h->{disabled} ? 'N' : 'Y', 
     
    22092216                 (defined $plugin_data->{$_}->{tainted} ? "!" : ""), 
    22102217                 pretty_date($h->{lastdata}), 
    2211                  $h->{laststatus} ? pretty_print($h->{laststatus},35) : ''); 
     2218                 ((defined $h->{disabled} && $h->{disabled} == 2) ? "centrally disabled" : 
     2219                     ($h->{laststatus} ? pretty_print($h->{laststatus},37) : ''))); 
    22122220        } 
    22132221    } 
     
    22212229                            $last_successful_run_data; 
    22222230        } 
    2223         &log("$str.\n"); 
     2231        &log("\n$str.\n"); 
     2232 
     2233        $str = sprintf "  History of runs: "; 
     2234        foreach my $when (sort {$b <=> $a} keys (%{$last_successful_runs})) { 
     2235            $str .= pretty_duration(time - $when). 
     2236                (sprintf "[%2.2f%%] ",$last_successful_runs->{$when}); 
     2237        } 
     2238        &log("$str\n"); 
    22242239    } 
    22252240    &log("\nPreferred titles from grabber '$pref_title_source'\n") if ($pref_title_source); 
  • status

    r704 r705  
    1 application     shepherd            0.4.97 
     1application     shepherd            0.4.98 
    22reference       channel_list        2 
    33reference       Shepherd/Common.pm  0.12