- if feedback_fn is None:
- feedback_fn = logger.ToStdout
- if proc is None:
- proc = mcpu.Processor(feedback=feedback_fn)
- return proc.ExecOpCode(op)
-
-
-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)
+ # TODO: Fix feedback_fn situation.
+ cl = luxi.Client()
+
+ job_id = cl.SubmitJob([op])
+
+ while True:
+ jobs = cl.QueryJobs([job_id], ["status"])
+ if not jobs:
+ # job not found, go away!
+ raise errors.JobLost("Job with id %s lost" % job_id)
+
+ # TODO: Handle canceled and archived jobs
+ status = jobs[0][0]
+ if status in (constants.JOB_STATUS_SUCCESS, constants.JOB_STATUS_ERROR):
+ break
+ time.sleep(1)
+
+ jobs = cl.QueryJobs([job_id], ["status", "result"])
+ if not jobs:
+ raise errors.JobLost("Job with id %s lost" % job_id)
+
+ status, result = jobs[0]
+ if status == constants.JOB_STATUS_SUCCESS:
+ return result[0]
+ else:
+ raise errors.OpExecError(result)