Error reporting; the user can retry; fix #1

This commit is contained in:
boyska 2013-12-27 02:17:12 +01:00
parent 4100b7b60b
commit 73a47f4f2b
21 changed files with 80 additions and 28 deletions

View file

@ -6,6 +6,7 @@
<link rel="icon" href="/static/img/icon.ico" />
<link rel="stylesheet" type="text/css" href="/static/css/pure-min.css" />
<!--link rel="stylesheet" type="text/css" href="/static/css/style.css"-->
<link rel="stylesheet" type="text/css" href="/static/css/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/css/techrec.css">
<link rel="stylesheet" type="text/css" href="/static/css/font-awesome.css" />

View file

@ -137,7 +137,7 @@ class RecAPI(Bottle):
# prendiamo la rec in causa
recid = dict(request.POST.allitems())['id']
rec = self.db._search(_id=recid)[0]
if rec.filename is not None and os.path.filename.exists(rec.filename):
if rec.filename is not None and os.path.exists(rec.filename):
return {'status': 'ready',
'message': 'The file has already been generated at %s' %
rec.filename,
@ -146,6 +146,7 @@ class RecAPI(Bottle):
if get_config()['FORGE_MAX_DURATION'] > 0 and \
(rec.endtime - rec.starttime).total_seconds() > \
get_config()['FORGE_MAX_DURATION']:
response.status = 400
return {'status': 'error',
'message': 'The requested recording is too long'
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

5
server/static/css/jquery-ui.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -12,6 +12,13 @@
display: table-cell;
}
.rec-download .fa {
color: green;
}
.rec-failed .fa {
color: red;
}
.pure-button-enorme {
font-size: 300%;
}

View file

@ -37,6 +37,7 @@ var API = {
$.widget("ror.countclock", {
options: {
errormsg: null,
since: null,
to: null
},
@ -72,7 +73,7 @@ $.widget("ror.ongoingrec", {
rec: null,
state: 0,
filename: null,
/*0 = ongoing, 1 = encoding, 2 = ready to download*/
/*0 = ongoing, 1 = encoding, 2 = ready to download, 9 = errors*/
},
_create: function() {
"use strict";
@ -102,12 +103,30 @@ $.widget("ror.ongoingrec", {
view.on("click", ".rec-stop", function(evt) {
widget._trigger("stop", evt, {rec: rec, widget: widget});
});
view.on("click", ".rec-failed", function(evt) {
$('<div/>').html($('<pre/>').text(widget.options.errormsg))
.dialog({modal: true, title: "Dettaglio errori",
buttons: {
Retry: function() {
console.log("retrying");
widget._setOption("state", 0);
widget._trigger("retry", evt, {rec: rec, widget: widget});
$(this).dialog("close");
}, Cancel: function() {
$(this).dialog("close");
}
}
});
});
return view;
},
_setOption: function(key, value) {
this.options[key] = value;
if(key === 'state') {
if(value !== 9) {
this.options.errormsg = null;
}
if(value < 2) {
this.options.filename = null;
}
@ -128,25 +147,29 @@ $.widget("ror.ongoingrec", {
this.element.find(':ror-countclock').countclock("option", "to", null);
}
this.element.find('a').removeClass(
'pure-button-disabled rec-encoding rec-download rec-failed rec-stop')
switch(this.options.state) {
case 0:
this.element.find('a').removeClass('pure-button-disabled rec-encoding rec-download')
.addClass("rec-stop").html(
this.element.find('a').addClass("rec-stop").html(
$('<i/>').addClass('fa fa-stop')).append(' Stop');
break;
case 1:
this.element.find('a').removeClass('rec-stop rec-download')
this.element.find('a')
.addClass("pure-button-disabled rec-encoding").html(
$('<i/>').addClass('fa fa-clock-o')).append(' Aspetta');
break;
case 2:
this.element.find('a').removeClass('pure-button-disabled rec-stop rec-encoding')
.addClass("rec-download")
this.element.find('a').addClass("rec-download")
.prop('href', this.options.filename)
.html(
$('<i/>').addClass('fa fa-download').css('color',
'green')).append(' Scarica');
break;
case 9:
this.element.find('a').addClass("rec-failed").html(
$('<i/>').addClass('fa fa-warning')).append(' Errori');
break;
}
}
});
@ -178,31 +201,43 @@ function add_new_rec() {
});
}
function gen_rec(rec, widget) {
"use strict";
var gen_xhr = API.generate(rec);
gen_xhr.done(function(res_gen) {
widget.option("state", 1);
poll_job(res_gen.job_id, function(data) {
if(data.job_status !== 'DONE') {
console.error("Job failed!", data);
widget.option("errormsg", "Generation failed");
widget.option("state", 9);
} else {
widget.option("filename", res_gen.result);
widget.option("state", 2);
}
});
});
gen_xhr.fail(function(res_gen) {
var error = JSON.parse(res_gen.responseText).message;
widget.option("errormsg", error);
widget.option("state", 9);
});
return gen_xhr;
}
function stop_rec(rec, widget) {
"use strict";
var xhr = API.stop(rec);
xhr.done(function(res_update) {
if(res_update.status !== true) {
console.error(res_update.status);
return;
}
var stop_xhr = API.stop(rec);
stop_xhr.done(function(res_update) {
widget.option("rec", res_update.rec);
var xhr = API.generate(rec)
.done(function(res_gen) {
//TODO: start polling on res.job_id
widget.option("state", 1);
poll_job(res_gen.job_id, function(data) {
if(data.job_status !== 'DONE') {
console.error("Job failed!", data);
} else {
widget.option("filename", res_gen.result);
widget.option("state", 2);
}
});
});
return xhr;
return gen_rec(rec, widget);
});
return xhr; //API.stop
stop_xhr.fail(function(res_update) {
var error = JSON.parse(res_update.responseText).message;
widget.option("errormsg", error);
widget.option("state", 9);
});
return stop_xhr; //API.stop
}
function show_ongoing(ongoing_recs) {
@ -210,6 +245,9 @@ function show_ongoing(ongoing_recs) {
var viewrec = $('<tr/>').ongoingrec({rec: rec});
viewrec.on("ongoingrecstop", function(evt, data) {
stop_rec(data.rec, data.widget);
}).on("ongoingrecretry", function(evt, data) {
//FIXME: bisognerebbe solo generare, senza stoppare
gen_rec(data.rec, data.widget);
}).on("ongoingrecchange", function(evt, data) {
//TODO: aggiorna nome sul server
API.update(data.rec.id, data.rec);