/usr/share/tcltk/tcllib1.17/cron/cron.tcl is in tcllib 1.17-dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | ###
# This file implements a process table
# Instead of having individual components try to maintain their own timers
# we centrally manage how often tasks should be kicked off here.
###
#
# Author: Sean Woods (for T&E Solutions)
package provide cron 1.1
::namespace eval ::cron {}
proc ::cron::at args {
switch [llength $args] {
2 {
variable processuid
set process event#[incr processuid]
lassign $args timecode command
}
3 {
lassign $args process timecode command
}
default {
error "Usage: ?process? timecode command"
}
}
variable processTable
if {[string is integer -strict $timecode]} {
set scheduled $timecode
} else {
set scheduled [clock scan $timecode]
}
set now [clock seconds]
set info [list process $process frequency 0 command $command scheduled $scheduled lastevent $now]
if ![info exists processTable($process)] {
lappend info lastrun 0 err 0 result {}
}
foreach {field value} $info {
dict set processTable($process) $field $value
}
::cron::runTasks
return $process
}
proc ::cron::in args {
switch [llength $args] {
2 {
variable processuid
set process event#[incr processuid]
lassign $args timecode command
}
3 {
lassign $args process timecode command
}
default {
error "Usage: ?process? timecode command"
}
}
variable processTable
set now [clock seconds]
set scheduled [expr {int(ceil($timecode+$now))}]
set info [list process $process frequency 0 command $command scheduled $scheduled lastevent $now]
if ![info exists processTable($process)] {
lappend info lastrun 0 err 0 result {}
}
foreach {field value} $info {
dict set processTable($process) $field $value
}
::cron::runTasks
return $process
}
###
# topic: 0776dccd7e84530fa6412e507c02487c
###
proc ::cron::every {process frequency command} {
variable processTable
set now [clock seconds]
set info [list process $process frequency $frequency command $command scheduled [expr {$now + $frequency}] lastevent $now]
if ![info exists processTable($process)] {
lappend info lastrun 0 err 0 result {}
}
foreach {field value} $info {
dict set processTable($process) $field $value
}
::cron::runTasks
}
proc ::cron::cancel {process} {
variable processTable
unset -nocomplain processTable($process)
}
###
# topic: 97015814408714af539f35856f85bce6
###
proc ::cron::run process {
variable processTable
dict set processTable($process) lastrun 0
}
###
# topic: 1f8d4726623321acc311734c1dadcd8e
# description:
# Run through our process table and
# kick off overdue tasks
###
proc ::cron::runProcesses {} {
variable processTable
set now [clock seconds]
###
# Determine what tasks to run this timestep
###
set tasks {}
set cancellist {}
foreach {process} [array names processTable] {
dict with processTable($process) {
if { $scheduled <= $now } {
lappend tasks $process
if { $frequency <= 0 } {
lappend cancellist $process
} else {
set scheduled [expr {$frequency + $lastrun}]
if { $scheduled <= $now } {
set scheduled [expr {$frequency + $now}]
}
}
set lastrun $now
}
set lastevent $now
}
}
foreach task $tasks {
dict with processTable($task) {
set err [catch {uplevel #0 $command} result]
if $err {
puts $result
}
}
}
foreach {task} $cancellist {
unset -nocomplain processTable($task)
}
}
###
# topic: 2f5a33d28948c4514764bd2f58b750fc
# description:
# Called once per second, and timed to ensure
# we run in roughly realtime
###
proc ::cron::runTasks {} {
variable lastcall
after cancel $lastcall
###
# Run the processes before we kick off another task...
###
catch {runProcesses}
variable processTable
###
# Look at our schedule and book the next timeslot
# or 15 minutes, whichever is sooner
###
set now [clock seconds]
set nexttime [expr {$now - ($now % 900) + 900}]
foreach {process} [array names processTable] {
dict with processTable($process) {
if {$scheduled > $now && $scheduled < $nexttime} {
set nexttime $scheduled
}
}
}
###
# Try to get the event to fire off on the border of the
# nearest second
###
if { $nexttime > $now } {
set ctime [clock milliseconds]
set next [expr {($nexttime-$now)*1000-1000+($ctime % 1000)}]
} else {
set next 0
}
set lastcall [after $next [namespace current]::runTasks]
}
###
# topic: 4a891d0caabc6e25fbec9514ea8104dd
# description:
# This file implements a process table
# Instead of having individual components try to maintain their own timers
# we centrally manage how often tasks should be kicked off here.
###
namespace eval ::cron {
variable lastcall 0
variable processTable
}
::cron::runTasks
|