Skip to content

Commit

Permalink
Fixed an issue where the sceduler stops accepting new schedules after…
Browse files Browse the repository at this point in the history
… restart / discovery (#42)
  • Loading branch information
Horizon0156 committed Mar 24, 2020
1 parent 9903ea6 commit 082d4e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public async Task StopDaemonActivitiesAsync()
_stateActions.Clear();
_serviceCallFunctionList.Clear();

await _scheduler.Stop();
await _scheduler.Restart();
}

/// <inheritdoc/>
Expand Down
12 changes: 11 additions & 1 deletion src/Daemon/NetDaemon.Daemon/Daemon/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Scheduler : IScheduler
/// <summary>
/// Used to cancel all running tasks
/// </summary>
private readonly CancellationTokenSource _cancelSource = new CancellationTokenSource();
private CancellationTokenSource _cancelSource = new CancellationTokenSource();

private readonly ConcurrentDictionary<int, Task> _scheduledTasks
= new ConcurrentDictionary<int, Task>();
Expand Down Expand Up @@ -271,6 +271,16 @@ public async Task Stop()
throw new ApplicationException("Failed to cancel all tasks");
}

/// <summary>
/// Restarts the scheduler.
/// Existing schedules are cancelled and the scheduler remains usable.
/// </summary>
public async Task Restart()
{
await Stop();
_cancelSource = new CancellationTokenSource();
}

private async Task SchedulerLoop()
{
try
Expand Down

0 comments on commit 082d4e8

Please sign in to comment.