From 1fc426cb1a7ae2092e66ed53462aa05fe93cfca5 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 19 Dec 2016 00:56:03 +0000 Subject: [PATCH] fixes/improvements git-svn-id: file:///root/webif/svn/pkg/webif/trunk@3434 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- etc/init.d/S59webif | 1 - webif/html/browse/script.js | 2 +- webif/html/diag/queue/fetch.jim | 37 +++++++++++++++ webif/html/diag/queue/index.jim | 40 ++++------------ webif/html/diag/queue/script.js | 80 +++++++++++++++++++++++++------- webif/html/settings/settings.jim | 2 +- webif/lib/bin/auto | 6 ++- webif/lib/bin/update_queue | 7 --- webif/lib/plugin | 2 +- webif/lib/queue.class | 27 ++++++++--- 11 files changed, 138 insertions(+), 68 deletions(-) create mode 100755 webif/html/diag/queue/fetch.jim delete mode 100755 webif/lib/bin/update_queue diff --git a/CONTROL/control b/CONTROL/control index 0753ec7..f0e0946 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.3.4 +Version: 1.3.4-1 Architecture: mipsel Maintainer: af123@hpkg.tv Depends: tcpfix,webif-channelicons(>=1.1.24),lighttpd(>=1.4.39-1),jim(>=0.77),jim-oo(>=0.77),jim-sqlite3(>=0.76),jim-cgi(>=0.7-1),jim-binary(>=0.76),service-control(>=2.3),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.3),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.9),webif-charts(>=1.2-1),stripts(>=1.2.5-3),tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7),hwctl,nugget(>=0.95),sqlite3(>=3.15.1) diff --git a/etc/init.d/S59webif b/etc/init.d/S59webif index 9bc5f88..eb907db 100755 --- a/etc/init.d/S59webif +++ b/etc/init.d/S59webif @@ -6,7 +6,6 @@ export TZ=GMT+0BST,M3.5.0/1,M10.5.0/2 case "$1" in start) - /mod/webif/lib/bin/update_queue /mod/webif/lib/bin/manage_logs plog activity "System booted (`lbr_descr`)." ;; diff --git a/webif/html/browse/script.js b/webif/html/browse/script.js index ddf0dfa..2e720d5 100755 --- a/webif/html/browse/script.js +++ b/webif/html/browse/script.js @@ -883,7 +883,7 @@ $('#bmpdialogue').dialog({ // Selection overlay $seloverlay = $('#selectoverlay').dialog({ modal: false, autoOpen: false, - height: 85, width: 460, + height: 85, width: 485, show: 'fade', hide: 'fade', draggable: true, resizable: false }); diff --git a/webif/html/diag/queue/fetch.jim b/webif/html/diag/queue/fetch.jim new file mode 100755 index 0000000..bc01b83 --- /dev/null +++ b/webif/html/diag/queue/fetch.jim @@ -0,0 +1,37 @@ +#!/mod/bin/jimsh + +source /mod/webif/lib/setup +require queue.class + +httpheader "application/json" + +puts "\[" +set flag 0 +foreach q [queue all] { + set name [string map { + "/mnt/hd2/My Video/" "" + "/media/drive1/Video/" "" + "/media/" "" + ".ts" "" + } [$q get file]] + set dat [clock format [$q get dat] -format {%c}] + + if {$flag} { puts "," } else { incr flag } + puts "{" + puts " \"qid\": [$q get id]," + puts " \"dat\": \"$dat\"," + puts " \"file\": \"$name\"," + puts " \"action\": \"[$q get action]\"," + puts " \"status\": \"[$q get status]\"," + puts " \"log\": \"[$q get log]\"," + if {[$q get elapsed] > 0} { + set time [clock format [$q get elapsed] -format "%T"] + puts " \"elapsed\": \"$time\"," + } else { + puts " \"elapsed\": \"0\"," + } + puts " \"retry\": \"[$q get retry]\"" + puts -nonewline "}" +} +puts "\n]" + diff --git a/webif/html/diag/queue/index.jim b/webif/html/diag/queue/index.jim index f53e816..798203d 100755 --- a/webif/html/diag/queue/index.jim +++ b/webif/html/diag/queue/index.jim @@ -16,51 +16,27 @@ puts {
Queued Tasks - +
- + + -} - -foreach q [queue all] { - set name [string map { - "/mnt/hd2/My Video/" "" - "/media/drive1/Video/" "" - "/media/" "" - ".ts" "" - } [$q get file]] - - puts " - - - - - - - - - " -} - -puts {
IDID Submitted File Action StatusTime Log
- [$q get id] - [clock format [$q get dat] -format {%c}]$name[$q get action][$q get status]" - if {[$q get status] eq "RUNNING"} { - puts "" - } - puts "[$q get log]
- + + + + +
} diff --git a/webif/html/diag/queue/script.js b/webif/html/diag/queue/script.js index 10b68f7..f77d61b 100644 --- a/webif/html/diag/queue/script.js +++ b/webif/html/diag/queue/script.js @@ -8,6 +8,50 @@ function page_refresh(msg) window.location.reload(true); } +function load() +{ + $.getJSON('fetch.jim', function(data) { + $('#queuetab > tbody').empty(); + + $.each(data, function(k, v) { + + $('#isloading').show('fast'); + + s = '' + + '' + + v.qid + '' + + '' + v.dat + '' + + '' + v.file + '' + + '' + v.action + '' + + '' + v.status; + if (v.status == 'RUNNING') + s += '  '; + s += ''; + if (v.elapsed != '0') + s += v.elapsed; + s += '' + + '' + v.log + '' + + ''; + + $('#queuetab > tbody').append(s); + }); + var resort = true; + $('#queuetab').trigger('update', [resort]); + $('input.qid:checkbox').prop('checked', false).enable(); + + $('tr').each(function() { + var status = $(this).find('td.status').text(); + + if (status == 'RUNNING') + $(this).find('input.qid:checkbox').disable(); + }); + + $('input.qid').first().trigger('change'); + $('#isloading').hide('slow'); + }); +} + $(function() { $('table') @@ -18,17 +62,9 @@ $('table') widgets: ['zebra', 'stickyHeaders'] }); +load(); -$('input.qid:checkbox').prop('checked', false).enable(); - -$('tr').each(function() { - var status = $(this).find('td.status').text(); - - if (status == 'RUNNING') - $(this).find('input.qid:checkbox').disable(); -}); - -$('input.qid:checkbox').on('change', function() { +$('#queuetab').on('change', 'input.qid', function() { var num = $('input.qid:checked').size(); if (num) $('#qdelete').enable(); @@ -47,7 +83,6 @@ $('#qdelete').button({icons:{primary:"ui-icon-trash"}}) message: '

Deleting...

' }); - var slots = $('input.qid:checked').map(function() { return this.value; }).get(); @@ -60,16 +95,27 @@ $('#qdelete').button({icons:{primary:"ui-icon-trash"}}) }); +$('#selnone').button({icons:{primary:"ui-icon-close"}}) + .on('click', function() { + $('#queuetab input:checkbox').prop('checked', false); +}); + +$('#selall').button({icons:{primary:"ui-icon-check"}}) + .on('click', function() { + $('#queuetab input:checkbox').prop('checked', true); +}); + +$('#selcomplete').button({icons:{primary:"ui-icon-stop"}}) + .on('click', function() { + $('#queuetab input:checkbox[status="COMPLETE"]').prop('checked', true); +}); + $('#refresh').button({icons:{primary:"ui-icon-refresh"}}) .on('click', function() { - page_refresh(); + load(); }); -$('#selall').on('change', function() { - $('input.qid:checkbox').prop('checked', $(this).prop('checked')); -}); - -setInterval(function() { page_refresh() }, 60000); +setInterval(load, 60000); }); diff --git a/webif/html/settings/settings.jim b/webif/html/settings/settings.jim index 402425d..d96d273 100755 --- a/webif/html/settings/settings.jim +++ b/webif/html/settings/settings.jim @@ -121,7 +121,7 @@ foreach mod $modules { proc plugin_callback {plugin hook} { puts "

Settings for [file tail $plugin] package

" puts "
" - if {[catch {source "$plugin/$hook"} msg]} { + if {[catch {uplevel source "$plugin/$hook"} msg]} { puts "ERROR: $msg" } puts "
" diff --git a/webif/lib/bin/auto b/webif/lib/bin/auto index f98205b..80609da 100755 --- a/webif/lib/bin/auto +++ b/webif/lib/bin/auto @@ -881,6 +881,7 @@ if {[lindex $argv 0] eq "-singledir"} { scansingle [lrange $argv 1 end] } elseif {[lindex $argv 0] eq "-queue"} { log "Processing queue..." 2 + queue startup while {[llength [set q [queue pop]]]} { oktorun @@ -900,11 +901,14 @@ if {[lindex $argv 0] eq "-singledir"} { } set func $::queue_actions($act) $q update RUNNING "Started at [clock format [clock seconds]]" + set start [clock seconds] if {[catch {$func $ts} msg]} { $q update FAILED $msg 1 continue } - $q update COMPLETE "Completed at [clock format [clock seconds]]" + set elapsed $([clock seconds] - $start) + $q update COMPLETE \ + "Completed at [clock format [clock seconds]]" 0 $elapsed } } elseif {[llength $argv] > 0} { set loglevel 2 diff --git a/webif/lib/bin/update_queue b/webif/lib/bin/update_queue deleted file mode 100755 index 14acb8d..0000000 --- a/webif/lib/bin/update_queue +++ /dev/null @@ -1,7 +0,0 @@ -#!/mod/bin/jimsh - -source /mod/webif/lib/setup -require queue.class - -queue boot - diff --git a/webif/lib/plugin b/webif/lib/plugin index bf7f96c..4fed142 100644 --- a/webif/lib/plugin +++ b/webif/lib/plugin @@ -4,7 +4,7 @@ proc eval_plugins {hook {verbose 0} {callback ""}} { if {[file exists "$plugin/.disabled"]} continue if {[file isfile "$plugin/$hook.hook"]} { if {$callback ne ""} { - $callback $plugin $hook.hook + uplevel $callback $plugin $hook.hook continue } if {[catch \ diff --git a/webif/lib/queue.class b/webif/lib/queue.class index 21e7cb7..3c33348 100644 --- a/webif/lib/queue.class +++ b/webif/lib/queue.class @@ -10,6 +10,7 @@ class queue { log "" status "" retry 0 + elapsed 0 } proc {queue dbhandle} {args} { @@ -36,6 +37,7 @@ proc {queue dbhandle} {args} { action text, status text default 'PENDING', log text default '', + elapsed integer, retry integer default 0 ); } @@ -44,26 +46,39 @@ proc {queue dbhandle} {args} { } } else { set ::queue::db [sqlite3.open /mod/etc/queue.db] +# XXX - Remove before release + catch { $::queue::db query { + alter table queue + add column elapsed integer default 0 + }} } return $::queue::db } -queue method update {_status {_log ""} {_retry 0}} { +queue method update {_status {_log ""} {_retry 0} {_elapsed 0}} { set db [queue dbhandle] $db query { update queue - set status = '%s', log = '%s', retry = retry + %s + set status = '%s', + log = '%s', + retry = retry + %s, + elapsed = %s where id = %s - } $_status $_log $_retry $id + } $_status $_log $_retry $_elapsed $id + + set status $_status + set log $_log + incr retry $_retry + set elapsed $_elapsed } -proc {queue boot} {} { +proc {queue startup} {} { set db [queue dbhandle] $db query { update queue set status = 'INTERRUPTED', - log = 'System was shut down. Job will be retried automatically.', + log = 'Job will be retried automatically.', retry = retry + 1 where status in ('RUNNING', 'INTERRUPTED') } @@ -71,7 +86,7 @@ proc {queue boot} {} { delete from queue where status in ('COMPLETE', 'FAILED') and dat < %s - } [expr [clock seconds] - 86400 * 3] + } [expr [clock seconds] - 86400 * 7] } proc {queue insert} {ts action} {