AsyncFlow.Queues.Generator
1.2.0
See the version list below for details.
dotnet add package AsyncFlow.Queues.Generator --version 1.2.0
NuGet\Install-Package AsyncFlow.Queues.Generator -Version 1.2.0
<PackageReference Include="AsyncFlow.Queues.Generator" Version="1.2.0" />
paket add AsyncFlow.Queues.Generator --version 1.2.0
#r "nuget: AsyncFlow.Queues.Generator, 1.2.0"
// Install AsyncFlow.Queues.Generator as a Cake Addin #addin nuget:?package=AsyncFlow.Queues.Generator&version=1.2.0 // Install AsyncFlow.Queues.Generator as a Cake Tool #tool nuget:?package=AsyncFlow.Queues.Generator&version=1.2.0
AsyncFlow Library
Integrate asynchronous job flows with ease in your .NET applications. AsyncFlow is designed for web applications that use a pattern where users call an invoke API, receive a job ID, and can then track and retrieve the job's results using separate endpoints.
Features
- Asynchronous Job Invocation: Easily handle long-running jobs by providing an immediate response with a job ID.
- Status Tracking: Allow users to track the status of their job.
- Flexible Result Retrieval: Once the job is complete, users can retrieve the result.
- Integration with Hangfire: Make use of the robust background processing library, Hangfire, to handle job execution.
- Extensible Cache Options: Store job results in-memory or use a distributed cache.
Getting Started
Installation
Use the package manager NuGet to install AsyncFlow packages:
dotnet add package AsyncFlow
dotnet add package AsyncFlow.Queues.Generator
Configuration
Setup Hangfire (or any supported background job processor):
builder.Services.AddHangfire(x => x.UseMemoryStorage()); builder.Services.AddHangfireServer(options => options.Queues = Flows.All));
Add AsyncFlow with Desired Cache:
For in-memory cache:
builder.Services.AddAsyncFlow(options => options.UseMemoryCache());
For distributed cache:
builder.Services.AddAsyncFlow(options => options.UseDistributedCache(yourDistributedCacheInstance));
Map Endpoints:
app.MapFlow<YourJobClass, YourRequestType, YourResponseType>("endpointName");
Certainly! Let's replace the C# record descriptions with JSON examples for the responses:
The Auto created API Endpoints
When you integrate the AsyncFlow
library into your application, the following API endpoints are provided for you:
Enqueue Endpoint:
- Path:
/[flowName]
- HTTP Method: POST
- Purpose: To initiate the async flow process.
- Response:
{ "RequestId": "12345-abcd", "DateTime": "2023-08-14T15:30:45Z" }
- Path:
Status Endpoint:
- Path:
/[flowName]/{jobId}/status
- HTTP Method: GET
- Purpose: To check the status of a previously enqueued request.
- Response:
{ "RequestId": "12345-abcd", "Status": "Processing", "CreatedAt": "2023-08-14T15:30:45Z", "progressData": { "progress": "Generating Data", "percentage": 90 } }
- Response:
- Path:
Result Endpoint:
- Path:
/[flowName]/{jobId}/result
- HTTP Method: GET
- Purpose: To retrieve the result of the job.
- Response: JSON that represents the result object.
- Path:
Delete Endpoint:
- Path:
/[flowName]/{jobId}
- HTTP Method: DELETE
- Purpose: To delete the result of the job.
- Response: No content (empty response).
- Path:
Error Endpoint:
- Path: /[flowName]/{jobId}/error
- HTTP Method: GET
- Purpose: To retrieve error details if a job fails.
- Response:
"JobId": "unique-job-id",
"Error": {
"Type": "ExceptionType",
"Message": "Detailed error message",
"StackTrace": "Stack trace details..."
}
}
Remember to replace the placeholders like "Details about the Result endpoint, including a JSON example." with the actual details for those endpoints if they provide responses similar to the ones you've described. If not, describe them as needed.
Also, make sure to guide your users on how to replace the [flowName]
placeholder appropriately.
Custom Endpoint Configuration
You can customize the behavior of the AsyncFlow endpoints using the AsyncFlowEndpointConfigurator
:
var configurator = new YourConfiguratorSubClass();
app.MapFlow<YourJobClass, YourRequestType, YourResponseType>("endpointName", configurator);
Usage Example
Define a job:
public class GenerateDataJob : IAsyncFlow<GenerateDataRequest, GenerateDataResponse>
{
public async Task<GenerateDataResponse> ProcessAsync(GenerateDataRequest request ,IProgress<ProgressData> progress , CancellationToken cancellationToken)
{
// Your logic here
}
}
Invoke it:
app.MapFlow<GenerateDataJob, GenerateDataRequest, GenerateDataResponse>("data");
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis (>= 4.4.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.4.0)
- System.Text.Json (>= 7.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.