/// <summary>Perform the command</summary> public void Do(CommandHistory CommandHistory) { IsRunning = true; stopwatch.Start(); jobRunner.Run(jobManager, wait: false); timer = new Timer(); timer.Interval = 1000; timer.AutoReset = true; timer.Elapsed += OnTimerTick; timer.Start(); }
/// <summary>Create a command runner one hasn't already been created.</summary> private void Start() { if (commandRunner == null) { lock (lockObject) { if (commandRunner == null) { commandRunner = new JobRunnerSync(); commandRunner.Run(this); ReadExistingDatabase(Connection); } } } }
public async ValueTask Excute(IJob job, CancellationToken cancellationToken) { await _jobRunner.Run(job, cancellationToken).ConfigureAwait(false); }
private void ExecuteJob(IJobFactory factory, IJobRunner runner, ScheduledJob job) { if (!OnJobStarting(job)) { return; } runner.Run(async() => { if (job.OverlapHandling == OverlapHandling.Skip && _activeJobs.Contains(job)) { return; } Lock(job); var activeJob = new ActiveJob(job, _cts.Token); _activeJobs.Add(activeJob); try { var context = new JobExecutionContext(this, activeJob.Token); OnJobStarted(context); try { if (!job.IsAnonymous) { using (var scope = factory.CreateScope()) { var instance = scope.Create(job.Type); await instance.ExecuteAsync(context); var supportsDispose = typeof(IDisposable).IsAssignableFrom(instance.GetType()); if (supportsDispose) { var disposable = (IDisposable)instance; disposable.Dispose(); } } } else { await job.Handler(context); } } catch (Exception ex) { if (OnJobError(context, ex)) { throw; } } OnJobFinished(job); } finally { _activeJobs.Remove(activeJob); Unlock(job); } }); }