tasks: make error a json

also, handle case where we never got to handle task exit cleanly
This commit is contained in:
Girish Ramakrishnan
2019-08-30 13:46:55 -07:00
parent dd0fb8292c
commit bd23abd265
6 changed files with 57 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ let assert = require('assert'),
DatabaseError = require('./databaseerror'),
safe = require('safetydance');
const TASKS_FIELDS = [ 'id', 'type', 'argsJson', 'percent', 'message', 'errorMessage', 'creationTime', 'resultJson', 'ts' ];
const TASKS_FIELDS = [ 'id', 'type', 'argsJson', 'percent', 'message', 'errorJson', 'creationTime', 'resultJson', 'ts' ];
function postProcess(task) {
assert.strictEqual(typeof task, 'object');
@@ -26,6 +26,9 @@ function postProcess(task) {
task.result = JSON.parse(task.resultJson);
delete task.resultJson;
task.error = safe.JSON.parse(task.errorJson);
delete task.errorJson;
}
function add(task, callback) {
@@ -50,8 +53,8 @@ function update(id, data, callback) {
let args = [ ];
let fields = [ ];
for (let k in data) {
if (k === 'result') {
fields.push('resultJson = ?');
if (k === 'result' || k === 'error') {
fields.push(`${k}Json = ?`);
args.push(JSON.stringify(data[k]));
} else {
fields.push(k + ' = ?');