let flush t =
database t
>>= fun db ->
let action =
let key = Unique_id.create () in
let value = Ketrew_measurement.Collection.serialize t.measurements in
Trakeva.Action.(set ~collection:"measurements" ~key value)
in
begin Database.act db ~action
>>= function
| `Done ->
Ketrew_measurement.Collection.clear t.measurements;
return ()
| `Not_done -> fail (`Database_unavailable "measurements")
end