Skip to content

Commit

Permalink
pp function for reports
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Aug 19, 2024
1 parent 22870e7 commit 64ff00c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/db/sync.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ type report = { status : status; sync_progress : progress option }

let initial_report = { status = Unknown; sync_progress = None }

let status_to_string = function
| Unknown -> "Unknown"
| In_sync -> "Synchronized"
| Inconsistent -> "Inconsistent"
| New_items { first_missing_key; first_unfetched_key; last_source_item_key }
->
Format.sprintf "New items: last: %i missing: %i unfetched: %i"
last_source_item_key first_missing_key first_unfetched_key
| Partial_fetch { first_unfetched_key; last_source_item_key } ->
Format.sprintf "Partial: last: %i unfetched: %i" first_unfetched_key
first_unfetched_key

let pp_progress fmt { total; remaining } =
Format.fprintf fmt "(%i/%i)" remaining total

let pp_report fmt { status; sync_progress } =
let status = status_to_string status in
Format.fprintf fmt "%s%a" status
(Format.pp_print_option pp_progress)
sync_progress

let log_status = function
| Unknown -> Console.info [ "Database status is unknown" ]
| In_sync -> Console.info [ "Database is synchronized" ]
Expand Down
1 change: 1 addition & 0 deletions lib/db/sync.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type progress = { total : int; remaining : int }
type report = { status : status; sync_progress : progress option }

val initial_report : report
val pp_report : Format.formatter -> report -> unit

val check_and_sync :
?report:(report -> unit) ->
Expand Down

0 comments on commit 64ff00c

Please sign in to comment.