Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmservera/longrunningapi
https://github.com/jmservera/longrunningapi
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jmservera/longrunningapi
- Owner: jmservera
- License: mit
- Created: 2021-10-14T22:16:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-08T16:15:22.000Z (about 2 years ago)
- Last Synced: 2024-04-13T03:17:43.722Z (9 months ago)
- Language: JavaScript
- Size: 1.82 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# An example for a long running API call
When you have an API call that takes too much time, you should move it to a background service like explained in the [best performance recommendations](https://docs.microsoft.com/en-us/aspnet/core/performance/performance-best-practices?view=aspnetcore-5.0#complete-long-running-tasks-outside-of-http-requests). You can see some architectural examples in the [Azure Documentation](https://docs.microsoft.com/en-us/azure/architecture/guide/architecture-styles/web-queue-worker).
So, use this trick to allow the call run without timing-out only if you cannot move it to a background service right now, but plan to do so later.
This example maintains the underlying connection stream opened, and sends data regularly to the client from an asynchronous task until the long process ends, similar to what SignalR does with the [forever frame technique](https://stackoverflow.com/questions/19226761/what-is-the-difference-between-web-sockets-long-polling-server-sent-events-and). This technique avoids the problems that happen with any intermediate piece detecting an idle connection, but it may not be suitable for all use cases.
> This code is not production ready, you will need to do proper error handling, logging and threat protection.