< Summary

Information
Class: Api.Jobs.WaitForCompletedJobsResult
Assembly: Api
File(s): /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Jobs/IJobsInterface.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 128
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Jobs/IJobsInterface.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5using System.Text.Json;
 6using Api.Jobs.Models;
 7using NodaTime;
 8
 9namespace Api.Jobs;
 10
 11/// TODO: should be scoped and use scopes transaction
 12public interface IJobsInterfae
 13{
 14    /// <param name="timeout"> if timeout is zero returns current jobs or none if there
 15    /// isn't </param>
 16    public Task<JobData[]> PeekPendingJobs(
 17        uint timeout,
 18        uint? maxJobs,
 19        Guid? leaserId,
 20        string[]? jobTypes,
 21        CancellationToken ct
 22    );
 23
 24    /// <param name="timeout"> if timeout is zero returns current jobs or none if there
 25    /// isn't </param>
 26    public Task<JobData[]> LeasePendingJobs(
 27        uint timeout,
 28        uint? maxJobs,
 29        Guid? leaserId,
 30        string[]? jobTypes,
 31        CancellationToken ct
 32    );
 33
 34    public Task<IPeekJobResult[]> PeekJobs(Guid[] jobIds);
 35
 36    public Task<ILeaseJobResult[]> LeaseJobs(Guid[] jobIds, CancellationToken ct);
 37
 38    public Task<IExtendLeaseResult[]> ExtendJobLeases(Guid[] jobIds);
 39
 40    public Task<JobMarkAsCompleteResult[]> MarkJobsAsComplete(
 41        JobCompletionData[] jobCompletions
 42    );
 43
 44    /// <summary>
 45    /// waits for completed jobs in specified <paramref name="jobTypes"/> or all jobs if it is
 46    /// null
 47    ///
 48    /// waits at max <paramref name="timeout"/> or indefinitely if <paramref name="timeout"/> is 0
 49    ///</summary>
 50    ///
 51    /// <param name="jobIds"> limits result to specified ids does not filter by ids if null</param>
 52    ///
 53    /// <returns> returns null when <paramref name="timeout"/> is active and passes</returns>
 54    public Task<WaitForCompletedJobsResult?> WaitForCompletedJobsOrForSeconds(
 55        uint timeout,
 56        Instant after,
 57        uint? maxJobs,
 58        string[]? jobTypes,
 59        CancellationToken ct,
 60        Guid[]? jobIds = null
 61    );
 62}
 63
 064public record WaitForCompletedJobsResult(Guid[] JobIds, Instant LatestCompletedJobTime);
 65
 66public record JobCompletionData(Guid JobId, JsonDocument? CompletionData);
 67
 68#region PeekJobResult
 69public interface IPeekJobResult;
 70
 71public record Success(JobData Job) : IPeekJobResult;
 72
 73public record JobDoesNotExists : IPeekJobResult;
 74
 75#endregion
 76
 77#region LeaseJobResult
 78// TODO: switch to discriminated unions or closed interfaces
 79public interface ILeaseJobResult;
 80
 81public partial record NewLeaseEndTime : ILeaseJobResult;
 82
 83public record LeasingFailed(LeaseExtendFailReason Reason) : ILeaseJobResult;
 84
 85public enum LeaseFailReason
 86{
 87    CurrentlyLeased,
 88    AlreadyCompleted,
 89    JobDoesNotExist,
 90}
 91
 92#endregion
 93
 94
 95#region IExtendLeaseResult
 96
 97// TODO: switch to discriminated unions or closed interfaces
 98public interface IExtendLeaseResult;
 99
 100public partial record NewLeaseEndTime(Instant LeaseEnd) : IExtendLeaseResult;
 101
 102public record LeaseExtendFailed(LeaseExtendFailReason Reason) : IExtendLeaseResult;
 103
 104public enum LeaseExtendFailReason
 105{
 106    NotLeasedCurrently,
 107    LeasedBySomeoneElse,
 108    LeaseExtensionLimitReached,
 109    JobDoesNotExist,
 110}
 111#endregion
 112
 113public enum JobMarkAsCompleteResult
 114{
 115    Completed,
 116    LeasedBySomeoneElse,
 117    NotLeasedCurrently,
 118    AlreadyCompleted,
 119    JobDoesNotExist,
 120}
 121
 122public enum JobStatus
 123{
 124    Free,
 125    Leased,
 126    Completed,
 127    MaxRetryReached,
 128}