@@ -16,18 +16,14 @@ namespace Syrna.QuartzAdmin.ExecutionHistory;
1616
1717public 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 }
0 commit comments