Skip to content

Commit

Permalink
[FS-9] fix tests;
Browse files Browse the repository at this point in the history
  • Loading branch information
lif0 committed Apr 24, 2024
1 parent d24e767 commit c444dc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/FabulousScheduler.Cron/Abstraction/BaseCronJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public async Task<JobResult<JobOk, JobFail>> ExecuteAsync()
else
{
Interlocked.Increment(ref _totalFail);
return new JobFail(CronJobFailEnum.FailedExecute, this.ID, $"the job {res.JobID} was finish with error");
}

return res;
Expand Down
4 changes: 4 additions & 0 deletions src/FabulousScheduler.Queue/Abstraction/BaseQueueJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public async Task<JobResult<JobOk, JobFail>> ExecuteAsync()
{
LastSuccessExecute = dt;
}
// else
// {
// Interlocked.Increment(ref _totalFail);
// }

return res;
}
Expand Down
19 changes: 10 additions & 9 deletions src/FabulousScheduler/Cron/CronJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FabulousScheduler.Cron;
/// </summary>
public static class CronJobManager
{
private static object _sync = new object();
private static readonly object _syncScheduler = new();
private static Config? _config;
private static CronScheduler? _scheduler;

Expand All @@ -27,7 +27,7 @@ public static class CronJobManager
/// <exception cref="SetConfigAfterRunSchedulingException"> if you call this method after calling <see cref="RunScheduler"/> method</exception>
public static void SetConfig(Config config)
{
lock (_sync)
lock (_syncScheduler)
{
if (_scheduler != null)
{
Expand All @@ -42,9 +42,9 @@ public static void SetConfig(Config config)
/// </summary>
public static void RunScheduler()
{
lock (_sync)
lock (_syncScheduler)
{
if (_scheduler != null)
if (_scheduler == null)
{
InternalInitUnsafe();
_scheduler!.RunScheduler();
Expand Down Expand Up @@ -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<Task>? 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");
Expand Down

0 comments on commit c444dc4

Please sign in to comment.