private UserActionRunner LaunchUserActionRunner(ScheduledAction action, CancellationToken cancellationToken) { using (ExecutionContext.SuppressFlow()) { var runner = new ScheduledActionRunner(action, log, tracer, diagnostics); var personalCancellationSource = new CancellationTokenSource(); var linkedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, personalCancellationSource.Token); var runnerTask = Task.Run(() => runner.RunAsync(linkedCancellationSource.Token)) .ContinueWith( task => { userRunners.TryRemove(action.Name, out _); runner.Dispose(); linkedCancellationSource.Dispose(); personalCancellationSource.Dispose(); }); return(new UserActionRunner(personalCancellationSource, runner, runnerTask)); } }
internal IScheduledActionsBuilder Schedule(ScheduledAction action) { actions.Add(action); if (ShouldLogScheduledActions) { log.Info("Scheduled '{ActionName}' action with scheduler '{Scheduler}'. ", action.Name, action.Scheduler.GetType().Name); } return(this); }
public ScheduledActionRunner(ScheduledAction action, ILog log, ITracer tracer, IVostokApplicationDiagnostics diagnostics) { this.action = action; this.tracer = tracer; this.log = log; if (diagnostics != null) { RegisterDiagnostics(diagnostics); } }
public void Update(ScheduledAction newAction) { if (newAction.Name != action.Name) { throw new InvalidOperationException($"Name mismatch on scheduled action update (old = '{action.Name}', new = '{newAction.Name}')."); } if (newAction.Scheduler is IStatefulScheduler newStateful && action.Scheduler is IStatefulScheduler oldStateful) { newStateful.TryCopyStateFrom(oldStateful); } action = newAction; }
public void Update(ScheduledAction action) => runner.Update(action);
public ScheduledActionRunner(ScheduledAction action, ILog log) { this.action = action; this.log = log; }