Skip to content

Commit d603f43

Browse files
committed
MarkExecutingJobAsIncomplete: setting result is exception and returncode is -1 for tracking
1 parent c468dff commit d603f43

File tree

5 files changed

+60
-78
lines changed

5 files changed

+60
-78
lines changed

modules/src/Syrna.QuartzAdmin.Blazor/Pages/QuartzAdmin/History/History.razor

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,11 @@
208208
<Text TextColor="TextColor.Dark">
209209
@if (context.IsException ?? false)
210210
{
211-
@context.GetShortExceptionMessage()
212-
;
211+
@context.GetShortExceptionMessage();
213212
}
214213
else
215214
{
216-
@context.GetShortResultMessage()
217-
;
215+
@context.GetShortResultMessage();
218216
}
219217
</Text>
220218
@if (context.IsException ?? false)

modules/src/Syrna.QuartzAdmin.Domain/Syrna/QuartzAdmin/ExecutionHistory/AbpExecutionHistoryPlugin.cs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ namespace Syrna.QuartzAdmin.ExecutionHistory;
1616

1717
public class AbpExecutionHistoryPlugin : SchedulerListenerBase, ISchedulerPlugin, IJobListener, ITriggerListener
1818
{
19-
//protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>();
20-
//protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName!) ?? NullLogger.Instance);
21-
22-
private const int RESULT_MAX_LENGTH = 8000;
23-
private const int MAX_BATCH_SIZE = 50;
19+
private const int ResultMaxLength = 8000;
2420

2521
private IScheduler _scheduler = null!;
2622
private IExecutionHistoryStore _store = null!;
2723

2824
public Type StoreType { get; set; } = null!;
2925

30-
public string Name { get; set; } = string.Empty;
26+
public string Name { get; private set; } = string.Empty;
3127

3228
public Task Initialize(string pluginName, IScheduler scheduler, CancellationToken cancellationToken = default)
3329
{
@@ -202,27 +198,10 @@ public async Task JobExecutionVetoed(IJobExecutionContext context, CancellationT
202198
var log = CreateScheduleJobLogEntry(context, defaultIsSuccess: false);
203199
log.IsVetoed = true;
204200
await _store.Save(log);
205-
//var entry = await _store.Get(context.FireInstanceId);
206-
//if (entry != null)
207-
//{
208-
// var log = CreateScheduleJobLogEntry(context, defaultIsSuccess: false);
209-
// log.IsVetoed = true;
210-
// await _store.Save(log);
211-
//}
212201
}
213202

214203
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
215204
{
216-
//var entry = await _store.Get(context.FireInstanceId);
217-
//if (entry != null)
218-
//{
219-
// entry.FinishedTimeUtc = DateTime.UtcNow;
220-
// entry.ErrorMessage = jobException?.GetBaseException()?.ToString();
221-
//}
222-
//else
223-
//{
224-
// entry = CreateScheduleJobLogEntry(context, jobException, true);
225-
//}
226205
var entry = CreateScheduleJobLogEntry(context, jobException, true);
227206
entry.FinishedTimeUtc = DateTime.UtcNow;
228207
await _store.Save(entry);
@@ -345,42 +324,42 @@ await PrepareAutoJob(t, () =>
345324
}
346325
}
347326

348-
private async Task PrepareAutoJob(Type t, Func<TriggerBuilder> triggerBuilders_func)
327+
private async Task PrepareAutoJob(Type t, Func<TriggerBuilder> triggerBuildersFunc)
349328
{
350329
var lst = new List<TriggerBuilder>();
351-
var tb = triggerBuilders_func?.Invoke();
330+
var tb = triggerBuildersFunc?.Invoke();
352331
if (tb != null)
353332
{
354333
lst.Add(tb);
355334
}
356335
await PrepareAutoJob(t, lst);
357336
}
358337

359-
private IEnumerable<IScheduleJob> _scheduleJobs => LazyServiceProvider.LazyGetRequiredService<IEnumerable<IScheduleJob>>();
338+
private IEnumerable<IScheduleJob> ScheduleJobs => LazyServiceProvider.LazyGetRequiredService<IEnumerable<IScheduleJob>>();
360339

361340
private async Task PrepareAutoJob(Type t, IEnumerable<TriggerBuilder> triggerBuilders)
362341
{
363-
var job = from js in _scheduleJobs where js.JobDetail.JobType == t select js;
342+
var job = (from js in ScheduleJobs where js.JobDetail.JobType == t select js).ToList();
364343
if (job.Any())
365344
{
366345
var scheduleJob = job.First();
367-
var lstgs = (List<ITrigger>)scheduleJob.Triggers;
346+
var items = (List<ITrigger>)scheduleJob.Triggers;
368347
triggerBuilders.ToList().ForEach(triggerBuilder =>
369348
{
370-
lstgs.Add(triggerBuilder.ForJob(scheduleJob.JobDetail).Build());
349+
items.Add(triggerBuilder.ForJob(scheduleJob.JobDetail).Build());
371350
});
372351
}
373352
await Task.CompletedTask;
374353
}
375354

376355
private async Task RegisterAutoJobsAsync(CancellationToken cancellationToken)
377356
{
378-
if (_scheduleJobs == null || !_scheduleJobs.Any())
357+
if (ScheduleJobs == null || !ScheduleJobs.Any())
379358
{
380359
return;
381360
}
382361

383-
foreach (var scheduleJob in _scheduleJobs)
362+
foreach (var scheduleJob in ScheduleJobs)
384363
{
385364
var isNewJob = true;
386365
foreach (var trigger in scheduleJob.Triggers)
@@ -432,6 +411,7 @@ private ExecutionHistoryEntry CreateScheduleJobLogEntry(IJobExecutionContext con
432411
{
433412
log.ReturnCode = "-1";
434413
log.IsSuccess = false;
414+
log.IsException = true;
435415
log.ErrorMessage = "Canceled by user";
436416

437417
logDetail.ExecutionDetails = "Canceled by user";
@@ -471,7 +451,7 @@ private ExecutionHistoryEntry CreateScheduleJobLogEntry(IJobExecutionContext con
471451
if (context.Result != null)
472452
{
473453
var result = Convert.ToString(context.Result, CultureInfo.InvariantCulture);
474-
log.Result = result?.Substring(0, Math.Min(result.Length, RESULT_MAX_LENGTH));
454+
log.Result = result?.Substring(0, Math.Min(result.Length, ResultMaxLength));
475455
}
476456
}
477457
}

modules/src/Syrna.QuartzAdmin.Domain/Syrna/QuartzAdmin/ExecutionHistory/IExecutionHistoryStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public interface IExecutionHistoryStore
2828
Task AddExecutionLog(QuartzExecutionHistory log, CancellationToken cancelToken = default);
2929
ValueTask UpdateExecutionLog(QuartzExecutionHistory log);
3030
Task SaveChangesAsync(CancellationToken cancelToken = default);
31-
Task MarkExecutingJobAsIncomplete(CancellationToken cancellToken = default);
31+
Task MarkExecutingJobAsIncomplete(CancellationToken cancellationToken = default);
3232
}
3333
}
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using System.Threading;
4-
using Volo.Abp.Domain.Repositories;
5-
using System.Collections.Generic;
6-
using System.Linq.Expressions;
7-
using System.Linq;
8-
9-
namespace Syrna.QuartzAdmin.ExecutionHistory;
10-
11-
public interface IQuartzExecutionHistoryRepository : IBasicRepository<QuartzExecutionHistory, long>
12-
{
13-
Task<QuartzExecutionHistory> FindByFireInstanceIdAsync(string fireInstanceId, CancellationToken cancellationToken = default);
14-
15-
Task<List<QuartzExecutionHistory>> GetLastOfEveryJobAsync(string schedulerName, int limitPerJob, CancellationToken cancellationToken = default);
16-
17-
Task<List<QuartzExecutionHistory>> GetLastOfEveryTriggerAsync(
18-
string schedulerName,
19-
int limitPerTrigger,
20-
int skipPerTrigger = 0,
21-
CancellationToken cancellationToken = default);
22-
23-
Task<List<QuartzExecutionHistory>> GetLastAsync(string schedulerName, int limit, CancellationToken cancellationToken = default);
24-
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Threading;
4+
using Volo.Abp.Domain.Repositories;
5+
using System.Collections.Generic;
6+
using System.Linq.Expressions;
7+
using System.Linq;
8+
9+
namespace Syrna.QuartzAdmin.ExecutionHistory;
10+
11+
public interface IQuartzExecutionHistoryRepository : IBasicRepository<QuartzExecutionHistory, long>
12+
{
13+
Task<QuartzExecutionHistory> FindByFireInstanceIdAsync(string fireInstanceId, CancellationToken cancellationToken = default);
14+
15+
Task<List<QuartzExecutionHistory>> GetLastOfEveryJobAsync(string schedulerName, int limitPerJob, CancellationToken cancellationToken = default);
16+
17+
Task<List<QuartzExecutionHistory>> GetLastOfEveryTriggerAsync(
18+
string schedulerName,
19+
int limitPerTrigger,
20+
int skipPerTrigger = 0,
21+
CancellationToken cancellationToken = default);
22+
23+
Task<List<QuartzExecutionHistory>> GetLastAsync(string schedulerName, int limit, CancellationToken cancellationToken = default);
24+
2525
Task PurgeAsync(CancellationToken cancellationToken = default);
2626

2727
//
28-
Task<IQueryable<QuartzExecutionHistory>> GetLatestExecutionLog(string jobName, string jobGroup, string triggerName, string triggerGroup, long firstLogId = 0, HashSet<LogType> logTypes = null);
29-
Task<IQueryable<QuartzExecutionHistory>> GetExecutionLogs(ExecutionLogFilter filter = null, long firstLogId = 0);
30-
Task<IList<string>> GetJobNames();
31-
Task<IList<string>> GetJobGroups();
32-
Task<IList<string>> GetTriggerNames();
33-
Task<IList<string>> GetTriggerGroups();
34-
Task<JobExecutionStatusSummaryModel> GetJobExecutionStatusSummary(DateTimeOffset? startTimeUtc, DateTimeOffset? endTimeUtc = null);
35-
Task MarkExecutingJobAsIncomplete(CancellationToken cancellToken = default);
36-
Task<bool> AnyAsync(Expression<Func<QuartzExecutionHistory, bool>> predicate);
37-
Task<QuartzExecutionHistory> FirstOrDefaultAsync(Expression<Func<QuartzExecutionHistory, bool>> predicate);
38-
Task<int> DeleteLogsByDays(int daysToKeep, CancellationToken cancelToken = default);
39-
Task SaveChangesAsync(CancellationToken cancelToken = default);
40-
41-
}
28+
Task<IQueryable<QuartzExecutionHistory>> GetLatestExecutionLog(string jobName, string jobGroup, string triggerName, string triggerGroup, long firstLogId = 0, HashSet<LogType> logTypes = null);
29+
Task<IQueryable<QuartzExecutionHistory>> GetExecutionLogs(ExecutionLogFilter filter = null, long firstLogId = 0);
30+
Task<IList<string>> GetJobNames();
31+
Task<IList<string>> GetJobGroups();
32+
Task<IList<string>> GetTriggerNames();
33+
Task<IList<string>> GetTriggerGroups();
34+
Task<JobExecutionStatusSummaryModel> GetJobExecutionStatusSummary(DateTimeOffset? startTimeUtc, DateTimeOffset? endTimeUtc = null);
35+
Task MarkExecutingJobAsIncomplete(CancellationToken cancellationToken = default);
36+
Task<bool> AnyAsync(Expression<Func<QuartzExecutionHistory, bool>> predicate);
37+
Task<QuartzExecutionHistory> FirstOrDefaultAsync(Expression<Func<QuartzExecutionHistory, bool>> predicate);
38+
Task<int> DeleteLogsByDays(int daysToKeep, CancellationToken cancelToken = default);
39+
Task SaveChangesAsync(CancellationToken cancelToken = default);
40+
41+
}

modules/src/Syrna.QuartzAdmin.EntityFrameworkCore/Syrna/QuartzAdmin/ExecutionHistory/QuartzExecutionHistoryRepository.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,23 @@ public async Task<JobExecutionStatusSummaryModel> GetJobExecutionStatusSummary(D
295295
};
296296
}
297297

298-
public async Task MarkExecutingJobAsIncomplete(CancellationToken cancellToken = default)
298+
public async Task MarkExecutingJobAsIncomplete(CancellationToken cancellationToken = default)
299299
{
300300
var isSuccessNullJobs = (await GetQueryableAsync()).Where(l => !l.IsSuccess.HasValue &&
301301
l.LogType == LogType.ScheduleJob);
302302

303303
foreach (var log in isSuccessNullJobs)
304304
{
305305
log.IsSuccess = false;
306+
log.IsException = true;
306307
log.ErrorMessage = "Incomplete execution.";
307-
log.JobRunTime = null;
308+
log.ReturnCode = "-1";
309+
//log.JobRunTime = null;
310+
//log.ExecutionLogDetail = new();
311+
//log.ExecutionLogDetail.ExecutionDetails = "Incomplete execution.";
308312
}
309313

310-
await SaveChangesAsync(cancellToken);
314+
await SaveChangesAsync(cancellationToken);
311315
}
312316

313317
public async Task<bool> AnyAsync(Expression<Func<QuartzExecutionHistory, bool>> predicate)

0 commit comments

Comments
 (0)