Index: openacs-4/packages/monitoring/www/scheduled-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/monitoring/www/scheduled-procs.tcl,v diff -u -r1.2 -r1.2.2.1 --- openacs-4/packages/monitoring/www/scheduled-procs.tcl 19 Aug 2002 23:10:28 -0000 1.2 +++ openacs-4/packages/monitoring/www/scheduled-procs.tcl 22 Jan 2003 17:02:10 -0000 1.2.2.1 @@ -36,15 +36,62 @@ set counter 0 set bgcolors { white #E0E0E0 } +proc ad_scheduled_procs_nextrun { interval last_run } { + # if simple ns_schedule_proc, interval will be integer + # if ns_schedule_daily, interval will be "hour" and "min" of next run + # if ns_schedule_weekly, interval will be "day", "hour" and "min" + + if { [llength $interval] == 1 } { + set next_run [expr { $last_run + $interval }] + } elseif { [llength $interval] == 2 } { + set hour [lindex $interval 0] + set minute [lindex $interval 1] + + set next_run [clock scan "${hour}:${minute}"] + + # has it already run today? Then get tomorrow's value + if { [clock seconds] > $next_run } { + set next_run [expr $next_run + 86400] + } + } elseif { [llength $interval] == 3 } { + set day_num [lindex $interval 0] + switch $day_num { + 0 { set day "Sunday" } + 1 { set day "Monday" } + 2 { set day "Tuesday" } + 3 { set day "Wednesday" } + 4 { set day "Thursday" } + 5 { set day "Friday" } + 6 { set day "Saturday" } + } + set hour [lindex $interval 1] + set minute [lindex $interval 2] + set next_run [clock scan "$day ${hour}:${minute}"] + + # has it already run this week? Then get next week's value + if { [clock seconds] > $next_run } { + set next_run [expr $next_run + 604800] + } + } else { + ad_return_error "Error: Unknown interval" \ + "Error in monitoring/www/scheduled-procs.tcl : + ad_scheduled_procs_nextrun" + } + + return $next_run +} + proc ad_scheduled_procs_compare { a b } { - set next_run_a [expr { [lindex $a 5] + [lindex $a 2] }] - set next_run_b [expr { [lindex $b 5] + [lindex $b 2] }] + # compare based on when next run is scheduled + set next_run_a [ad_scheduled_procs_nextrun [lindex $a 2] [lindex $a 5]] + set next_run_b [ad_scheduled_procs_nextrun [lindex $b 2] [lindex $b 5]] + if { $next_run_a < $next_run_b } { - return -1 + return -1 } elseif { $next_run_a > $next_run_b } { - return 1 + return 1 } else { - return [string compare [lindex $a 3] [lindex $b 3]] + return [string compare [lindex $a 3] [lindex $b 3]] } } @@ -58,26 +105,26 @@ set proc [lindex $proc_info 3] set args [lindex $proc_info 4] if { $args == "" } { - set args " " + set args " " } set time [lindex $proc_info 5] set count [lindex $proc_info 6] set debug [ad_decode [lindex $proc_info 7] "t" "Yes" "No"] set last_run [ad_decode $count 0 " " [ns_fmttime $time $time_fmt]] - set next_run [ns_fmttime [expr { $time + $interval }] $time_fmt] - set next_run_in "[expr { $time + $interval - [ns_time] }] s" + set next_run [ns_fmttime [ad_scheduled_procs_nextrun $interval $time] $time_fmt] + set next_run_in "[expr { [ad_scheduled_procs_nextrun $interval $time] - [ns_time] }] s" append page_content "" foreach name { proc args } { - append page_content "[set $name]" + append page_content "[set $name]" } append page_content "$count" foreach name { last_run next_run } { - append page_content "[set $name]" + append page_content "[set $name]" } append page_content "$next_run_in" foreach name { thread once debug } { - append page_content "[set $name]" + append page_content "[set $name]" } append page_content "\n" }