Allow generic files to be added to queue

This commit is contained in:
HummyPkg 2018-10-07 16:15:38 +01:00
parent da9f328316
commit 710722bf15
2 changed files with 39 additions and 18 deletions

View File

@ -168,13 +168,23 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} {
# Try to run the first item in the queue.
set q [lindex $qq 0]
set plugin [$q get action]
set file [$q get file]
::auto::log "De-queuing [$q get id] - [$q get action] - [$q get file]" 0
::auto::log "De-queuing [$q get id] - [$q get action] - $file" 0
if {[catch {set ts [ts fetch [$q get file]]}] || $ts eq "0"} {
::auto::log "ts load failed." 0
$q update "FAILED" "Could not load .ts file" 1
continue
if {[string match {file://*} $file]} {
set arg [string range $file 7 end]
if {![file exists $arg]} {
::auto::log "file does not exist." 0
$q update "FAILED" "File does not exist" 1
continue
}
} else {
if {[catch {set arg [ts fetch $file]}] || $arg eq "0"} {
::auto::log "ts load failed." 0
$q update "FAILED" "Could not load .ts file" 1
continue
}
}
::auto::dsc
@ -186,7 +196,7 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} {
set ::auto::logprefix "$plugin:$::auto::logprefix"
set st [clock milliseconds]
lassign [::auto::runplugin $plugin dequeue $q $ts] code msg next
lassign [::auto::runplugin $plugin dequeue $q $arg] code msg next
set ::auto::logprefix $ologprefix
set elapsed [::auto::elapsed $st]
@ -200,7 +210,7 @@ for {set qq [::auto::pending]} {[llength $qq]} {set qq [::auto::pending]} {
}
"OK" {
$q update "COMPLETE" $msg 1 $elapsed
::auto::runplugins dequeued $plugin $q $ts
::auto::runplugins dequeued $plugin $q $arg
}
"DEFER" {
if {$next ne ""} { $q set start $next }

View File

@ -17,6 +17,15 @@ class queue {
last 0
}
proc {queue key} {o} {
set type "string"
catch { set type [getref $o] }
switch -- $type {
ts { return [file normalize [$o get file]] }
default { return [concat "file://" $o] }
}
}
# Queue status values:
# PENDING
# FAILED
@ -113,27 +122,29 @@ proc {queue fetch} {file action} {
select * from queue
where file = '%s'
and action = '%s'
} [file normalize $file] $action] {
} [queue key $file]] {
return [queue new $row]
}
return {}
}
proc {queue insert} {args ts action} {
proc {queue insert} {args file action} {
set db [queue dbhandle]
set status "PENDING"
if {"-hold" in $args} { set status "HOLD" }
set file [queue key $file]
$db query {
insert or ignore into queue(submitted, file, action, status)
values(%s, '%s', '%s', '%s')
} [clock seconds] [file normalize [$ts get file]] $action $status
} [clock seconds] $file $action $status
return [queue fetch [$ts get file] $action]
return [queue fetch $file $action]
}
proc {queue delete} {ts {action "*"}} {
proc {queue delete} {file {action "*"}} {
set db [queue dbhandle]
set q "
@ -145,7 +156,7 @@ proc {queue delete} {ts {action "*"}} {
append q " and action = '%s'"
}
$db query $q [file normalize [$ts get file]] $action
$db query $q [queue key $file] $action
}
proc {queue delete_by_id} {id} {
@ -186,8 +197,8 @@ proc {queue hold} {id} {
$db query $q $id
}
proc {queue status} {ts} {
if {$ts eq "0"} { return "" }
proc {queue status} {file} {
if {$file eq "0"} { return "" }
set db [queue dbhandle]
@ -196,7 +207,7 @@ proc {queue status} {ts} {
from queue
where file = '%s'
and status not in ('COMPLETE', 'FAILED', 'HOLD')
} [file normalize [$ts get file]]]
} [queue key $file]]
set q ""
if {[llength $ret] == 1} {
@ -205,8 +216,8 @@ proc {queue status} {ts} {
return $q
}
proc {queue check} {ts {q "any"}} {
set queues [split [queue status $ts] ,]
proc {queue check} {file {q "any"}} {
set queues [split [queue status $file] ,]
if {$q eq "any" && [llength $queues]} {
return 1
}