Fix retrieval of container log timestamp from db

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-11-20 11:19:53 -08:00
parent 7191d4917d
commit e44c7073f9
No known key found for this signature in database
GPG Key ID: 49690ED87032539F

View File

@ -1,3 +1,5 @@
import * as _ from 'lodash';
import Database from '../db';
import log from '../lib/supervisor-console';
@ -38,14 +40,14 @@ export class LogMonitor {
.select('lastSentTimestamp')
.where({ containerId });
if (timestampObj == null) {
if (timestampObj == null || _.isEmpty(timestampObj)) {
// Create a row in the db so there's something to
// update
await this.db
.models('containerLogs')
.insert({ containerId, lastSentTimestamp: 0 });
} else {
this.timestamps[containerId] = timestampObj.lastSentTimestamp;
this.timestamps[containerId] = timestampObj[0].lastSentTimestamp;
}
} catch (e) {
log.error(