Skip to content

Commit dc91f76

Browse files
authored
Extended Termination of a job with detailed and also with adjustable … (#349)
* Extended Termination of a job with detailed and also with adjustable status * updated to default set skipped on variable
1 parent bee0902 commit dc91f76

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/TickerQ/Exceptions/TerminateExecutionException.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
using System;
2+
using TickerQ.Utilities.Enums;
23

34
namespace TickerQ.Exceptions
45
{
56
internal class TerminateExecutionException : Exception
67
{
8+
internal readonly TickerStatus Status = TickerStatus.Skipped;
79
public TerminateExecutionException(string message) : base(message) { }
10+
public TerminateExecutionException(TickerStatus tickerType, string message) : base(message) {}
11+
public TerminateExecutionException(string message, Exception innerException) : base(message, innerException) {}
12+
public TerminateExecutionException(TickerStatus tickerType, string message, Exception innerException) : base(message, innerException)
13+
=> Status = tickerType;
814
}
915

1016
internal class ExceptionDetailClassForSerialization

src/TickerQ/Src/TickerExecutionTaskHandler.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,23 @@ private async Task RunContextFunctionAsync(InternalFunctionContext context, bool
217217
}
218218
catch (TerminateExecutionException ex)
219219
{
220-
context.SetProperty(x => x.Status, TickerStatus.Skipped)
220+
context.SetProperty(x => x.Status, ex.Status)
221221
.SetProperty(x => x.ExecutedAt, _clock.UtcNow)
222-
.SetProperty(x => x.ElapsedTime, stopWatch.ElapsedMilliseconds)
223-
.SetProperty(x => x.ExceptionDetails, ex.Message);
222+
.SetProperty(x => x.ElapsedTime, stopWatch.ElapsedMilliseconds);
223+
224+
if (ex.InnerException != null)
225+
{
226+
context.SetProperty(x => x.ExceptionDetails, ex.InnerException.Message);
227+
jobActivity?.SetTag("tickerq.job.skip_reason", ex.InnerException.Message);
228+
}
229+
else
230+
{
231+
context.SetProperty(x => x.ExceptionDetails, ex.Message);
232+
jobActivity?.SetTag("tickerq.job.skip_reason", ex.Message);
233+
}
224234

225235
// Add skip tags to activity
226236
jobActivity?.SetTag("tickerq.job.final_status", context.Status.ToString());
227-
jobActivity?.SetTag("tickerq.job.skip_reason", ex.Message);
228237

229238
// Log job skipped
230239
_tickerQInstrumentation.LogJobSkipped(context.TickerId, context.FunctionName, ex.Message);

0 commit comments

Comments
 (0)