我在AngularJS的显示图上遇到了麻烦。我有我的后端写在nodeJS中,我有一个聚合器作为缓冲区,netdata接收数据,我在那里插入数据插入BD。但与此同时,我是用cron做的。
使用新的客户端请求我需要另一个cron为同一个BD写入并使用相同的聚合器但结构不同,我没有使用netdata并且我做了所有更改,但问题是插入的时间戳是不同的。
例如,
First Cron:2017-07-12 15:31:28 + 01 Second Cron:2017-07-12 15:16:21.335547 + 01(插入时我使用CURRENT_TIMESTAMP)
也许这会在AngularJS中发生冲突......任何人都有想法以#34; 2017-07-12 15:31:28 + 01"在我的BB?我的时间戳字段是带有时区的时间戳。
如果我评论第二个cron,其他图表显示确定
AgregateDatabase:
AgregateDatabase.prototype.addRow = function (dbConnection, data) {
createLog('info', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'addRow','inicio');
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'addRow','type', data.type);
return new Promise(function (resolve, reject) {
pg.connect(dbConnection, function (err, client, done) {
if (err) {
createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'addRow', err);
reject(err);
return
}
if(data.type==='probing_live' || data.type==='probing_repeated' || data.type==='probing_passBy'){
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'addRow','data', data);
client.query("INSERT INTO default_dataset (id, timestamp, agregation_period, medium, maximum, minimum, sum, type, device_id, network_id, organization_id, labels) \
VALUES ($1, CURRENT_TIMESTAMP, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
[data.id, data.agregation_period, data.medium, data.maximum, data.minimum, data.sum, data.type, data.device_id, data.network_id, data.organization_id, data.labels],
function (err, result) {
done();
if (err) {
console.log("probing addRow errrrrrrro");
createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'probing addRow error', err);
reject(err);
} else {
console.log("probing addRow row added ", JSON.stringify(result));
createLog('info', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'probing addRow row added');
resolve(result.rows);
}
});
} else {
client.query("INSERT INTO default_dataset (id, timestamp, agregation_period, medium, maximum, minimum, sum, type, device_id, network_id, organization_id, labels) \
VALUES ($1, to_timestamp($2), $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
[data.id, data.timestamp, data.agregation_period, data.medium, data.maximum, data.minimum, data.sum, data.type, data.device_id, data.network_id, data.organization_id, data.labels],
function (err, result) {
done();
if (err) {
console.log("probing addRow errrrrrrro");
createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'probing addRow error', err);
reject(err);
} else {
console.log("probing addRow row added ", JSON.stringify(result));
createLog('info', __dirname, __filename.slice(__dirname.length + 1, -3), data.device_id, 'probing addRow row added');
resolve(result.rows);
}
});
}
});
});
}
答案 0 :(得分:0)
尝试截断current_timestamp,如下所示:
INSERT INTO default_dataset (....)
VALUES ($1, DATE_TRUNC('second',CURRENT_TIMESTAMP) .....