Skip to content

Commit f3894df

Browse files
committed
Rename IDurableJobRun to IJobRunContext and update references across the codebase
1 parent 50d6244 commit f3894df

12 files changed

Lines changed: 37 additions & 37 deletions

File tree

‎src/Orleans.DurableJobs/Hosting/DurableJobsOptions.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public sealed class DurableJobsOptions
3838
/// the time when the job should be retried, or <see langword="null"/> if the job should not be retried.
3939
/// Default: Retry up to 5 times with exponential backoff (2^n seconds).
4040
/// </summary>
41-
public Func<IDurableJobRun, Exception, DateTimeOffset?> ShouldRetry { get; set; } = DefaultShouldRetry;
41+
public Func<IJobRunContext, Exception, DateTimeOffset?> ShouldRetry { get; set; } = DefaultShouldRetry;
4242

43-
private static DateTimeOffset? DefaultShouldRetry(IDurableJobRun jobContext, Exception ex)
43+
private static DateTimeOffset? DefaultShouldRetry(IJobRunContext jobContext, Exception ex)
4444
{
4545
// Default retry logic: retry up to 5 times with exponential backoff
4646
if (jobContext.DequeueCount >= 5)

‎src/Orleans.DurableJobs/IDurableJobHandler.cs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Orleans.DurableJobs;
66
/// <summary>
77
/// Provides contextual information about a durable job execution.
88
/// </summary>
9-
public interface IDurableJobRun
9+
public interface IJobRunContext
1010
{
1111
/// <summary>
1212
/// Gets the durable job being executed.
@@ -28,7 +28,7 @@ public interface IDurableJobRun
2828
/// Represents the execution context for a durable job.
2929
/// </summary>
3030
[GenerateSerializer]
31-
internal class DurableJobRun : IDurableJobRun
31+
internal class JobRunContext : IJobRunContext
3232
{
3333
/// <summary>
3434
/// Gets the durable job being executed.
@@ -49,12 +49,12 @@ internal class DurableJobRun : IDurableJobRun
4949
public int DequeueCount { get; }
5050

5151
/// <summary>
52-
/// Initializes a new instance of the <see cref="DurableJobRun"/> class.
52+
/// Initializes a new instance of the <see cref="JobRunContext"/> class.
5353
/// </summary>
5454
/// <param name="job">The durable job to execute.</param>
5555
/// <param name="runId">The unique identifier for this execution run.</param>
5656
/// <param name="retryCount">The number of times this job has been dequeued, including retries.</param>
57-
public DurableJobRun(DurableJob job, string runId, int retryCount)
57+
public JobRunContext(DurableJob job, string runId, int retryCount)
5858
{
5959
Job = job;
6060
RunId = runId;
@@ -76,7 +76,7 @@ public DurableJobRun(DurableJob job, string runId, int retryCount)
7676
/// <code>
7777
/// public class MyGrain : Grain, IDurableJobHandler
7878
/// {
79-
/// public Task ExecuteJobAsync(IDurableJobRun context, CancellationToken cancellationToken)
79+
/// public Task ExecuteJobAsync(IJobRunContext context, CancellationToken cancellationToken)
8080
/// {
8181
/// // Process the durable job
8282
/// var jobName = context.Job.Name;
@@ -106,8 +106,8 @@ public interface IDurableJobHandler
106106
/// </para>
107107
/// <para>
108108
/// If the method throws an exception and a retry policy is configured, the job may be retried.
109-
/// The <see cref="IDurableJobRun.DequeueCount"/> property can be used to determine if this is a retry attempt.
109+
/// The <see cref="IJobRunContext.DequeueCount"/> property can be used to determine if this is a retry attempt.
110110
/// </para>
111111
/// </remarks>
112-
Task ExecuteJobAsync(IDurableJobRun context, CancellationToken cancellationToken);
112+
Task ExecuteJobAsync(IJobRunContext context, CancellationToken cancellationToken);
113113
}

‎src/Orleans.DurableJobs/IDurableJobReceiverExtension.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal interface IDurableJobReceiverExtension : IGrainExtension
1717
/// <param name="context">The context containing information about the durable job.</param>
1818
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
1919
/// <returns>A task that represents the asynchronous operation.</returns>
20-
Task DeliverDurableJobAsync(IDurableJobRun context, CancellationToken cancellationToken);
20+
Task DeliverDurableJobAsync(IJobRunContext context, CancellationToken cancellationToken);
2121
}
2222

2323
/// <inheritdoc />
@@ -32,7 +32,7 @@ public DurableJobReceiverExtension(IGrainContext grain, ILogger<DurableJobReceiv
3232
_logger = logger;
3333
}
3434

35-
public async Task DeliverDurableJobAsync(IDurableJobRun context, CancellationToken cancellationToken)
35+
public async Task DeliverDurableJobAsync(IJobRunContext context, CancellationToken cancellationToken)
3636
{
3737
if (_grain.GrainInstance is IDurableJobHandler handler)
3838
{

‎src/Orleans.DurableJobs/InMemoryJobQueue.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Orleans.DurableJobs;
1010
/// Provides an in-memory priority queue for managing durable jobs based on their due times.
1111
/// Jobs are organized into time-based buckets and enumerated asynchronously as they become due.
1212
/// </summary>
13-
internal sealed class InMemoryJobQueue : IAsyncEnumerable<IDurableJobRun>
13+
internal sealed class InMemoryJobQueue : IAsyncEnumerable<IJobRunContext>
1414
{
1515
private readonly PriorityQueue<JobBucket, DateTimeOffset> _queue = new();
1616
private readonly Dictionary<string, JobBucket> _jobsIdToBucket = new();
@@ -91,7 +91,7 @@ public bool CancelJob(string jobId)
9191
/// The job is removed from its current bucket and added to a new bucket based on the specified due time.
9292
/// The dequeue count from the context is preserved.
9393
/// </remarks>
94-
public void RetryJobLater(IDurableJobRun jobContext, DateTimeOffset newDueTime)
94+
public void RetryJobLater(IJobRunContext jobContext, DateTimeOffset newDueTime)
9595
{
9696
var jobId = jobContext.Job.Id;
9797
var newJob = new DurableJob
@@ -122,10 +122,10 @@ public void RetryJobLater(IDurableJobRun jobContext, DateTimeOffset newDueTime)
122122
/// </summary>
123123
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
124124
/// <returns>
125-
/// An async enumerator that returns <see cref="IDurableJobRun"/> instances for jobs that are due.
125+
/// An async enumerator that returns <see cref="IJobRunContext"/> instances for jobs that are due.
126126
/// The enumerator checks for due jobs every second and terminates when the queue is marked complete and empty.
127127
/// </returns>
128-
public async IAsyncEnumerator<IDurableJobRun> GetAsyncEnumerator(CancellationToken cancellationToken = default)
128+
public async IAsyncEnumerator<IJobRunContext> GetAsyncEnumerator(CancellationToken cancellationToken = default)
129129
{
130130
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
131131
while (true)
@@ -169,7 +169,7 @@ public async IAsyncEnumerator<IDurableJobRun> GetAsyncEnumerator(CancellationTok
169169

170170
if (shouldYield)
171171
{
172-
yield return new DurableJobRun(job, Guid.NewGuid().ToString(), dequeueCount + 1);
172+
yield return new JobRunContext(job, Guid.NewGuid().ToString(), dequeueCount + 1);
173173
}
174174
}
175175

‎src/Orleans.DurableJobs/JobShard.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface IJobShard : IAsyncDisposable
5151
/// Consumes durable jobs from this shard in order of their due time.
5252
/// </summary>
5353
/// <returns>An asynchronous enumerable of durable job contexts.</returns>
54-
IAsyncEnumerable<IDurableJobRun> ConsumeDurableJobsAsync();
54+
IAsyncEnumerable<IJobRunContext> ConsumeDurableJobsAsync();
5555

5656
/// <summary>
5757
/// Gets the number of jobs currently scheduled in this shard.
@@ -81,7 +81,7 @@ public interface IJobShard : IAsyncDisposable
8181
/// <param name="newDueTime">The new due time for the job.</param>
8282
/// <param name="cancellationToken">A token to cancel the operation.</param>
8383
/// <returns>A task that represents the asynchronous operation.</returns>
84-
Task RetryJobLaterAsync(IDurableJobRun jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken);
84+
Task RetryJobLaterAsync(IJobRunContext jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken);
8585

8686
/// <summary>
8787
/// Attempts to schedule a new job on this shard.
@@ -136,7 +136,7 @@ protected JobShard(string id, DateTimeOffset startTime, DateTimeOffset endTime)
136136
public ValueTask<int> GetJobCountAsync() => ValueTask.FromResult(_jobQueue.Count);
137137

138138
/// <inheritdoc/>
139-
public IAsyncEnumerable<IDurableJobRun> ConsumeDurableJobsAsync()
139+
public IAsyncEnumerable<IJobRunContext> ConsumeDurableJobsAsync()
140140
{
141141
return _jobQueue;
142142
}
@@ -186,7 +186,7 @@ public Task MarkAsCompleteAsync(CancellationToken cancellationToken)
186186
}
187187

188188
/// <inheritdoc/>
189-
public async Task RetryJobLaterAsync(IDurableJobRun jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken)
189+
public async Task RetryJobLaterAsync(IJobRunContext jobContext, DateTimeOffset newDueTime, CancellationToken cancellationToken)
190190
{
191191
await PersistRetryJobAsync(jobContext.Job.Id, newDueTime, cancellationToken);
192192
_jobQueue.RetryJobLater(jobContext, newDueTime);

‎src/Orleans.DurableJobs/README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public class NotificationGrain : Grain, INotificationGrain, IDurableJobHandler
170170
}
171171

172172
// This method is called when the durable job executes
173-
public Task ExecuteJobAsync(IDurableJobRun context, CancellationToken cancellationToken)
173+
public Task ExecuteJobAsync(IJobRunContext context, CancellationToken cancellationToken)
174174
{
175175
var userId = this.GetPrimaryKeyString();
176176
var message = context.Job.Metadata?["Message"];
@@ -253,7 +253,7 @@ public class OrderGrain : Grain, IOrderGrain, IDurableJobHandler
253253
await _orderService.CancelOrderAsync(orderId);
254254
}
255255

256-
public async Task ExecuteJobAsync(IDurableJobRun context, CancellationToken cancellationToken)
256+
public async Task ExecuteJobAsync(IJobRunContext context, CancellationToken cancellationToken)
257257
{
258258
var step = context.Job.Metadata!["Step"];
259259
var orderId = this.GetPrimaryKey();
@@ -270,7 +270,7 @@ public class OrderGrain : Grain, IOrderGrain, IDurableJobHandler
270270
}
271271
}
272272

273-
private async Task HandleDeliveryReminder(IDurableJobRun context, CancellationToken ct)
273+
private async Task HandleDeliveryReminder(IJobRunContext context, CancellationToken ct)
274274
{
275275
var customerId = context.Job.Metadata!["CustomerId"];
276276
var orderNumber = context.Job.Metadata["OrderNumber"];
@@ -304,7 +304,7 @@ public class PaymentProcessorGrain : Grain, IDurableJobHandler
304304
private readonly IPaymentService _paymentService;
305305
private readonly ILogger<PaymentProcessorGrain> _logger;
306306

307-
public Task ExecuteJobAsync(IDurableJobRun context, CancellationToken cancellationToken)
307+
public Task ExecuteJobAsync(IJobRunContext context, CancellationToken cancellationToken)
308308
{
309309
var paymentId = context.Job.Metadata?["PaymentId"];
310310

‎src/Orleans.DurableJobs/ShardExecutor.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task RunShardAsync(IJobShard shard, CancellationToken cancellationT
8484
}
8585

8686
private async Task RunJobAsync(
87-
IDurableJobRun jobContext,
87+
IJobRunContext jobContext,
8888
IJobShard shard,
8989
ConcurrentDictionary<string, Task> runningTasks,
9090
CancellationToken cancellationToken)

‎test/Grains/TestGrainInterfaces/IDurableJobGrain.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IDurableJobGrain : IGrainWithStringKey
2121

2222
Task<DateTimeOffset> GetJobExecutionTime(string jobId);
2323

24-
Task<IDurableJobRun> GetJobRun(string jobId);
24+
Task<IJobRunContext> GetJobRun(string jobId);
2525

2626
Task<bool> WasCancellationTokenCancelled(string jobId);
2727
}

‎test/Grains/TestGrainInterfaces/IRetryTestGrain.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public interface IRetryTestGrain : IGrainWithStringKey
1919

2020
Task<List<int>> GetJobDequeueCountHistory(string jobId);
2121

22-
Task<IDurableJobRun> GetFinalJobRun(string jobId);
22+
Task<IJobRunContext> GetFinalJobRun(string jobId);
2323
}

‎test/Grains/TestGrains/DurableJobGrain.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DurableJobGrain : Grain, IDurableJobGrain, IDurableJobHandler
1414
{
1515
private Dictionary<string, TaskCompletionSource> jobRunStatus = new();
1616
private Dictionary<string, DateTimeOffset> jobExecutionTimes = new();
17-
private Dictionary<string, IDurableJobRun> jobContexts = new();
17+
private Dictionary<string, IJobRunContext> jobContexts = new();
1818
private Dictionary<string, bool> cancellationTokenStatus = new();
1919
private readonly ILocalDurableJobManager _localDurableJobManager;
2020
private readonly ILogger<DurableJobGrain> _logger;
@@ -30,7 +30,7 @@ public Task<bool> HasJobRan(string jobId)
3030
return Task.FromResult(jobRunStatus.TryGetValue(jobId, out var taskResult) && taskResult.Task.IsCompleted);
3131
}
3232

33-
public Task ExecuteJobAsync(IDurableJobRun ctx, CancellationToken cancellationToken)
33+
public Task ExecuteJobAsync(IJobRunContext ctx, CancellationToken cancellationToken)
3434
{
3535
_logger.LogInformation("Job {JobId} received at {ReceivedTime}", ctx.Job.Id, DateTime.UtcNow);
3636
jobExecutionTimes[ctx.Job.Id] = DateTimeOffset.UtcNow;
@@ -74,7 +74,7 @@ public Task<DateTimeOffset> GetJobExecutionTime(string jobId)
7474
return Task.FromResult(time);
7575
}
7676

77-
public Task<IDurableJobRun> GetJobRun(string jobId)
77+
public Task<IJobRunContext> GetJobRun(string jobId)
7878
{
7979
if (!jobContexts.TryGetValue(jobId, out var ctx))
8080
{

0 commit comments

Comments
 (0)