- let rec loop () =
- let out = shout "timeout 120 koji buildinfo %s 2>&1 ||:" verrel in
- if state_complete out then
- true
- else if state_other out then
- false
- else if no_such_build out then
- false
- else (
- eprintf "%s\n" out;
- eprintf "koji_build_exists: unknown output\nretrying ...\n%!";
- loop ()
- )
- in
- let r = loop () in
- memory_set key "1";
- r
+ let out = shout "timeout 120 koji buildinfo %s 2>&1 ||:" verrel in
+ if no_such_build out then
+ failwith (sprintf "koji_build_state_task: %s: no such build" verrel);
+ let state =
+ try
+ let subs = Pcre.exec ~rex:state out in
+ match Pcre.get_substring subs 1 with
+ | "BUILDING" -> `Building
+ | "COMPLETE" -> `Complete
+ | "DELETED" -> `Deleted
+ | "FAILED" -> `Failed
+ | "CANCELED" -> `Canceled
+ | sub ->
+ failwith (sprintf "koji_build_state_task: %s: unknown build state '%s'"
+ verrel sub)
+ with
+ Not_found ->
+ failwith (sprintf "koji_build_state_task: %s: no build state found"
+ verrel) in
+ let task =
+ try
+ let subs = Pcre.exec ~rex:task_id out in
+ Some (int_of_string (Pcre.get_substring subs 1))
+ with
+ Not_found -> None in
+
+ if state == `Complete then
+ memory_set key "1";
+
+ state, task