From 58f86e9d87730cdbf97f8f84aa196fc1fa1bdd59 Mon Sep 17 00:00:00 2001 From: Jose Luis Guerra Infante Date: Sat, 4 Apr 2026 00:46:54 +0200 Subject: [PATCH] feat: enhance NuGet package metadata and streamline CI/CD workflows - Added detailed package metadata (authors, description, tags, license, project URL) to `.csproj` files. - Included `README.md` in NuGet package distribution. - Optimized `nugetpackage.yml`: - Refined permissions for package publishing. - Consolidated .NET build setup for simplicity. - Unified NuGet push logic for GitHub Packages and NuGet.org with duplicate-check support. - Expanded `README.md` with comprehensive usage documentation, including setup, examples, and API reference. Signed-off-by: Jose Luis Guerra Infante --- .github/workflows/nugetpackage.yml | 25 +++-- README.md | 106 +++++++++++++++++- ...ework.Tasks.Management.Abstractions.csproj | 11 ++ .../NetFramework.Tasks.Management.csproj | 11 ++ 4 files changed, 139 insertions(+), 14 deletions(-) diff --git a/.github/workflows/nugetpackage.yml b/.github/workflows/nugetpackage.yml index b5fd4b0..a826d9a 100644 --- a/.github/workflows/nugetpackage.yml +++ b/.github/workflows/nugetpackage.yml @@ -5,14 +5,13 @@ on: tags: - "v[0-9]+.[0-9]+.[0-9]+" -env: - DOTNET_VERSION: '10.0' - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - jobs: release: runs-on: ubuntu-latest timeout-minutes: 15 + permissions: + contents: read + packages: write steps: - name: Checkout uses: actions/checkout@v4 @@ -25,7 +24,7 @@ jobs: - name: Set VERSION variable from tag run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - - name: Setup .NET (all versions for multi-targeting) + - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: | @@ -37,9 +36,7 @@ jobs: run: dotnet restore src/NetFramework.Task.Management.sln - name: Build - run: | - dotnet build src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj --configuration Release /p:Version=${VERSION} --no-restore - dotnet build src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj --configuration Release /p:Version=${VERSION} --no-restore + run: dotnet build src/NetFramework.Task.Management.sln --configuration Release /p:Version=${VERSION} --no-restore - name: Test run: dotnet test src/NetFramework.Tasks.Management.xUnit.Tests/ --configuration Release --no-build --logger "console;verbosity=normal" @@ -49,8 +46,12 @@ jobs: dotnet pack src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj --configuration Release /p:Version=${VERSION} --no-build --output $GITHUB_WORKSPACE/packages dotnet pack src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj --configuration Release /p:Version=${VERSION} --no-build --output $GITHUB_WORKSPACE/packages - - name: Push NetFramework.Tasks.Management - run: dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.${VERSION}.nupkg --source https://nuget.pkg.github.com/ryujose/index.json --api-key ${GITHUB_TOKEN} + - name: Push to GitHub Packages + run: | + dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.${VERSION}.nupkg --source https://nuget.pkg.github.com/ryujose/index.json --api-key ${{ secrets.GITHUB_TOKEN }} + dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.Abstractions.${VERSION}.nupkg --source https://nuget.pkg.github.com/ryujose/index.json --api-key ${{ secrets.GITHUB_TOKEN }} - - name: Push NetFramework.Tasks.Management.Abstractions - run: dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.Abstractions.${VERSION}.nupkg --source https://nuget.pkg.github.com/ryujose/index.json --api-key ${GITHUB_TOKEN} + - name: Push to NuGet.org + run: | + dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate + dotnet nuget push $GITHUB_WORKSPACE/packages/NetFramework.Tasks.Management.Abstractions.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate diff --git a/README.md b/README.md index c235082..6939aab 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,107 @@ # NetTaskManagement -This dependency will grant to you the ability to manipulate the life of the tasks around your app. +A .NET Standard 2.0 library for Task Parallel Library (TPL) orchestration with Dependency Injection support. -You will perform a better multi tasking app and a reusage of some tasks with each names when clearing them from the Garbage Collector. +Tasks are identified by **string key** and managed through a **status-based API** — no raw `Task` objects exposed to callers. The library handles the full task lifecycle: register → start → cancel → check completion → delete, and exposes an append-only observability queue that captures disposal metadata for external monitoring. + +## Packages + +| Package | NuGet | +|---|---| +| `NetFramework.Tasks.Management` | Core implementation | +| `NetFramework.Tasks.Management.Abstractions` | Interfaces, enums, and models only | + +## Installation + +```bash +dotnet add package NetFramework.Tasks.Management +``` + +If you only need the `ITaskManagement` contract (e.g. in a project that wires up DI but doesn't consume the implementation directly): + +```bash +dotnet add package NetFramework.Tasks.Management.Abstractions +``` + +## Quick start + +### Register the service + +```csharp +services.AddTaskManagement(); +``` + +### Inject and use `ITaskManagement` + +```csharp +public class MyService +{ + private readonly ITaskManagement _tasks; + + public MyService(ITaskManagement tasks) => _tasks = tasks; + + public void RunJob(string jobName) + { + var cts = new CancellationTokenSource(); + + _tasks.RegisterTask(jobName, state => + { + var token = ((CancellationTokenSource)state).Token; + while (!token.IsCancellationRequested) + { + // do work + } + }, cts); + + _tasks.StartTask(jobName); + } + + public void CancelJob(string jobName) => _tasks.CancelTask(jobName); +} +``` + +## API reference + +All methods return `TaskManagementStatus` — an enum value instead of throwing exceptions for expected outcomes. + +| Method | Description | +|---|---| +| `RegisterTask(name, action, cts)` | Registers a new task by name | +| `StartTask(name)` | Starts a previously registered task | +| `CancelTask(name)` | Requests cancellation via the task's `CancellationTokenSource` | +| `CheckTaskStatusCompleted(name, retry, timeoutMs)` | Polls until the task completes or the timeout elapses | +| `DeleteTask(name, sendToQueue)` | Disposes the task and removes it from the registry; optionally enqueues disposal metadata | +| `DequeueTaskDisposedDataModel(out model)` | Dequeues one disposal record for external monitoring | +| `GetTasksStatus()` | Returns a snapshot `Dictionary` of all live tasks | +| `CancelAllTasks(except, ref failed)` | Cancels all tasks, optionally skipping a list of names | +| `CheckAllTaskStatusCompleted(except, ref statuses, retry, timeoutMs)` | Polls completion for all tasks, optionally skipping a list of names | +| `GetCancellationTokenSource(name, ref cts)` | Retrieves the `CancellationTokenSource` for a registered task | + +### Status enum highlights + +| Status | Meaning | +|---|---| +| `Added` | Task registered successfully | +| `Started` | Task started successfully | +| `Canceled` | Cancellation requested | +| `Completed` | Task reached a completion state | +| `NotCompleted` | Polling timed out before completion | +| `Deleted` | Task disposed and removed | +| `TaskNotFound` | No task registered under that name | +| `AlreadyRegistered` | A task with that name already exists | + +## Observability queue + +When `DeleteTask(name, sendToQueue: true)` is called, a `TaskDisposedDataModel` record (task name, id, final status, disposed flag) is appended to an internal `ConcurrentQueue`. Dequeue and forward it to your logging or monitoring platform however you like: + +```csharp +if (_tasks.DequeueTaskDisposedDataModel(out var record) == TaskManagementStatus.ObjectInfoDequeued) +{ + logger.LogInformation("Task {Name} (id={Id}) finished with status {Status}", + record.TaskName, record.TaskId, record.TaskStatus); +} +``` + +## License + +MIT © Jose Luis Guerra Infante diff --git a/src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj b/src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj index 779b57f..03207bf 100644 --- a/src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj +++ b/src/NetFramework.Task.Management.Abstractions/NetFramework.Tasks.Management.Abstractions.csproj @@ -6,8 +6,19 @@ NetFramework.Tasks.Management.Abstractions + Jose Luis Guerra Infante + Copyright © Jose Luis Guerra Infante + Interfaces, enums, and models for NetFramework.Tasks.Management — a .NET Standard 2.0 TPL orchestration library with Dependency Injection support. Reference this package when you only need the ITaskManagement contract and status types without depending on the core implementation. + task tpl task-parallel-library dependency-injection abstractions interfaces netstandard dotnet + MIT + https://github.com/Ryujose/NetTaskManagement + README.md git https://github.com/Ryujose/NetTaskManagement + + + + diff --git a/src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj b/src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj index 8411831..2d0b060 100644 --- a/src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj +++ b/src/NetFramework.Task.Management/NetFramework.Tasks.Management.csproj @@ -6,10 +6,21 @@ NetFramework.Tasks.Management + Jose Luis Guerra Infante + Copyright © Jose Luis Guerra Infante + A .NET Standard 2.0 library for Task Parallel Library (TPL) orchestration with Dependency Injection support. Tasks are identified by string key and managed through a status-based API — register, start, cancel, check completion, and delete — without exposing raw Task objects to callers. Includes an append-only observability queue that captures disposal metadata for external monitoring. + task tpl task-parallel-library dependency-injection orchestration netstandard dotnet + MIT + https://github.com/Ryujose/NetTaskManagement + README.md git https://github.com/Ryujose/NetTaskManagement + + + +