Skip to content

Commit

Permalink
Fix failed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo committed Dec 31, 2024
1 parent 17ed4d0 commit 94b103b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,30 @@ public async Task<IActionResult> PostTestInvokeEvent(string functionName)
};

// Wait for our event to process
await tcs.Task;
// TODO: This is where we can timeout if the event was not processed in time
try {
await tcs.Task.WaitAsync(TimeSpan.FromSeconds(60));
} catch (TimeoutException e) {
eventContainer.ReportErrorResponse("Task Timed Out", "Error");

return Ok(new {
StatusCode = 202,
FunctionError = "Unhandled",
ExecutedVersion = "$LATEST",
Payload = "{\"errorMessage\":\"Task Timed Out\",\"errorType\":\"Error\"}"
});
} catch (Exception e) {
// This is a catch all for any other exceptions
// We should not get here
eventContainer.ReportErrorResponse("Unhandled Error", "Error");

return Ok(new {
StatusCode = 202,
FunctionError = "Unhandled",
ExecutedVersion = "$LATEST",
Payload = "{\"errorMessage\":\"Unhandled Error\",\"errorType\":\"Error\"}"
});
}

if (eventContainer.ErrorResponse != null)
{
Expand Down Expand Up @@ -164,6 +187,11 @@ public async Task GetNextInvocation()
await Response.Body.WriteAsync(buffer, 0, buffer.Length);
Response.Body.Close();
}

// TODO: The response from this function is the active event
// The event gets run by the lambda that called this endpoint

// This is where we need to setup a timeout for the event
}

[HttpPost("/2018-06-01/runtime/invocation/{awsRequestId}/response")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ public bool MarkExecuting()

public DateTime LastUpdated { get; private set; }

public Task TimeoutTask { get; set; }
public TaskCompletionSource DispatchedTCS { get; private set; } = new ();
public CancellationTokenSource TimedOutCTS { get; private set; } = new (1000);
public CancellationTokenSource TimedOutCTS { get; private set; }
private readonly object _statusLock = new();
private IEventContainer.Status _status = IEventContainer.Status.Queued;
public IEventContainer.Status EventStatus
Expand All @@ -289,6 +288,8 @@ public EventContainer(RuntimeApiDataStore dataStore, int eventCount, string even
this._dataStore = dataStore;
this.AwsRequestId = eventCount.ToString("D12");
this.EventJson = eventJson;
// TODO: Parse the JSON so we can get the timeout value
this.TimedOutCTS = new (1000);
}

public string FunctionArn
Expand Down Expand Up @@ -330,6 +331,10 @@ public void Cancel(string errorBody)
{
ReportErrorResponse("Throttled", errorBody);
}
else
{
ReportErrorResponse("Failed", errorBody);
}
}
}
}
Expand Down

0 comments on commit 94b103b

Please sign in to comment.