- if feedback_fn is None:
- feedback_fn = logger.ToStdout
- if proc is None:
- proc = mcpu.Processor(feedback=feedback_fn)
- return proc.ExecOpCode(op)
+ # TODO: Fix feedback_fn situation.
+ cl = luxi.Client()
+ job = opcodes.Job(op_list=[op])
+ jid = SubmitJob(job)
+
+ query = {
+ "object": "jobs",
+ "fields": ["status"],
+ "names": [jid],
+ }
+
+ while True:
+ jdata = SubmitQuery(query)
+ if not jdata:
+ # job not found, go away!
+ raise errors.JobLost("Job with id %s lost" % jid)
+
+ status = jdata[0][0]
+ if status in (opcodes.Job.STATUS_SUCCESS, opcodes.Job.STATUS_FAIL):
+ break
+ time.sleep(1)
+
+ query["fields"].extend(["op_list", "op_status", "op_result"])
+ jdata = SubmitQuery(query)
+ if not jdata:
+ raise errors.JobLost("Job with id %s lost" % jid)
+ status, op_list, op_status, op_result = jdata[0]
+ if status != opcodes.Job.STATUS_SUCCESS:
+ raise errors.OpExecError(op_result[0])
+ return op_result[0]
+
+
+def SubmitJob(job, cl=None):
+ if cl is None:
+ cl = luxi.Client()
+ return cl.SubmitJob(job)
+
+
+def SubmitQuery(data, cl=None):
+ if cl is None:
+ cl = luxi.Client()
+ return cl.Query(data)