Merge pull request 'fix: millisecond precision timestamps and correct history ordering' (#58) from feat/jobs-system into dev
Reviewed-on: #58
This commit was merged in pull request #58.
This commit is contained in:
16
server/db.js
16
server/db.js
@@ -173,7 +173,8 @@ export function createInstance(data) {
|
||||
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
|
||||
`).run(data);
|
||||
db.prepare(
|
||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, 'created', NULL, NULL)`
|
||||
`INSERT INTO instance_history (vmid, field, old_value, new_value, changed_at)
|
||||
VALUES (?, 'created', NULL, NULL, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||
).run(data.vmid);
|
||||
}
|
||||
|
||||
@@ -184,12 +185,13 @@ export function updateInstance(vmid, data) {
|
||||
name=@name, state=@state, stack=@stack, vmid=@newVmid,
|
||||
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
|
||||
tailscale=@tailscale, andromeda=@andromeda, tailscale_ip=@tailscale_ip,
|
||||
hardware_acceleration=@hardware_acceleration, updated_at=datetime('now')
|
||||
hardware_acceleration=@hardware_acceleration, updated_at=strftime('%Y-%m-%dT%H:%M:%f', 'now')
|
||||
WHERE vmid=@vmid
|
||||
`).run({ ...data, newVmid: data.vmid, vmid });
|
||||
const newVmid = data.vmid;
|
||||
const insertEvt = db.prepare(
|
||||
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, ?, ?, ?)`
|
||||
`INSERT INTO instance_history (vmid, field, old_value, new_value, changed_at)
|
||||
VALUES (?, ?, ?, ?, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||
);
|
||||
for (const field of HISTORY_FIELDS) {
|
||||
const oldVal = String(old[field] ?? '');
|
||||
@@ -227,7 +229,7 @@ export function importInstances(rows, historyRows = []) {
|
||||
|
||||
export function getInstanceHistory(vmid) {
|
||||
return db.prepare(
|
||||
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at ASC, id ASC'
|
||||
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at DESC, id DESC'
|
||||
).all(vmid);
|
||||
}
|
||||
|
||||
@@ -309,12 +311,14 @@ export function updateJob(id, { enabled, schedule, config }) {
|
||||
}
|
||||
|
||||
export function createJobRun(jobId) {
|
||||
return Number(db.prepare('INSERT INTO job_runs (job_id) VALUES (?)').run(jobId).lastInsertRowid);
|
||||
return Number(db.prepare(
|
||||
`INSERT INTO job_runs (job_id, started_at) VALUES (?, strftime('%Y-%m-%dT%H:%M:%f', 'now'))`
|
||||
).run(jobId).lastInsertRowid);
|
||||
}
|
||||
|
||||
export function completeJobRun(runId, status, result) {
|
||||
db.prepare(`
|
||||
UPDATE job_runs SET ended_at=datetime('now'), status=@status, result=@result WHERE id=@id
|
||||
UPDATE job_runs SET ended_at=strftime('%Y-%m-%dT%H:%M:%f', 'now'), status=@status, result=@result WHERE id=@id
|
||||
`).run({ id: runId, status, result });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user