Allow generic files to be added to queue

This commit is contained in:
HummyPkg 2018-10-07 17:03:04 +01:00
parent da9f328316
commit 6745b88fb9
3 changed files with 47 additions and 19 deletions

View File

@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
Version: 1.4.3-3
Version: 1.4.4
Architecture: mipsel
Maintainer: af123@hpkg.tv
Depends: tcpfix,webif-channelicons(>=1.1.26),lighttpd(>=1.4.39-1),jim(>=0.77),jim-oo(>=0.77),jim-sqlite3(>=0.77),jim-cgi(>=0.7-1),jim-binary(>=0.76),service-control(>=2.3),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.8),hmt(>=2.0.10),ssmtp,cron-daemon(>=1.18.3-3),at(>=3.1.18),anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.1.11),webif-charts(>=1.2-1),stripts(>=1.4.2),tmenu(>=1.21-2),ffmpeg(>=2.8),id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7),hwctl,nugget(>=0.98-3),sqlite3(>=3.15.1),jim-xconv

View File

@ -123,7 +123,7 @@ proc ::auto::dumpq {qq} {
proc ::auto::runplugin {plugin fn args} {
set rfn "::${plugin}::${fn}"
if {![exists -proc $rfn]} { return -1 }
if {[catch {set ret [uplevel 1 $rfn {*}$args]} msg]} {
if {[catch {set ret [uplevel 1 $rfn $args]} msg]} {
log "$rfn: $msg" 0
lassign [info stacktrace] p f l
log " $f:$l @ $p" 0
@ -168,13 +168,25 @@ 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
}
} elseif {[string first :// $file] != -1} {
set arg $file
} 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 +198,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 +212,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,20 @@ 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 {
if {[string first :// $o] != -1} {
return $o
}
return "file://$o"
}
}
}
# Queue status values:
# PENDING
# FAILED
@ -119,21 +133,23 @@ proc {queue fetch} {file action} {
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 +161,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 +202,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 +212,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 +221,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
}