diff --git a/src/FabulousScheduler.Cron/Abstraction/BaseCronJob.cs b/src/FabulousScheduler.Cron/Abstraction/BaseCronJob.cs index 5eef336..767275c 100644 --- a/src/FabulousScheduler.Cron/Abstraction/BaseCronJob.cs +++ b/src/FabulousScheduler.Cron/Abstraction/BaseCronJob.cs @@ -116,7 +116,6 @@ public async Task> ExecuteAsync() else { Interlocked.Increment(ref _totalFail); - return new JobFail(CronJobFailEnum.FailedExecute, this.ID, $"the job {res.JobID} was finish with error"); } return res; diff --git a/src/FabulousScheduler.Queue/Abstraction/BaseQueueJob.cs b/src/FabulousScheduler.Queue/Abstraction/BaseQueueJob.cs index f944d9e..e945d37 100644 --- a/src/FabulousScheduler.Queue/Abstraction/BaseQueueJob.cs +++ b/src/FabulousScheduler.Queue/Abstraction/BaseQueueJob.cs @@ -85,6 +85,10 @@ public async Task> ExecuteAsync() { LastSuccessExecute = dt; } + // else + // { + // Interlocked.Increment(ref _totalFail); + // } return res; } diff --git a/src/FabulousScheduler/Cron/CronJobManager.cs b/src/FabulousScheduler/Cron/CronJobManager.cs index f3143d3..e9e1a20 100644 --- a/src/FabulousScheduler/Cron/CronJobManager.cs +++ b/src/FabulousScheduler/Cron/CronJobManager.cs @@ -11,7 +11,7 @@ namespace FabulousScheduler.Cron; /// public static class CronJobManager { - private static object _sync = new object(); + private static readonly object _syncScheduler = new(); private static Config? _config; private static CronScheduler? _scheduler; @@ -27,7 +27,7 @@ public static class CronJobManager /// if you call this method after calling method public static void SetConfig(Config config) { - lock (_sync) + lock (_syncScheduler) { if (_scheduler != null) { @@ -42,9 +42,9 @@ public static void SetConfig(Config config) /// public static void RunScheduler() { - lock (_sync) + lock (_syncScheduler) { - if (_scheduler != null) + if (_scheduler == null) { InternalInitUnsafe(); _scheduler!.RunScheduler(); @@ -156,14 +156,15 @@ public static Guid Register(Action action, string name, string category, TimeSpa private static Guid InternalRegisterJob(TimeSpan sleepDuration, Action? actionSync = null, Func? actionAsync = null, string? name = null, string? category = null) { - if (_scheduler != null) + lock (_syncScheduler) { - throw new SchedulerNotRunnableException( - $"Scheduler is not a runnable, just call {nameof(CronJobManager)}.RunScheduler() for fix that, before when begin register jobs"); + if (_scheduler == null) + { + throw new SchedulerNotRunnableException( + $"The scheduler is not runnable. To fix this, you need to call the {nameof(CronJobManager)}.RunScheduler method before registering any jobs."); + } } - ArgumentNullException.ThrowIfNull(_scheduler, ""); - if (actionSync == null && actionAsync == null) { throw new ArgumentNullException(nameof(actionSync)+" and "+nameof(actionAsync), "one of action must be not null");