let call_query ~target query =
let module Target = Ketrew_target in
match Target.build_process target with
| `Long_running (plugin, _) ->
begin match Target.latest_run_parameters target with
| Some rp ->
begin match find_plugin plugin with
| Some m ->
let module Long_running = (val m : LONG_RUNNING) in
begin try
let c = Long_running.deserialize_exn rp in
Long_running.query c query
with e ->
fail Log.(s "Run-parameters deserialization" % exn e)
end
| None ->
let log = Log.(s "Plugin not found: " % sf "%S" plugin) in
fail log
end
| None -> fail Log.(s "Target has no run-parameters: " % Target.log target)
end
| other -> fail Log.(s "Target has no queries: " % Target.log target)