Skip to content

Commit

Permalink
Ensures that the async calls are configured correctly on library boun…
Browse files Browse the repository at this point in the history
…daries (#112)
  • Loading branch information
chjahnert authored Aug 3, 2023
1 parent bfa3cb9 commit f18b23b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
36 changes: 36 additions & 0 deletions source/EXBP.Dipren/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,42 @@ public Engine(IEngineDataStore store, Configuration configuration = null, IEvent
/// </para>
/// </remarks>
public async Task RunAsync<TKey, TItem>(Job<TKey, TItem> job, bool wait, CancellationToken cancellation = default)
=> await this.RunImpAsync(job, wait, cancellation).ConfigureAwait(false);


/// <summary>
/// Executes a distributed processing job.
/// </summary>
/// <typeparam name="TKey">
/// The type of the item key.
/// </typeparam>
/// <typeparam name="TItem">
/// The type of items to process.
/// </typeparam>
/// <param name="job">
/// The job to start.
/// </param>
/// <param name="wait">
/// <see langword="true"/> to wait for the job to be ready; otherwise, <see langword="false"/>.
/// </param>
/// <param name="cancellation">
/// The <see cref="CancellationToken"/> used to propagate notifications that the operation should be
/// canceled.
/// </param>
/// <returns>
/// A <see cref="Task"/> that represents the asynchronous operation and can be used to access the result.
/// </returns>
/// <exception cref="JobNotScheduledException">
/// Argument <paramref name="wait"/> is <see langword="false"/> and the job has not yet been scheduled for
/// processing.
/// </exception>
/// <remarks>
/// <para>
/// If <paramref name="wait"/> is <see langword="true"/> and the job is not yet scheduled, the method will
/// wait for the job to be scheduled.
/// </para>
/// </remarks>
private async Task RunImpAsync<TKey, TItem>(Job<TKey, TItem> job, bool wait, CancellationToken cancellation)
{
Assert.ArgumentIsNotNull(job, nameof(job));

Expand Down
43 changes: 43 additions & 0 deletions source/EXBP.Dipren/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ public Scheduler(IEngineDataStore store, IEventHandler handler = null) : this(st
/// A <see cref="Task"/> object that represents the asynchronous operation.
/// </returns>
public async Task ScheduleAsync<TKey, TItem>(Job<TKey, TItem> job, Settings settings, CancellationToken cancellation = default)
=> await this.ScheduleImpAsync(job, settings, cancellation).ConfigureAwait(false);


/// <summary>
/// Schedules a distributed processing job.
/// </summary>
/// <typeparam name="TKey">
/// The type of the item key.
/// </typeparam>
/// <typeparam name="TItem">
/// The type of items to process.
/// </typeparam>
/// <param name="job">
/// The job to schedule for distributed processing.
/// </param>
/// <param name="settings">
/// The job settings to use.
/// </param>
/// <param name="cancellation">
/// The <see cref="CancellationToken"/> used to propagate notifications that the operation should be
/// canceled.
/// </param>
/// <returns>
/// A <see cref="Task"/> object that represents the asynchronous operation.
/// </returns>
private async Task ScheduleImpAsync<TKey, TItem>(Job<TKey, TItem> job, Settings settings, CancellationToken cancellation)
{
Assert.ArgumentIsNotNull(job, nameof(job));

Expand Down Expand Up @@ -104,6 +130,23 @@ public async Task ScheduleAsync<TKey, TItem>(Job<TKey, TItem> job, Settings sett
/// operation.
/// </returns>
public async Task<StatusReport> GetStatusReportAsync(string id, CancellationToken cancellation = default)
=> await this.GetStatusReportImpAsync(id, cancellation).ConfigureAwait(false);

/// <summary>
/// Gets a status report of the job with the specified unique identifier.
/// </summary>
/// <param name="id">
/// The unique identifier of the job.
/// </param>
/// <param name="cancellation">
/// The <see cref="CancellationToken"/> used to propagate notifications that the operation should be
/// canceled.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> of <see cref="StatusReport"/> object that represents the asynchronous
/// operation.
/// </returns>
private async Task<StatusReport> GetStatusReportImpAsync(string id, CancellationToken cancellation)
{
DateTime timestamp = this.Clock.GetCurrentTimestamp();

Expand Down

0 comments on commit f18b23b

Please sign in to comment.