// MySQL counts changed rows, not matched rows. A no-op persist of the same
// state in the same second therefore returns RowsAffected == 0 even while
// the lease is still held. Confirm the lock before treating this as loss.
// Reuse `now` from the UPDATE so a clock tick cannot reintroduce false
// lock-loss; a lease that expires during the write is caught by the next heartbeat.
varheldint64
err=DB.Model(&SystemTask{}).
Where("task_id = ? AND status = ? AND locked_by = ?",taskID,SystemTaskStatusRunning,lockedBy).
Where("EXISTS (SELECT 1 FROM system_task_locks WHERE system_task_locks.task_id = system_tasks.task_id AND system_task_locks.locked_by = ? AND system_task_locks.locked_until >= ?)",lockedBy,now).