def promise_then_job_fn_job(job, promise, *args, **kwargs):
"""
Toil job that runs a promise created with a then_job_fn handler.
Takes the promise, and the arguments to forward along to the handler, the
last of which is the (result, error) pair from the last promise which gets
processed to just a result.
Returns the promise's success result and error, as a pair.
"""
# The pickled handler in this case takes a bunch of arguments: the Toil job,
# and the success result from the last promise, and then any other arguments
# or kwargs that the user wanted to pass along.
then_handler = dill.loads(promise.then_dill)
# Pull out the results from the last promise
resolved, rejected = args[-1]
args = args[:-1]
if rejected is None:
# Actually run this child promise
# Stick the resolved value on
args = list(args) + [resolved]
try:
# Get the result from the then handler and resolve with it
result = then_handler(job, *args, **kwargs)
promise.handle_resolve(job, result)
except Exception as e:
# Reject with an error if there is one
Logger.error("".join(traceback.format_exception(*sys.exc_info())))
promise.handle_reject(job, e)
else:
# Parent promise rejected so we should not run
# Bubble up the error
promise.handle_reject(job, rejected)
return (promise.result, promise.err)
评论列表
文章目录