in src/task/CallHttpWithPollingTask.ts [44:86]
public trySetValue(child: TaskBase): void {
if (child.stateObj === TaskState.Completed) {
if (child.actionObj instanceof CallHttpAction) {
const resultObj = child.result as DurableHttpResponse;
const result = new DurableHttpResponse(
resultObj.statusCode,
resultObj.content,
resultObj.headers
);
if (result.statusCode === 202 && result.getHeader("Location")) {
const retryAfterHeaderValue = result.getHeader("Retry-After");
const delay: moment.Duration = retryAfterHeaderValue
? moment.duration(retryAfterHeaderValue, "s")
: this.defaultHttpAsyncRequestSleepDuration;
const currentTime = this.orchestrationContext.currentUtcDateTime;
const timerFireTime = moment(currentTime).add(delay).toDate();
// this should be safe since both types returned by this call
// (DFTimerTask and LongTimerTask) are TaskBase-conforming
const timerTask = (this.orchestrationContext.createTimer(
timerFireTime
) as unknown) as TaskBase;
const callHttpTask = new AtomicTask(
false,
new CallHttpAction(this.action.httpRequest)
);
this.addNewChildren([timerTask, callHttpTask]);
} else {
// Set the value of a non-redirect HTTP response as the value of the entire
// compound task
this.setValue(false, result);
}
}
} else {
// If any subtask failed, we fail the entire compound task
if (this.firstError === undefined) {
this.firstError = child.result as Error;
this.setValue(true, this.firstError);
}
}
}