Commit 23fc68d0 authored by Fardale's avatar Fardale

Improve jobq

delete without id will always delete the last job
better printing of the jobq
parent cf79be48
......@@ -35,9 +35,14 @@ let cmd id delete addr port pass () =
else false)
jobs
|> Array.of_list
|> Array.map (fun j ->
[| PrintBox.sprintf "%i" (fst j.id)
; PrintBox.text (String.concat " " j.args) |])
|> fun jobs ->
Array.init (Array.length jobs + 1) (fun i ->
if i = 0 then
[| PrintBox.text "ID"
; PrintBox.text "ARG"|]
else
[| PrintBox.sprintf "%i" (fst jobs.(i-1).id)
; PrintBox.text (String.concat " " jobs.(i-1).args) |])
|> PrintBox.grid |> PrintBox.frame
|> PrintBox_text.output stdout ;
Format.printf "@." ;
......
......@@ -142,8 +142,11 @@ let server_handler pass port sockaddr (ic, oc) =
(Serialization_j.string_of_query_data jobq))
>>= fun () ->
if delete then (
let id = CCOpt.get_or ~default:(!jobs_id - 1) id in
CCDeque.filter_in_place jobs (fun j -> fst j.id != id) ;
let last_id =
try fst (CCDeque.peek_back jobs).id with CCDeque.Empty -> 0
in
let id = CCOpt.get_or ~default:last_id id in
CCDeque.filter_in_place jobs (fun j -> fst j.id != id);
Logs_lwt.info (fun m -> m "Removing jobs with id %i" id) )
else
(let jobs_list =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment